Skip to content

Prometheus & Grafana

In this section Grafana and Prometheus technologies are introduced. Also, an example combining both platforms with the eManager will be presented.

Prometheus

Prometheus is coupled with its robust data model and querying language, excels in time-series-based monitoring, making it ideal for tracking device metrics over time.

Some of Prometheus main features are:

  • A multi-dimensional data model with time series data identified by metric name and key/value pairs
  • PromQL, a flexible query language to leverage this dimensionality
  • No reliance on distributed storage; single server nodes are autonomous
  • Time series collection happens via a pull model over HTTP
  • Pushing time series is supported via an intermediary gateway
  • Targets are discovered via service discovery or static configuration
  • Multiple modes of graphing and dashboarding support

Grafana

Grafana allows you to query, visualize, alert on, and explore your metrics, logs, and traces no matter where they are stored. It provides you with tools to turn your time-series database data into insightful graphs and visualizations.

With its intuitive dashboards and visualization capabilities, empowers users to monitor and analyze device metrics in real-time, providing actionable insights for performance optimization.

Example of use with the eManager

This example is only a proof of concept to show how eManager can be integrated with some monitoring tools.

In this example we are going to use Prometheus and Grafana to monitor some eManager parameters as: the CPU basic, memory basic, RAM Used, disk space used, etc.

Once we finish the example we will obtain a dashboard as the one shown below.

Example_grafana_prometheus

In the next sections, the steps that must be followed to reproduce this example will be detailed.

1. eManager installation

We will use Docker to install an agent, called node-exporter that gathers system metrics and exposes them in a format which can be ingested by Prometheus.

  1. Login into the eManager terminal and create a directory:
    mkdir node-exporter
    
  2. Create a docker-compose.yml file
    cd node-exporter
    nano docker-compose.yml
    
    with this content:
    version: '3'
    services:
      node_exporter:
        image: quay.io/prometheus/node-exporter:latest
        container_name: node_exporter
        command:
          - "--path.rootfs=/host"
        ports:
          - 9300:9100
        pid: host
        restart: unless-stopped
        volumes:
          - '/:/host:ro,rslave'
    
  3. Execute: docker-compose up

Now the eManager should be exposing its metrics at the port 9300, usually found in 10.1.10.10:9300.

2. PC installation

Note

The process detailed below has been tested with Debian 10 and Ubuntu 20.04.

Once the eManager is prepared, we install in our PC both Grafana and Prometheus using Docker.

  1. Install docker in your laptop:
    sudo apt update
    sudo apt install docker-ce
    
  2. Create a new directory for this example:
    mkdir prometheus_grafana
    
  3. Create a docker-compose file in prometheus_grafana directory
    cd prometheus_grafana
    nano docker-compose.yml
    
    with the following content:
    services:
      prometheus:
        image: prom/prometheus:v2.49.1
        command:
          - --config.file=/etc/prometheus/prometheus.yml
          - --log.level=debug
        ports:
          - 9090:9090
        restart: unless-stopped
        volumes:
          - ./prometheus:/etc/prometheus
          - prometheus-data:/prometheus
      grafana:
        image: grafana/grafana:9.5.15
        ports:
          - "3001:3000"
        environment:
          - GF_PATHS_PROVISIONING=/etc/grafana/provisioning
          - DS_PROMETHEUS=prometheus
        volumes:
          - grafana-data:/var/lib/grafana
          - ./grafana:/etc/grafana/provisioning
        privileged: true
        depends_on:
          - prometheus
    volumes:
      prometheus-data:
      grafana-data:
    
  4. Clone our sample project.
    git clone https://github.com/circutor-iot/prometheus-grafana-example
    
  5. Now our example is set, so that the eManager is expected to be found at the IP 10.1.10.10. In order to use another IP, edit static_config/targets field in
    nano prometheus-grafana-example/prometheus/prometheus.yml 
    
  6. Finally execute
    docker-compose up
    
    You can access Grafana using localhost:3001 in your web browser and Prometheus using localhost:9090. Windows as the ones shown below should be displayed.

grafana

prometheus

The first time you login into Grafana use the credentials admin/admin. Then follow the steps to change the password.

3. Create Grafana dashboard

In this example we use an official Dashboard provided by Grafana.

Navigate to here, then select Download JSON in order to download a 1860_rev36.json file.

Once the dashboard template example is downloaded, access Grafana through the web browser using localhost:3001.

Select the plus symbol placed in the right top part and choose Import dashboard as shown in the image below.

grafana_1

A window as the one below will be opened. Select Upload dashboard JSON file and search for 1860_rev36.json previously downloaded.

grafana_2

In Prometheus field select Prometheus and leave the rest of fields as default.

grafana_3

Once you click import you will see the dashboard that has been shown at the beginning of the example.