Tag Archives: grafana

Setting up Prometheus and Grafana on Windows

Ever since I stumbled on Grafana and Prometheus several months ago while looking at creating a comprehensive smart home dashboard, I’ve always wanted to set one up.

After a friend introduced me to Stable Diffusion a few weeks ago, I wanted to be able to run generation from anywhere, so I got my instance of Stable set up with AUTOMATIC1111/stable-diffusion-webui: Stable Diffusion web UI (github.com) by following How to Run Stable Diffusion Locally with a GUI on Windows (howtogeek.com).

This was all well and good, and I can now create AI art from anywhere, but I wanted to be able to see my system’s performance stats as well, so I started looking up webui’s for monitoring and stumbled across Grafana again.

Let’s get this going. Note: This does not follow any best practices, so reader beware. #musicfueledlatenightcomputeradventures

Exporter Installation and Configuration

Step 1 – Download and Install Windows_Exporter

Download the latest release of windows_exporter Releases · prometheus-community/windows_exporter (github.com)
As of writing: windows_exporter-0.20.0-amd64.msi

Unzip and move this file to an easy to access path such as C:\Monitoring\

Open up cmd or PowerShell as admin.
cd to the directory housing your msi file and install using msiexec as demonstrated:

> cd C:\Monitoring
> msiexec /i windows_exporter-0.20.0-amd64.msi --LISTEN_ADDR=127.0.0.1 --LISTEN_PORT=9182

This will install windows_exporter as a Windows service, so you will not need to worry about starting it or creating a task in Task Scheduler.

To verify it is working, open a new tab and navigate to http://127.0.0.1:9182/metrics

Step 2 – Download and Install OhmGraphite

Download the latest release of OhmGraphite Releases · nickbabcock/OhmGraphite (github.com)
As of writing: OhmGraphite-0.27.0.zip

Unzip and move this file to an easy to access path such as C:\Monitoring\

Edit the OhmGraphite.exe.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="type" value="prometheus" />
    <add key="prometheus_port" value="4445" />
    
    <!-- This is the host that OhmGraphite listens on.
         `*` means that it will listen on all interfaces.
         Consider restricting to a given IP address -->
    <add key="prometheus_host" value="127.0.0.1" />
  </appSettings>
</configuration>

Open cmd or PowerShell as admin and cd to the folder housing OhmGraphite:

> cd C:\Monitoring\OhmGraphite
> .\OhmGraphite.exe install
> .\OhmGraphite.exe start

To verify it is working, open a new tab and navigate to http://127.0.0.1:4445/metrics

Prometheus – Installation and Configuration

Step 1 – Download and Installation

Download the latest release of Prometheus Releases · prometheus/prometheus (github.com)
As of writing: prometheus-2.40.0.windows-amd64.zip

Extract the contents with your preferred unzipping application and choose an easily accessible path such as C:\Monitoring\ and if desired, rename the folder to just prometheus-2.40.0.

Next, open up the default YAML config file, prometheus.yml, we will add scraper targets to this file.

# my global config
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
#alerting:
  #alertmanagers:
  #  - static_configs:
 #       - targets:
          # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  - job_name: 'fractal'
    metrics_path: '/metrics'
    # scheme defaults to 'http'.
    static_configs:  
      - targets: ['127.0.0.1:9182', '127.0.0.1:4445']

Open cmd or PowerShell as admin and cd to the folder housing Prometheus and start Prometheus with the config file specified:

> cd C:\Monitoring\prometheus-2.40.0
> .\prometheus.exe --config.file="prometheus.yml"

As long as you don’t see any funky errors like the following, you should be able to access Prometheus at http://localhost:9090 to test queries.

ts=2022-11-08T04:00:07.855Z caller=main.go:468 level=error msg="Error loading config (--config.file=prometheus.yml)" file=C:\Monitoring\prometheus-2.40.0\prometheus.yml err="parsing YAML file prometheus.yml: yaml: line 28: did not find expected key"

Test it out by entering cpu into the search bar, then picking a query from the dropdown and pressing enter again.

The instance and job fields as seen above are pulled from the prometheus.yml configuration file.

Grafana Setup

Step 1 – Download and Install

Head on over to Grafana get started | Cloud, Self-managed, Enterprise. Click Download and then choose your OS (Windows for this tutorial).
Download Grafana | Grafana Labs

Run the installer.

Step 2 – Configure Grafana

Once Grafana is installed, open up your web browser and navigate to http://localhost:3000 to complete first-time setup.

Step 3 – Import Dashboard

At this point, you can choose to create a new dashboard from scratch or do what I did and use an existing dashboard to learn how to make the queries work once the exporters are set up.

Manage dashboards | Grafana documentation

Learn Version: Windows Desktop Overview | Grafana Labs

TLDR Version: Stable Diffusion Monitor-1667965231420.json

As long as all this works, you should be able to use the TLDR dashboard out of the box.

I recommend creating a few panels from scratch just to learn the Grafana interface.

That’s all she wrote, folks!