Prometheus & Grafana
On Unikraft Cloud (UKC), it’s possible to use the platform’s metrics API to export instance metrics in different formats, including Prometheus. In this guide we show you how to quickly set this up.
Prometheus Integration
To use the Unikraft Cloud metrics API we’ll assume you already have at least one instance running (e.g., you can follow the nginx guide).
First, we’ll need to retrieve the instance’s uuid, which we can do with the kraft cloud inst get
command.
For example, assuming the instance’s name is nginx-y6587
:
We can then query the metrics API to get the metrics for the instance in the prometheus format:
Next, let’s start a simple Prometheus server and add the instance as a target. For this step you’ll need to make sure that your Unikraft Cloud token is available to Prometheus via a file, for example:
Let’s start the server:
With this in place, let’s configure our Prometheus configuration file;
we’ll use port 9090 for this and job name myinstance
:
You should be able to see that the instance is UP in the Prometheus UI: http://localhost:9090/targets?search=myinstance
This means we can now do queries directly in Prometheus: http://localhost:9090/graph?g0.expr=instance_cpu_time_milliseconds&g0.tab=0&g0.display_mode=lines&g0.show_exemplars=0&g0.range_input=1h
Grafana Integration
We can also use Grafana to visualize the metrics. First, let’s start a Grafana server and add Prometheus as a data source:
To get the IP of the prometheus server in docker, you can use the following commands:
After this, log in with the default credentials: admin
and admin
.
Now let’s add the newly started Prometheus server as a data source by creating a new Prometheus data source: http://localhost:3000/connections/datasources/new
Next, under Connection
, set the Prometheus server URL: http://192.168.0.1XX:9090
.
We need to set the IP/FQDN to it, as localhost
will not work (we’re inside a container).
When saving it, it will tell us that the connection is working; you should now see the data on the Grafana board, as an example:
To customize the dashboard please consult the Grafana documentation.
Learn More
- The Unikraft Cloud metrics API
- The Grafana documentation