Skip to content

Prometheus & Grafana

On KraftCloud, 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 KraftCloud 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:

➜ kraft cloud inst get nginx-h86j5
uuid: d1e6253e-16fa-4f91-8433-93122506b5b7
name: nginx-y6587

We can then query the metrics API to get the metrics for the instance in the prometheus format:

Terminal window
curl -X GET \
-H "Authorization: Bearer ${KRAFTCLOUD_TOKEN}" \
# HELP Resident set size in bytes
# TYPE instance_rss_bytes gauge
instance_rss_bytes{instance_uuid="d1e6253e-16fa-4f91-8433-93122506b5b7"} 34566144
# HELP Consumed CPU time in milliseconds
# TYPE instance_cpu_time_milliseconds counter
instance_cpu_time_milliseconds{instance_uuid="d1e6253e-16fa-4f91-8433-93122506b5b7"} 680
# HELP Amount of bytes received over network
# TYPE instance_rx_bytes counter
instance_rx_bytes{instance_uuid="d1e6253e-16fa-4f91-8433-93122506b5b7"} 42
# HELP Amount of bytes transmitted over network
# TYPE instance_tx_bytes counter
instance_tx_bytes{instance_uuid="d1e6253e-16fa-4f91-8433-93122506b5b7"} 2060
# HELP Count of packets received from network
# TYPE instance_rx_packets counter
instance_rx_packets{instance_uuid="d1e6253e-16fa-4f91-8433-93122506b5b7"} 1
# HELP Count of packets transmitted over network
# TYPE instance_tx_packets counter
instance_tx_packets{instance_uuid="d1e6253e-16fa-4f91-8433-93122506b5b7"} 8

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 KraftCloud token is available to Prometheus via a file, for example:

Terminal window
echo -n "${KRAFTCLOUD_TOKEN}" > /tmp/kc_token.txt

Let’s start the server:

Terminal window
docker run \
-p 9090:9090 \
-v /tmp/kc_token.txt:/kc_token.txt \
-v /tmp/prometheus.yml:/etc/prometheus/prometheus.yml \

With this in place, let’s configure our Prometheus configuration file; we’ll use port 9090 for this and job name myinstance:

scrape_interval: 15s
evaluation_interval: 15s
- job_name: prometheus
- targets: ["localhost:9090"]
- job_name: myinstance
scheme: https
metrics_path: "/v1/instances/<your_instance_uuid>/metrics"
credentials_file: "/kc_token.txt"
- targets: [""]

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&

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:

Terminal window
docker run \
-p 3000:3000 \

To get the IP of the prometheus server in docker, you can use the following commands:

Terminal window
docker container list # to get the container id
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <prometheus container id>

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: 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:

Service groups in KraftCloud

To customize the dashboard please consult the Grafana documentation.

Learn More