Menu
Grafana Cloud

Docker integration for Grafana Cloud

Docker is a popular open-source platform that enables developers to create, deploy, and run applications in a virtualized environment called a container. It allows developers to package an application with all its dependencies, libraries, and other components required to run it, into a single container image. The Docker integration collects metrics and logs from a Docker instance and provides useful pre-built dashboards to monitor them.

This integration includes 2 pre-built dashboards to help monitor and visualize Docker metrics and logs.

Before you begin

The integration collects Docker container metrics through embedded cAdvisor in Grafana agent

This integration uses the Docker service discovery feature of the Grafana agent to identify and collect logs. In order for the integration to work, the Grafana agent must have access to docker daemon. To give the agent access to docker daemon, you need to add the “grafana-agent” user to “docker” group with the following command:

sudo usermod -a -G docker grafana-agent

Elevated privileges are required to run cAdvisor in Grafana agent in standalone mode, See cAdvisor documentation. After installing the Grafana agent, you can give the agent elevated permissions by changing the user of the Grafana agent installed service by editing the systemctl unit file:

sudo systemctl edit --full grafana-agent.service

Change User=grafana-agent to User=root and save the file. Then reload systemctl changes using:

sudo systemctl daemon-reload

Then restart the Grafana agent:

sudo systemctl restart grafana-agent.service

Install Docker integration for Grafana Cloud

  1. In your Grafana Cloud stack, click Connections in the left-hand menu.
  2. Find Docker and click its tile to open the integration.
  3. Review the prerequisites in the Configuration Details tab and set up Grafana Agent to send Docker metrics and logs to your Grafana Cloud instance.
  4. Click Install to add this integration’s pre-built dashboards to your Grafana Cloud instance, and you can start monitoring your Docker setup.

Post-install configuration for the Docker integration

This integration is configured to work with the cadvisor exporter, which is embedded in Grafana Agent.

Enable the integration by adding the provided snippet to your agent configuration file.

This integration supports metrics and logs for Docker containers. If you want to see your logs and metrics correlated on your dashboards, as a single pane of glass, ensure the following:

  • job and instance label values must match for cadvisor integration and logs scrape config in your agent configuration file.
  • job label must be set to integrations/docker (already configured in the snippets through relabel_configs).
  • instance label must be set to a value that uniquely identifies your Docker Node. Replace it according to your environment (instance entry for cadvisor integration and the second relabel_config for logs scrape). Note that if you use localhost for multiple nodes, the dashboards will not be able to filter correctly by instance.

The log snippet is configured to collect logs from Docker using Docker service discovery.

For a full description of configuration options see how to configure the cadvisor_config block in the agent documentation.

Configuration snippets for Grafana Agent

Below integrations, insert the following lines and change the URLs according to your environment:

  cadvisor:
    enabled: true
    docker_only: true
    instance: localhost:9090
    relabel_configs:
      - action: replace
        replacement: integrations/docker
        target_label: job

Below logs.configs.scrape_configs, insert the following lines according to your environment.

    - job_name: integrations/docker
      docker_sd_configs:
        - host: unix:///var/run/docker.sock
          refresh_interval: 5s
      relabel_configs:
        - action: replace
          replacement: integrations/docker
          source_labels: 
            - __meta_docker_container_id
          target_label: job
        - action: replace
          replacement: localhost:9090
          source_labels:
            - __meta_docker_container_id
          target_label: instance
        - source_labels:
            - __meta_docker_container_name
          regex: '/(.*)'
          target_label: container
        - source_labels: 
            - __meta_docker_container_log_stream
          target_label: stream

Full example configuration for Grafana Agent

Refer to the following Grafana Agent configuration for a complete example that contains all the snippets used for the Docker integration. This example also includes metrics that are sent to monitor your Grafana Agent instance.

integrations:
  agent:
    enabled: true
    relabel_configs:
    - action: replace
      source_labels:
      - agent_hostname
      target_label: instance
    - action: replace
      target_label: job
      replacement: "integrations/agent-check"
    metric_relabel_configs:
    - action: keep
      regex: (prometheus_target_.*|prometheus_sd_discovered_targets|agent_build.*|agent_wal_samples_appended_total|process_start_time_seconds)
      source_labels:
      - __name__
  cadvisor:
    enabled: true
    docker_only: true
    instance: localhost:9090
    relabel_configs:
      - action: replace
        replacement: integrations/docker
        target_label: job
  prometheus_remote_write:
  - basic_auth:
      password: <your_prom_pass>
      username: <your_prom_user>
    url: <your_prom_url>
logs:
  configs:
  - clients:
    - basic_auth:
        password: <your_loki_pass>
        username: <your_loki_user>
      url: <your_loki_url>
    name: integrations
    positions:
      filename: /tmp/positions.yaml
    scrape_configs:
    - job_name: integrations/docker
      docker_sd_configs:
        - host: unix:///var/run/docker.sock
          refresh_interval: 5s
      relabel_configs:
        - action: replace
          replacement: integrations/docker
          source_labels: 
            - __meta_docker_container_id
          target_label: job
        - action: replace
          replacement: localhost:9090
          source_labels:
            - __meta_docker_container_id
          target_label: instance
        - source_labels:
            - __meta_docker_container_name
          regex: '/(.*)'
          target_label: container
        - source_labels: 
            - __meta_docker_container_log_stream
          target_label: stream
metrics:
  configs:
  - name: integrations
    remote_write:
    - basic_auth:
        password: <your_prom_pass>
        username: <your_prom_user>
      url: <your_prom_url>
    scrape_configs:
  global:
    scrape_interval: 60s
  wal_directory: /tmp/grafana-agent-wal

Dashboards

The Docker integration installs the following dashboards in your Grafana Cloud instance to help monitor your system.

  • Docker Logs
  • Docker Overview

Overview & Compute

image

Logs

image

Metrics

The most important metrics provided by the Docker integration, which are used on the pre-built dashboards, are as follows:

  • container_cpu_usage_seconds_total
  • container_fs_inodes_free
  • container_fs_inodes_total
  • container_fs_limit_bytes
  • container_fs_usage_bytes
  • container_last_seen
  • container_memory_usage_bytes
  • container_network_receive_bytes_total
  • container_network_tcp_usage_total
  • container_network_transmit_bytes_total
  • container_spec_memory_reservation_limit_bytes
  • machine_memory_bytes
  • machine_scrape_error

Changelog

# 0.0.6 - April 2023

* Add missing descriptions to panels

# 0.0.5 - November 2022

* Add integration status panel

# 0.0.4 - May 2022

* Update mixin to latest version:
  - Fix log line counts

# 0.0.3 - April 2022

* Add instructions for scraping docker logs
* Update integration to work with embedded Grafana agent Cadvisor

# 0.0.2 - April 2022

* Update mixin to latest version:
  - Update variable display names
  - Rename datasource to prometheus_datasource
  - Group by instance as well on disk usage
  - Fix total images / containers showing up as double
  - Add integration status panels
  - Convert to gridpos
  - Remove deprecated singlestat panel
  - Disable shared tooltip

# 0.0.1 - October 2020

* Initial release

Cost

By connecting your Docker instance to Grafana Cloud, you might incur charges. To view information on the number of active series that your Grafana Cloud account uses for metrics included in each Cloud tier, see Active series and dpm usage and Cloud tier pricing.