VK Cloud logo
Updated atDecember 18, 2023   03:36 PM

Monitoring Redis with Prometheus, Node exporter and Grafana

Prometheus is a server designed to collect and store metrics received from processes (exporters). The accumulated data can be viewed both through the Prometheus web interface and through separate visualization tools, for example, Grafana.

This instruction will help:

  • deploy Prometheus 2.45.1 server in CentOS 8.4 operating system in VK Cloud;
  • install the Node exporter extension in the Redis 5 Single configuration DBMS;
  • customize the visualization of data from Redis in Prometheus and Grafana 10.

Prometheus server, DBMS and Grafana will be deployed on separate VMs.

Preparatory steps

  1. Create a virtual network, for example, monitoring-net.

  2. Create VM for Prometheus server:

    • name: Centos_8_5_Prometheus;
    • operating system: CentOS 8.4;
    • network: monitoring-net;
    • public IP address: assign it, as an example is given 87.239.239.239;
    • security groups: default, all.

    The internal IP address of the created instance: 10.0.3.7.

  3. Create a DB instance:

    • name: Redis-5;
    • DBMS: Redis 5;
    • configuration type: Single;
    • network: monitoring-net;

    The internal IP address of the created instance: 10.0.3.13.

  4. Deploy Grafana 10 is on the monitoring-net network.

2. Install and configure Prometheus

  1. Install the Node exporter extension for the Redis-5 DB instance. When installing, specify the parameter listen_port = 9100.

  2. Connect to the Centos_8_5_Prometheus VM.

  3. Download Prometheus and unzip the downloaded archive:

    1sudo su
    2export VERSION="2.45.1"
    3wget https://github.com/prometheus/prometheus/releases/download/v$VERSION/prometheus-$VERSION.linux-amd64.tar.gz -O - | tar -xzv -C /tmp
  4. Copy the contents of the repository prometheus-2.45.1.linux-amd64:

    1mkdir /etc/prometheus
    2mkdir /var/lib/prometheus
    3cp /tmp/prometheus-$VERSION.linux-amd64/prometheus /usr/local/bin
    4cp /tmp/prometheus-$VERSION.linux-amd64/promtool /usr/local/bin
    5cp -r /tmp/prometheus-$VERSION.linux-amd64/consoles /etc/prometheus
    6cp -r /tmp/prometheus-$VERSION.linux-amd64/console_libraries /etc/prometheus
    7cp /tmp/prometheus-$VERSION.linux-amd64/prometheus.yml /etc/prometheus/
  5. (Optional) Delete files from the temporary folder:

    rm -rf /tmp/prometheus-$VERSION.linux-amd64
  6. Create a group and a user prometheus, assign him rights to the associated repositories:

    1groupadd --system prometheus
    2useradd --system -g prometheus -s /bin/false prometheus
    3chown -R prometheus:prometheus /var/lib/prometheus /etc/prometheus
    4chown prometheus:prometheus /usr/local/bin/prometheus /usr/local/bin/promtool
  7. In the file /etc/prometheus/prometheus.yml add content to the scrape_configs block:

    1- job_name: "node"
    2  scrape_interval: 10s
    3  static_configs:
    4    - targets: ["10.0.3.13:9100"]
  8. Create a Prometheus startup script /etc/systemd/system/prometheus.service with the contents:

    1[Unit]
    2Description=Prometheus
    3Wants=network-online.target
    4After=network-online.target
    5
    6[Service]
    7User=prometheus
    8Group=prometheus
    9ExecStart=/usr/local/bin/prometheus \
    10    --config.file /etc/prometheus/prometheus.yml \
    11    --storage.tsdb.path /var/lib/prometheus \
    12    --web.console.templates=/etc/prometheus/consoles \
    13    --web.console.libraries=/etc/prometheus/console_libraries
    14ExecReload=/bin/kill -HUP $MAINPID
    15[Install]
    16WantedBy=default.target
  9. Run Prometheus:

    1systemctl daemon-reload
    2systemctl start prometheus.service
    3systemctl enable prometheus.service
  10. Make sure that Prometheus is working correctly:

    systemctl status prometheus.service

    The output of the command must contain the active status.

  11. Wait a few minutes for the data to accumulate.

  12. Go to the address http://87.239.239.239:9090.

    The Prometheus server web interface opens.

  13. (Optional) Review the available data:

  14. (Optional) Unbind floating address from VM Centos_8_5_Prometheus.

3. Set up data visualization in Grafana

  1. Go to the Grafana web interface.
  2. Add new data source: to Prometheus server URL specify http://10.0.3.7:9090.
  3. Install sets of graphs for visualizing the received data, for example, by importing a ready-made version — Node Exporter Full.

4. (Optional) Check the monitoring data after the test load

  1. Create a test load on the Redis-5 VM in a way that is convenient for you.

  2. Make sure to change the indicators of the Grafana charts.

Delete unused resources

The created resources are charged and quotas are spent. If you don't need them anymore:

  1. Delete deployed virtual machines.
  2. Delete a virtual machine with Grafana.
  3. Remove the floating IP address assigned to the Centos_8_5_Prometheus VM.
  4. Delete the port to which the virtual IP address is assigned.
  5. Delete a monitoring-net network.