Add Prometheus
As with the other services we also use an existing docker image to run the Prometheus server. By mounting a volume to the container we can configure the server as we already did with Kong.
Create the configuration
We will put the configuration for Prometheus in a directory called prometheus:
# Create the directory
mkdri prometheus
In this directory we create a file called prometheus.yml with the following content:
global:
scrape_interval: 15s # By default, scrape targets every 15 seconds.
# Attach these labels to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels:
monitor: 'codelab-monitor'
# 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=<job_name>` to any timeseries scraped from this config.
- job_name: 'kong'
# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: 5s
static_configs:
- targets: ['kong:8001']
Add a service
Now we can add the Prometheus service to our docker-compose.yaml:
prometheus:
container_name: prometheus
image: prom/prometheus:v2.12.0
depends_on:
- "kong"
restart: always
networks:
- kong-rover-demo
volumes:
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
Lets see what has changed and start our services. As we didn’t expose the AdminAPI endpoint we have to call it from within the docker network. We can easily do this with Docker:
docker container exec -it kong \
curl -X GET http://localhost:8001/metrics
As we didn’t call our API there are only a few metrics available. So lets use our API as we already did by running a few commands (see the (cURL-)commands from the first section).
When we call the /metrics endpoint again, we see a bunch of new metrics. But we want to see them rendered in a dashboard. So lets stop the services again and add Grafana.