Visualization and monitoring system. Grafana + Prometheus

I’ll tell you a little about installing Grafana on windows and setting up basic system metrics.

A few words about Grafana itself and what it is for.

Grafana is an open source monitoring, data analysis and visualization platform for collected data. In fact, it is used to visually represent the collected metrics for more comfortable monitoring of the system status.

In this article I will use:

  • Grafana

  • Prometheus

  • windows_exporter

  • Blackbox_exporter

To get started, download the current distribution of Grafana itself and install it (Download may require a VPN)

Let’s go to the link: https://grafana.com/grafana/download and choose the version you want to download.

Then download and install Prometheus.

Prometheus is essentially a metric collector. By installing it on one PC that will act as a server for Grafana, it will only be enough to start collecting metrics from other machines (enter the corresponding block into the Prometheus configuration file), and Prometheus, in turn, will prepare metrics for Grafana itself.

Prometheus: https://prometheus.io/download

Installation requires NSSM, which is a service assistant that helps install utility utilities.

NSSM Link: https://www.nssm.cc/download

Let’s start installing Prometheus

Go to CMD and enter the following commands (run CMD as admin):

  1. Go to the directory with the NSSM package:

    cd C:\GrafanaSetup\nssm-2.24\win64

  2. We install the Prometheus service:

    nssm.exe install prometheus C:\GrafanaSetup\prometheus-2.43.0.windows-amd64\prometheus.exe

At this stage, the Prometheus service should be installed. Next, we will install the services for collecting metrics.

Install Windows_exporter – a metrics collector that collects statistics from the system and compiles a kind of “logs”.

Windows exporter download link: https://github.com/prometheus-community/windows_exporter/releases

Choose the version that suits us and install

After installation, we also check in the services that the installation was successful and the service is running (the default service name is windows_exporter).

Now you can check the collection of metrics by reference to the service port: http://localhost:9182/metrics

At this stage, we can install the Blackbock exporter – used to monitor the availability status of URLs. Follow the link and download the version of Blackbox we need: https://prometheus.io/download/ and install.

Now let’s start configuring the installed services

Let’s start with Grafana:

Go to folder C:\Program Files\GrafanaLabs\grafana\conf and open the file defaults.ini using a text editor and change the value in the smtp block in the enabled field to true and save the changes. We start the Grafana service if it is already running, just restart for the changes to take effect.

By clicking on the link: http://localhost:3000 we will see the active Grafana interface. The default login is admin / admin, then it will ask you to change your password and redirect you to the Grafana management home page.

Next, let’s start setting up Prometheus:

We need to make changes to the configuration by including metrics in the config. To do this, go to the prometheus directory”) and open the prometheus.yml file and make the following changes:

Add a block to connect windows_exporter:

- job_name: "Любое комфортное имя"

static_configs:

#IP-адрес и порт, где собираются метрики window_exporter\

- targets: ["localhost:9182”]

When adding multiple machines, you can add a lables block that will change the displayed IP address to its own description:

static_configs:

- targets: ["localhost:9182"]

labels:

instance: Server-1

- targets: ["192.168.0.254:9182"]

labels:

instance: Server-2

Immediately add a block for blackbox_exporter:

- job_name: 'blackbox'

metrics_path: /probe

params:

module: [http_2xx] # Look for a HTTP 200 response.

static_configs:

- targets:

-https://youtube.com

-https://google.com

relabel_configs:

- source_labels: [__address__]

target_label: __param_target

- source_labels: [__param_target]

target_label: instance

- target_label: __address__

replacement: localhost:9115 # The blackbox exporter's real hostname:port

In the targets block, we list the required URLs.

Just pay attention, in order for the block to work correctly and there were no errors when starting the service, it is necessary to strictly observe the tabulation of lines.
Having added the necessary blocks, we can run prometheus.

Then make sure all services are running:

  1. Grafana

  2. Prometheus

  3. Windows_ exporter

  4. Blackbox_exporter

and now we check the status of the services by the link: http://localhost:9090/targets

In general, we have set up basic metrics, it remains to enable the display of metrics in Grafana.

Go to grafana main page ( Default: http://localhost:3000 ).

We connect the Prometheus data source:

On the main page, go to the Data sources menu

Choosing our Prometheus

And we specify our URL. In our case, everything is located on the same local machine and we can register it through the format: http://localhost:port/

And press the button: Save & test

Now you need to configure dashboards for windows exporter metrics. To configure, go to the main page and add a panel:

At the time of writing, I found two of the most comprehensive Dashboards:

  1. 14510

  2. 14694

    You can use them or customize everything yourself.

To add a Dashboard, specify the ID in the field and click on the Load button.

Then we are directed to the settings panel, where we specify the Prometheus data source and can change the name of the panel itself. Then click the Import button

And we already have a ready-made, customized dashboard, which can already be added with the necessary functionality. Unnecessary graphics can be deleted or arranged in the order you need.

When adding new PCs for monitoring, it is enough to add lines to the Prometheus.yml configuration file and restart the Prometheus service. The service will independently analyze the metrics and add a new PC to the monitoring on a ready-made dashboard, where it will not be difficult to switch between PCs.

Further, you can already play with specific metrics, and display specific services from different machines. For example: On the main screen, press ADD > Visualization and get into the panel creation menu. In field Metrics browser we enter the selected metric and indicate the parameters that we want to receive (well, or display). Let’s use the windows service as an example:

  1. Name – service name

  2. State – a status type that refers to the windows_service_state metric

  3. Instance – from which particular machine to take the metric.

windows_service_state{name="нужная служба", state="running", instance="Server-1"}

and in the upper right corner select the desired panel type, in my case it is Stat:

In the panel options in the menu Value mappings and change the digital values ​​of the metrics to readable words, for example: Ok/Bad Up/Down.

Save and get the following panel:

Well, let’s set up a metric to get HTTP statuses:

We use the metric: probe_http_status_code and configure value mapping:

probe_http_status_code{instance="https://youtube.com"}

And as a result we get such a panel:

Next, you can go to http://localhost:9090/targets choose the metrics you need for your tasks and configure the ones you need for your tasks.

I think we can end there. The basic setup is not that difficult, but when you encounter it for the first time, it can be difficult, so I wanted to share a step-by-step setup. I hope this will help someone and reduce enough time to search for information and initial setup.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *