Prometheus and Grafana
Installation and first step
As time series database, prometheus is often used in the world of monitoring system in combination with grafana, which is at the very basic a visualization tool for time series data. I will show you, how to get them up and running with the easiest way.
Grafana documentation is awesome, please check out there for several installation possibilities, I will use the installation with docker for simplicity. Because I want to change some of the default configs for later use, I will mount the configuration file with the docker run.
As well for prometheus, I will take the simple path and install it with docker, again we are using volumes in order to keep persistence and to be able to change the configuration without diving in the container.
But before we can run the docker container, we have to prepare the following configs:
Create a file called grafana.ini and copy&past official default configuration in there. It is good to run the config file as volume because of future changes, that you might want to do.
In order to tell prometheus, where to take the metrics, we need to write a config file as well.
- create a file called prometheus.yml
- Paste this very basic code example in it, note that at this time you should have an application running, that exposes metrics to prometheus. In my example on localhost using port 8080, check out here the code. You can take localhost:9090, which exposes metrics about the prometheus application itself.
- Please change this file according to your need
Now we have grafana and prometheus installed, but grafana has no idea, where to get the data to show. So, Let us tell grafana to use prometheus.
Connect Grafana and Prometheus using Grafana UI
- Open http://your-server-ip:3000
- Login with username admin and password admin
- On the left side, open the configuration menu and choose datasource
Connect Grafana and Prometheus using Grafana provisioning
This is my favourite one :) … We can directly tell grafana to connect to prometheus using the new provisioning system available for v5.0. We just need to create a datasource.yaml file and while running the container, just mount it to
You can as well choose to run both Prometheus and Grafana at once, using
docker-compose depending on your needs.
And that’s it, you can know create your dashboard and use the metrics you get from your prometheus.
The rest is up to you, for more input you can check these links
So that’s it, I hope it helped you go faster during the installation.