Skip to content

How to set up Prometheus and Grafana

Danylo Chinyakov edited this page Mar 6, 2023 · 6 revisions

You will need a Linux distribution, I will show you a clean Ubuntu 22.04 image in a virtual machine.

How to set up access to a virtual machine .

You can skip this step if you are not using a virtual machine.

After the normal installation method, you need to set the network adapter type to bridge.

image

After that you can see a new device in your router - this is our Ubuntu.

image

We can see ip of this machine ( in my example it's 192.168.1.106), it will help us later

Prerequisites

Git Docker

How to install a git and clone a projekt

You can install git with the command apt-get install git or sudo apt-get install git

You can check the installation with git --version.

You should see a message like this

image

You can clone our project with the command git clone https://github.com/ita-social-projects/TeachUA.

The folder we are mostly interested in is the scripts folder, because that's where our dockers will be located

How to install the docker

First, update your existing list of packages:

sudo apt update.

Next, install a few prerequisite packages which let apt use packages over HTTPS:

``sudo apt install apt-transport-https ca-certificates curl software-properties-common .

Then add the GPG key for the official Docker repository to your system:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Add the Docker repository to APT sources:

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"

This will also update our package database with the Docker packages from the newly added repo.

Make sure you are about to install from the Docker repo instead of the default Ubuntu repo:

apt-cache policy docker-ce.

You'll see output like this, although the version number for Docker may be different:

image

Finally, install Docker:

sudo apt install docker-ce.

And install Docker-compose

sudo apt install docker-compose.

Docker should now be installed, the daemon started, and the process enabled to start on boot. Check that it's running:

sudo systemctl status docker !

image

How to configure Grafana and Prometheus

After cloning the project, you will see the following files and folders in the scripts folder

image

In file usage.txt you will find a brief explanation how to start and configure Grafana and Prometheus

In the config/prometheus.yml file you can configure the host address, endpoint, and authentication data to collect metrics.

Basically you should only config prometheus.yml file, and after pasting needed data, it should look something like this

зображення

How to run Grafana and Prometheus

In the scripts folder (where the docker-compose file is) you open a terminal and write sudo docker-compose up --build.

How to open the Grafana and Prometheus GUI

On the host machine we type in the ip address of Ubuntu (192.168.1.106 in my case) and then :port, specifying the port of the application we want to open, with the default settings Prometheus = 9090, Grafana = 3030

Our address should look something like this: 192.168.1.106:3030 or 192.168.1.106:9090

Prometheus Startup screen

image

In Status -> Targets , we can see if everything is OK

зображення

Grafana work screen

зображення

Default login and password is admin admin

Here, you can see premade dashboards that you can use

зображення

зображення

How to export dashboard

If you created dashboard, and want to share it in project Click desired dashboard -> Gear Icon - Json Model -> Copy everythig -> paste it in scripts/grafana/provisioning/dashboards in new file yourName.json -> commit and create pull request for changes зображення


зображення


зображення


зображення