Chapter 9. Containers and Kubernetes
Container deployments are becoming more common with technologies such as Docker and Kubernetes—you may even already be using them. In this chapter we will cover exporters that you can use with containers, and explain how to use Prometheus with Kubernetes.
All Prometheus components run happily in containers, with the sole exception of the Node Exporter, as noted in Chapter 7.
cAdvisor
In the same way the Node Exporter provides metrics about the machine, cAdvisor is an exporter that provides metrics about cgroups. Cgroups are a Linux kernel isolation feature that are usually used to implement containers on Linux, and are also used by runtime environments such as systemd.
You can run cAdvisor with Docker:
docker run \ --volume=/:/rootfs:ro \ --volume=/var/run:/var/run:rw \ --volume=/sys:/sys:ro \ --volume=/var/lib/docker/:/var/lib/docker:ro \ --volume=/dev/disk/:/dev/disk:ro \ --publish=8080:8080 \ --detach=true \ --name=cadvisor \ gcr.io/cadvisor/cadvisor:v0.45.0
If you visit http://localhost:8080/metrics, you will see a long list of metrics, as Figure 9-1 shows.
The container metrics are prefixed with container_
, and
you will notice that they all have an id
label. The id
labels starting with
/docker/
or /system.slice/docker-
are from Docker and its containers, and if you have /user.slice/ ...
Get Prometheus: Up & Running, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.