How to monitor Docker for Mac/Windows

Monitoring is now baked into Docker for Mac/Windows by default. How cool is that? No longer do we need to guess about the performance of our development machines or test environments.
Some may ask the Million Dollar $$ question as to why we would want to monitor our local installation. For starters, I am sort of monitoring mad and monitor everything. Second, in order to truly understand your environment, we need to dissect what is running and how it's running. Finally, it is a good practice to understand your environment and if it is impacting the performance of your workload or not.
Monitoring the Docker for Mac/Windows Daemon
Let's get started by configuring your installation. The following screenshots are from a Mac but the steps should work the same for Windows. We will now enable Daemon metrics on our Docker for Mac/Windows formatted for Prometheus
- Open Docker for Mac/Windows Preferences menu
Monitor with Prometheus
Our local Docker for Mac/Windows installation is now creating Prometheus formatted metrics. Next, let's start-up a Prometheus stack and consume these newly created metrics.
- Clone the Prometheus stack locally:
git clone https://github.com/vegasbrianc/prometheus.git .
- Edit the
prometheus/prometheus.yml
file. Navigate to the end of the file and find the section namestatic_configs
- Edit the target string to the with the hostname or IP of the machine running Docker for Mac/Windows:
- targets: ['hostname-here:9323']
- Save the file and exit
- Start the Prometheus stack:
docker-compose up -d
Configure Grafana
-
In a new browser tab open Grafana:
http://0.0.0.0:3000
-
Login to Grafana: username -
admin
password -foobar
-
After logging in you will be prompted with a green button to add a data source. Click
Add Data Source
-
Input the following information into the Data Source:
Name:Prometheus
Type:Prometheus
URL:http://prometheus:9090
Access: Leave default
HTTP Auth: ClickBasic Auth
user:admin
password:foobar
-
Click `Save & Test``
-
Click on the Grafana Logo in the upper right-hand corner, hover over Dashboards, and select
import
-
Type the number
1229
in the Grafana.com Dashboard input area and clickLoad
-
Everything should now be populated except for the last field that requires the data source. Click the drop-down and select
prometheus
and clickImport
Conclusion
We have set up the Docker Daemon log its metrics, configured and launched a Prometheus stack to consume these metrics, and finally imported a Grafana dashboard as a starting point. You should now be able to create some interesting graphs and reports based on your installation.
Happy monitoring.
Follow me
If you liked this article be sure to Follow Me on Twitter to stay updated!