/ docker

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

  1. Open Docker for Mac/Windows Preferences menu

Docker Preferences

2. Navigate to the `Daemon` menu and click `Advanced`

Docker Daemon

3. Inside the box of code, we will add an additional line to enable the metrics. Add the following line of code below the `debug` statement: `metrics-addr" : "0.0.0.0:9323",` 4. Click `Àpply & Restart` and wait for Docker to come back online. 5. Test it out. Open a browser tab with the following URL: `http://127.0.0.1:9323/metrics`

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.

  1. Clone the Prometheus stack locally: git clone https://github.com/vegasbrianc/prometheus.git .
  2. Edit the prometheus/prometheus.yml file. Navigate to the end of the file and find the section name static_configs
  3. Edit the target string to the with the hostname or IP of the machine running Docker for Mac/Windows: - targets: ['hostname-here:9323']
  4. Save the file and exit
  5. Start the Prometheus stack: docker-compose up -d

Configure Grafana

  1. In a new browser tab open Grafana: http://0.0.0.0:3000

  2. Login to Grafana: username - admin password - foobar

  3. After logging in you will be prompted with a green button to add a data source. Click Add Data Source

  4. Input the following information into the Data Source:
    Name: Prometheus
    Type: Prometheus
    URL: http://prometheus:9090
    Access: Leave default
    HTTP Auth: Click Basic Auth
    user: admin
    password: foobar

  5. Click `Save & Test``
    Configure Grafana Data Source

  6. Click on the Grafana Logo in the upper right-hand corner, hover over Dashboards, and select import

  7. Type the number 1229 in the Grafana.com Dashboard input area and click Load

  8. Everything should now be populated except for the last field that requires the data source. Click the drop-down and select prometheus and click Import
    Import Grafana Dashboard

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.

Brian Christner

Brian Christner

Brian's spent a large portion of his career in the casino industry where he made sure the house always won. Brian is a nominated member of the Docker Captain’s program and a seasoned cloud architect.

Read More