Skip to main content

Prometheus and Grafana configuration for KanBo metrics

Table of Contents

Prerequisites

Configuration of KanBo metrics requires a working Ubuntu Virtual Machine that is able to communicate with the KanBo app. Also make sure that port 3000 (port used by Grafana) is open for Your ip address.

The KanBo app itself requires an addition to the “config” section in the appsettings.json that should look like this:

    "UserCanEditProfile": true,
    "AllowPublicBoards": false,
    "Telemetry": {
        "Type": "Prometheus",
        "AuthKey": "random string here"
      }

Setting up an AuthKey here is required in the later steps.

Make sure the KanBo app has been restarted after appsettings.json changes.

1. Downloading and configuring Prometheus

For the steps below, the code fragments written in cursive represent values to be substituted

  1. SSH into Your Ubuntu VM
  2. Go to the Prometheus download page and copy the latest Linux build link
  3. cd to the /tmp folder and download the package with “wget link“
  4. Unpack the downloaded package by running “tar xvf packagefilename“
  5. cd to the unpacked folder
  6. Run “nano prometheus.yml”

You have now opened the default prometheus configuration file which requires a few additions or changes which are highlighted below:

# 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:
  # The job name is added as a label `job=` to any timeseries scraped from this config.
  - job_name: "prometheus"
    scheme: https
    authorization:
      credentials: "AuthKey from KanBo appsettings.json"
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    static_configs:
      - targets: ["KanBo Url"]
       # The label name is added as a label `label_name=` to any timeseries scraped from this config.
        labels:
          app: "prometheus"

Make sure the linebreaks are in the exact same places as they are above.

The scheme and the authorization section need to be added manually. The value for credentials needs to be the same as the AuthKey in the KanBo appsettings.json.

Targets are present by default in the config but need to be changed to the URL of Your KanBo.

Save the file after modifying.

2. Setting up Prometheus as a service

Unlike Grafana, Prometheus does not have an official package, which means setting it up as a service needs to be done manually. The steps below create all required folders with permissions to a newly created user, as well as a create a service file for systemd. Before running it, make sure You are still in the unzipped Prometheus folder.
  1. sudo useradd –no-create-home –shell /bin/false prometheus
  2. sudo mkdir /etc/prometheus
  3. sudo mkdir /var/lib/prometheus
  4. sudo chown prometheus:prometheus /etc/prometheus /var/lib/prometheus
  5. sudo cp prometheus promtool /usr/local/bin/
  6. sudo chown prometheus:prometheus /usr/local/bin/prometheus /usr/local/bin/promtool
  7. sudo cp prometheus.yml /etc/prometheus/
  8. sudo chown -R prometheus:prometheus /etc/prometheus
Now all the files are in their required places. Create a systemd service file by running sudo nano /etc/systemd/system/prometheus.service, and then paste the following contents into it:
[Unit]
Description=Prometheus Monitoring
Wants=network-online.target
After=network-online.target

[Service]
User=prometheus
Group=prometheus
Type=simple
Restart=on-failure
ExecStart=/usr/local/bin/prometheus \
  --config.file=/etc/prometheus/prometheus.yml \
  --storage.tsdb.path=/var/lib/prometheus/ \
  --web.listen-address=0.0.0.0:9090

[Install]
WantedBy=multi-user.target
Save the file

Grafana download and installation

Installation of Grafana requires adding its GPG Key and repository to the package tool, after which You will be able to install and update it with apt. To do that, follow the steps below:

  1. cd to /etc/apt/keyrings. If the folder does not exist, create it with mkdir
  2. Download the GPG Key with sudo wget -O /etc/apt/keyrings/grafana.asc https://apt.grafana.com/gpg-full.key
  3. sudo chmod 644 /etc/apt/keyrings/grafana.asc
  4. Add the Grafana repository with echo “deb [signed-by=/etc/apt/keyrings/grafana.asc] https://apt.grafana.com stable main” | sudo tee -a /etc/apt/sources.list.d/grafana.list

To install Grafana after adding its repository run sudo apt-get update first, then sudo apt-get install grafana

Starting and configuring Grafana

First, reload systemd by running systemctl daemon-reload. This will make Grafana and Prometheus runnable as services, which You start by running sudo systemctl enable –now prometheus and sudo systemctl start grafana-server
Your Prometheus service runs on port 3000, while the Grafana service runs on port 9090.

Go to yourmachineip:9000. You will be prompted to login

The temporary login and password are both “admin”. After logging in You will be prompted to change the password, which you should do.

Next, open the connections tab, click on “Add new connection” and select “Prometheus”.

Then click on “Add new data source”

The only change required afterwards is typing out http://localhost:9090 as the Prometheus server URL

Scroll to the bottom and click on “Save & Test”

You should get a message informing You that querying was successful. Click on “Explore view”.

Now You are able to query KanBo metric data!