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
This integration uses Grafana Alloy Docker service discovery feature to identify and collect logs. To do this, it must have access to docker daemon. To give this access, add the “alloy” user to “docker” group with the following command:
sudo usermod -a -G docker alloy
Elevated privileges are required to run cAdvisor in Grafana Alloy in standalone mode, See cAdvisor documentation. After installing Grafana Alloy, you must give it elevated permissions. Follow the instructions below:
Open the systemctl unit file to change the user running Grafana Alloy process:
sudo systemctl edit --full alloy.service
Change User=alloy
to User=root
and save the file.
Reload systemctl changes using:
sudo systemctl daemon-reload
Then restart Grafana Alloy:
sudo systemctl restart alloy.service
Install Docker integration for Grafana Cloud
- In your Grafana Cloud stack, click Connections in the left-hand menu.
- Find Docker and click its tile to open the integration.
- Review the prerequisites in the Configuration Details tab and set up Grafana Agent to send Docker metrics and logs to your Grafana Cloud instance.
- Click Install to add this integration’s pre-built dashboards to your Grafana Cloud instance, and you can start monitoring your Docker setup.
Configuration snippets for Grafana Alloy
Simple mode
These snippets are configured to scrape a single Docker engine running locally with default ports.
Manually copy and append the following snippets into your Grafana Alloy configuration file.
Integrations snippets
prometheus.exporter.cadvisor "integrations_cadvisor" {
docker_only = true
}
discovery.relabel "integrations_cadvisor" {
targets = prometheus.exporter.cadvisor.integrations_cadvisor.targets
rule {
target_label = "job"
replacement = "integrations/docker"
}
rule {
target_label = "instance"
replacement = constants.hostname
}
}
prometheus.scrape "integrations_cadvisor" {
targets = discovery.relabel.integrations_cadvisor.output
forward_to = [prometheus.remote_write.metrics_service.receiver]
}
Logs snippets
linux
Advanced mode
To instruct Grafana Alloy to scrape your docker engine, go though the subsequent instructions.
The snippets provide examples to guide you through the configuration process.
First, manually copy and append the following snippets into your Grafana Alloy configuration file.
Then follow the instructions below to modify the necessary variables.
Advanced integrations snippets
prometheus.exporter.cadvisor "integrations_cadvisor" {
docker_only = true
}
discovery.relabel "integrations_cadvisor" {
targets = prometheus.exporter.cadvisor.integrations_cadvisor.targets
rule {
target_label = "job"
replacement = "integrations/docker"
}
rule {
target_label = "instance"
replacement = constants.hostname
}
}
prometheus.scrape "integrations_cadvisor" {
targets = discovery.relabel.integrations_cadvisor.output
forward_to = [prometheus.remote_write.metrics_service.receiver]
}
Add a pair of prometheus.exporter.cadvisor and discovery.relabel to your Grafana Alloy configuration to monitor a docker daemon.
For ease of use, the provided snippets sets the instance
label to the hostname using the constants.hostname
Agent Flow constant variable.
If you want to monitor more than one daemon running within the same host, set a different value for each to avoid instance
label conflicts.
You will also need to set the docker_host
and containerd_host
properties within prometheus.exporter.cadvisor
for each daemon.
There is an array of options available within this component, like setting up tls connection, specific cgroup collection, amongst others.
Refer to prometheus.exporter.cadvisor in Grafana Alloy reference documentation for a complete description of the configuration options.
Finally, reference each discovery.relabel
component within the targets
property of the prometheus.scrape component.
Advanced logs snippets
linux
Add a group of discovery.docker, discovery.relabel and loki.source.docker to your Grafana Alloy configuration to monitor a docker daemon.
For ease of use, the provided snippets sets the instance
label to the hostname using the constants.hostname
Agent Flow constant variable.
If you want to monitor more than one daemon running within the same host, set a different value for each to avoid instance
label conflicts.
You will also need to set the host
property within discovery.docker
and loki.source.docker
for each daemon.
Make sure that for each docker daemon you are monitoring the instance label is set to the same value within the discovery.relabel
components collecting cadvisor metrics and the daemon logs.
Grafana Agent static configuration (deprecated)
The following section shows configuration for running Grafana Agent in static mode which is deprecated. You should use Grafana Alloy for all new deployments.
Before you begin
The integration collects Docker container metrics through embedded cAdvisor in Grafana agent. This integration is only suited for Linux docker engine. For Windows & Mac, the Docker Desktop for Grafana Cloud can be used.
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
- In your Grafana Cloud stack, click Connections in the left-hand menu.
- Find Docker and click its tile to open the integration.
- Review the prerequisites in the Configuration Details tab and set up Grafana Agent to send Docker metrics and logs to your Grafana Cloud instance.
- 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
andinstance
label values must match forcadvisor
integration andlogs
scrape config in your agent configuration file.job
label must be set tointegrations/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 forcadvisor
integration and the second relabel_config forlogs
scrape). Note that if you uselocalhost
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: '<your-instance-name>' # must match instance used in logs
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
target_label: job
- action: replace
replacement: '<your-instance-name>' # must match instance used in cadvisor
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.
Dashboards
The Docker integration installs the following dashboards in your Grafana Cloud instance to help monitor your system.
- Docker Logs
- Docker Overview
Overview & Compute
Logs
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
- up
Changelog
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.