Using Grafana to plot Docker container metrics Source

1---
2title: 'Using Grafana to plot Docker container metrics'
3date: '2020-09-18'
4published_at: '2020-09-18T11:23:00.001+10:00'
5tags: ['cadvisor', 'containers', 'docker', 'grafana', 'prometheus']
6author: 'Gavin Jackson'
7excerpt: 'At work, we have been busy playing around with Docker (initially for development environments, with a view to bump these into higher environments further down the track. I wanted to get some performan...'
8updated_at: '2020-09-18T11:23:58.899+10:00'
9legacy_url: 'http://www.gavinj.net/2020/09/using-grafana-to-plot-docker-container.html'
10---
11
12At work, we have been busy playing around with Docker (initially for development environments, with a view to bump these into higher environments further down the track.
13
14I wanted to get some performance metrics for my running docker containers. Below is a recipe that I ended up using (which may be of interest to others).
15
16## The Code
17
18[https://github.com/gavinjackson/docker-metrics](https://github.com/gavinjackson/docker-metrics)
19
20## How it Works
21
22It consists of the following four containers (defined in the docker-compose.yml file):
23
241. **cadvisor **collects container stats
252. **node-exporter** collects physical hardware stats.
263. **prometheus **harvests this data.
274. **grafana **is configured to consume data from the prometheus server and present some pre-made dashboards to visualise the data.
28
29Once running, this is what the dashboards look like:
30
31[![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjObNNCOoiHAlEOal0vVsszuiVtGFPci5lGeS2EiAI-xXb6doEmRpGH-w2bcLndirThzDPr5uDIFYjup3-KIZdOQrU6Tx3VDcfStEA8V2KjEvIY9oS8ITXY7SAoWCrgl63877gR_aAKhhg/w662-h335/image.png)](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjObNNCOoiHAlEOal0vVsszuiVtGFPci5lGeS2EiAI-xXb6doEmRpGH-w2bcLndirThzDPr5uDIFYjup3-KIZdOQrU6Tx3VDcfStEA8V2KjEvIY9oS8ITXY7SAoWCrgl63877gR_aAKhhg/)
32
33[![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8fFPmQuvLNaPNJdsJGnLKM7ryredDMtbXnd2tYxcQ1poarZMWz4oKMerLAuTDYR8H7NFMIW2rYb0vHu3tZ56_WM8R3QYZ4_RjdeY8vYdg9zdio3rZ0i4DEIYzl-wGqXVjPh7lApv8Ngg/w659-h335/image.png)](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8fFPmQuvLNaPNJdsJGnLKM7ryredDMtbXnd2tYxcQ1poarZMWz4oKMerLAuTDYR8H7NFMIW2rYb0vHu3tZ56_WM8R3QYZ4_RjdeY8vYdg9zdio3rZ0i4DEIYzl-wGqXVjPh7lApv8Ngg/)
34
35The cool thing about this is that you can copy this into your existing docker project and you will get instant metrics for all of your running containers (and host system).
36
37## Interesting links:
38
39**cadvisor **- the magical container that extracts the docker container metrics [https://github.com/google/cadvisor](https://github.com/google/cadvisor)
40
41**node-exporter** - the container that harvests the host metrics [https://github.com/prometheus/node_exporter](https://github.com/prometheus/node_exporter)
42
43**prometheus **- the tool that collects this data [https://prometheus.io/](https://prometheus.io/)
44
45**grafana **- the time based visualisation layer that draws it's data from prometheus [https://grafana.com/](https://grafana.com/)
46
47The following grafana dashboards were provisioned:
48
491. [https://grafana.com/grafana/dashboards/1860](https://grafana.com/grafana/dashboards/1860) Node Exporter Full, and
502. [https://grafana.com/grafana/dashboards/893](https://grafana.com/grafana/dashboards/893) Docker and system Monitoring
513. [https://grafana.com/grafana/dashboards/8321](https://grafana.com/grafana/dashboards/8321) Docker monitoring with node selection
52
53
54