Monitoring docker containers on Windows using Prometheus + Grafana
I guess most of us are fans of Docker. But if you happen to be working for an enterprise whose IT department only lends out Windows OS installed laptops, I am sure you have at some point of time gone through the pain of getting Docker installed and working on your windows laptops and possibly failed at it and switched to using a Linux VM or VirtualBox.
Well, you don’t have to do that anymore. Docker has made its installation really simple on latest Windows OS which contains Hyper-V functionality , i.e either 8 or 10 , only side-effect is that VirtualBox can no longer be used if Hyper-V is functioning. The “cherry on top” is the Enable Kubernetes option shipped with latest Docker CE that lets you get your hands dirty with those kubectl operations you always wanted to try.(Although , you might want to be very careful with the amount of resources that you give for such a setup, as running an single k8s cluster can be resource intensive)
If your experience has been anything close to above and always wanted to get most of your container development stuff working on your local windows environment instead of shared linux VMs ( or any other reason that lets you sleep well at night ) , go ahead and get latest Docker setup along with Kubernetes and get going with your development locally.
Once you have successfully achieved the above, you might also want to monitor your containers and get some feedback on your container performance like cpu and memory consumption. There are many articles and github repos providing various ways of doing this. Some of the most comprehensive ones are listed below. But, if you try to run these as is you will face some issues with Windows environment.Through rest of the blog , I will be sharing my experiences of getting this monitoring setup up and running on windows environment along with few other tweaks required to get that dashboard on your Grafana page.
If you are only interested in getting this monitoring dashboard up , here is the Github repository which lets you setup dashboard using docker-compose.
Monitor your Docker containers using prometheus, cAdvisor , node-exported and grafana on Windows …
Still here … Ok , lets start then
There are four basic components that could make up Docker Monitoring framework on Windows environment. Stefan Prodan’s blog ( in credits section) has an excellent diagram which explains the architecture and flow between these components. I suggest you to read this blog to get a better understanding how these components work together. Until then you can also refer to my humble diagram which attempts to provide a similar understanding of these components.
cAdvisor is a daemon and monitoring tool which collects and aggregates the resource usage data from containers. But it does not have its own DB to present a time-series information on the resource utilization. This is where prometheus comes in picture.
node-exporter is similar to cAdvisor , but collects the metrics of hardware and OS from the host machines itself.
prometheus is an excellent metrics db collection tool which also provides time-series representation of your metrics data with powerful queries and good visualization. Prometheus scrapes ( collects metrics data at regular interval ) data from exposed cAdvisor and node-exporter ports and stores it in its persistent storage. You can also alternatively configure alerts based on your metrics, we will not be going into this part.
grafana provides excellent visualization and querying dashboard with lot of pre-existing built dashboards for most of common metrics visualizations. Prometheus also comes with its own visualizations but Grafana takes the visualization and monitoring to the next level and is quite easy to setup.
- In my setup , I have skipped Alert Manager as I had no need for it at the moment. But you can very well follow the instructions in the above links on how to set them up.
- Some of the blogs would suggest mounting “rootfs” volume for cAdvisor and node-exporter containers. Remember , docker in Windows runs inside a Hyper-V MobyLinux VM , If you keep “rootfs” volume mapping on Windows, you will end up with a failure on running your docker-compose up command since rootfs is not available on the Windows docker env. You can safely skip this volume map setting in your docker-compose file for both cAdvisor and node-exporter.
- When using docker-compose you will also need to set another Env variable from your Windows powershell to convert your windows paths present in your docker-compose volume mappings. On your Powershell run this command $Env:COMPOSE_CONVERT_WINDOWS_PATHS=1
- I have included couple of Dashboards ( updated and customized for windows to receive data from prometheus ) for displaying Container and Host metrics. You can find them present inside Grafana folder in my Github project
Once ready just run docker-compose up on your path. Once all the containers are up and running go-to http://localhost:3000 for Grafana home ( default user/pass : admin/admin).
I went through quite a few blogs and github projects before I could complete this project. But these are some of the projects/blogs which influenced this project the most.
A docker-compose stack for Prometheus monitoring. Contribute to vegasbrianc/prometheus development by creating an…