# Docker by Zabbix agent 2 ## Overview The template to monitor Docker engine by Zabbix that work without any external scripts. Most of the metrics are collected in one go, thanks to Zabbix bulk data collection. Template `Docker by Zabbix agent 2` — collects metrics by polling zabbix-agent2. ## Requirements Zabbix version: 7.0 and higher. ## Tested versions This template has been tested on: - Docker 23.0.3 ## Configuration > Zabbix should be configured according to the instructions in the [Templates out of the box](https://www.zabbix.com/documentation/7.0/manual/config/templates_out_of_the_box) section. ## Setup Setup and configure Zabbix agent 2 compiled with the Docker monitoring plugin. The user by which the Zabbix agent 2 is running should have access permissions to the Docker socket. Test availability: `zabbix_get -s docker-host -k docker.info` ### Macros used |Name|Description|Default| |----|-----------|-------| |{$DOCKER.LLD.FILTER.CONTAINER.MATCHES}|
Filter of discoverable containers.
|`.*`| |{$DOCKER.LLD.FILTER.CONTAINER.NOT_MATCHES}|Filter to exclude discovered containers.
|`CHANGE_IF_NEEDED`| |{$DOCKER.LLD.FILTER.IMAGE.MATCHES}|Filter of discoverable images.
|`.*`| |{$DOCKER.LLD.FILTER.IMAGE.NOT_MATCHES}|Filter to exclude discovered images.
|`CHANGE_IF_NEEDED`| ### Items |Name|Description|Type|Key and additional info| |----|-----------|----|-----------------------| |Docker: Ping||Zabbix agent|docker.ping**Preprocessing**
Discard unchanged with heartbeat: `10m`
Total number of containers on this host.
|Dependent item|docker.containers.total**Preprocessing**
JSON Path: `$.Containers`
Total number of containers running on this host.
|Dependent item|docker.containers.running**Preprocessing**
JSON Path: `$.ContainersRunning`
Total number of containers stopped on this host.
|Dependent item|docker.containers.stopped**Preprocessing**
JSON Path: `$.ContainersStopped`
Total number of containers paused on this host.
|Dependent item|docker.containers.paused**Preprocessing**
JSON Path: `$.ContainersPaused`
Number of images with intermediate image layers.
|Dependent item|docker.images.total**Preprocessing**
JSON Path: `$.Images`
Docker storage driver.
https://docs.docker.com/storage/storagedriver/
|Dependent item|docker.driver**Preprocessing**
JSON Path: `$.Driver`
Discard unchanged with heartbeat: `1d`
**Preprocessing**
JSON Path: `$.MemoryLimit`
Discard unchanged with heartbeat: `1d`
**Preprocessing**
JSON Path: `$.SwapLimit`
Discard unchanged with heartbeat: `1d`
**Preprocessing**
JSON Path: `$.KernelMemory`
Discard unchanged with heartbeat: `1d`
**Preprocessing**
JSON Path: `$.KernelMemoryTCP`
Discard unchanged with heartbeat: `1d`
https://docs.docker.com/config/containers/resource_constraints/#configure-the-default-cfs-scheduler
|Dependent item|docker.cpu_cfs_period.enabled**Preprocessing**
JSON Path: `$.CpuCfsPeriod`
Discard unchanged with heartbeat: `1d`
https://docs.docker.com/config/containers/resource_constraints/#configure-the-default-cfs-scheduler
|Dependent item|docker.cpu_cfs_quota.enabled**Preprocessing**
JSON Path: `$.CpuCfsQuota`
Discard unchanged with heartbeat: `1d`
https://docs.docker.com/config/containers/resource_constraints/#configure-the-default-cfs-scheduler
|Dependent item|docker.cpu_shares.enabled**Preprocessing**
JSON Path: `$.CPUShares`
Discard unchanged with heartbeat: `1d`
https://docs.docker.com/config/containers/resource_constraints/#configure-the-default-cfs-scheduler
|Dependent item|docker.cpu_set.enabled**Preprocessing**
JSON Path: `$.CPUSet`
Discard unchanged with heartbeat: `1d`
**Preprocessing**
JSON Path: `$.PidsLimit`
Discard unchanged with heartbeat: `1d`
**Preprocessing**
JSON Path: `$.IPv4Forwarding`
Discard unchanged with heartbeat: `1d`
**Preprocessing**
JSON Path: `$.Debug`
Discard unchanged with heartbeat: `1d`
Number of used File Descriptors.
|Dependent item|docker.nfd**Preprocessing**
JSON Path: `$.NFd`
**Preprocessing**
JSON Path: `$.OomKillDisable`
Discard unchanged with heartbeat: `1d`
Number of goroutines.
|Dependent item|docker.goroutines**Preprocessing**
JSON Path: `$.NGoroutines`
**Preprocessing**
JSON Path: `$.LoggingDriver`
Discard unchanged with heartbeat: `1d`
**Preprocessing**
JSON Path: `$.CgroupDriver`
Discard unchanged with heartbeat: `1d`
**Preprocessing**
JSON Path: `$.NEventsListener`
**Preprocessing**
JSON Path: `$.KernelVersion`
Discard unchanged with heartbeat: `1d`
**Preprocessing**
JSON Path: `$.OperatingSystem`
Discard unchanged with heartbeat: `1d`
**Preprocessing**
JSON Path: `$.OSType`
Discard unchanged with heartbeat: `1d`
**Preprocessing**
JSON Path: `$.Architecture`
Discard unchanged with heartbeat: `1d`
**Preprocessing**
JSON Path: `$.NCPU`
**Preprocessing**
JSON Path: `$.MemTotal`
**Preprocessing**
JSON Path: `$.DockerRootDir`
Discard unchanged with heartbeat: `1d`
**Preprocessing**
JSON Path: `$.Name`
**Preprocessing**
JSON Path: `$.ServerVersion`
Discard unchanged with heartbeat: `1d`
**Preprocessing**
JSON Path: `$.DefaultRuntime`
Discard unchanged with heartbeat: `1d`
**Preprocessing**
JSON Path: `$.LiveRestoreEnabled`
Discard unchanged with heartbeat: `1d`
**Preprocessing**
JSON Path: `$.LayersSize`
**Preprocessing**
JSON Path: `$.Images[*].Size.sum()`
**Preprocessing**
JSON Path: `$.Containers[*].SizeRw.sum()`
**Preprocessing**
JSON Path: `$.Volumes[*].UsageData.Size.sum()`
Number of top-level images.
|Dependent item|docker.images.top_level**Preprocessing**
JSON Path: `$.length()`
Zabbix has not received data for items for the last 30 minutes.
|`nodata(/Docker by Zabbix agent 2/docker.name,30m)=1`|Warning|**Manual close**: YesDocker version has changed. Acknowledge to close the problem manually.
|`last(/Docker by Zabbix agent 2/docker.server_version,#1)<>last(/Docker by Zabbix agent 2/docker.server_version,#2) and length(last(/Docker by Zabbix agent 2/docker.server_version))>0`|Info|**Manual close**: Yes| ### LLD rule Images discovery |Name|Description|Type|Key and additional info| |----|-----------|----|-----------------------| |Images discovery|Discovery of images metrics.
|Zabbix agent|docker.images.discovery| ### Item prototypes for Images discovery |Name|Description|Type|Key and additional info| |----|-----------|----|-----------------------| |Image {#NAME}: Created||Dependent item|docker.image.created["{#ID}"]**Preprocessing**
JSON Path: `$[?(@.Id == "{#ID}")].Created.first()`
Discard unchanged with heartbeat: `1d`
**Preprocessing**
JSON Path: `$[?(@.Id == "{#ID}")].Size.first()`
Discovery of containers metrics.
Parameter:
true - Returns all containers
false - Returns only running containers
|Zabbix agent|docker.containers.discovery[false]| ### Item prototypes for Containers discovery |Name|Description|Type|Key and additional info| |----|-----------|----|-----------------------| |Container {#NAME}: Get stats|Get container stats based on resource usage.
|Zabbix agent|docker.container_stats["{#NAME}"]| |Container {#NAME}: CPU total usage per second||Dependent item|docker.container_stats.cpu_usage.total.rate["{#NAME}"]**Preprocessing**
JSON Path: `$.cpu_stats.cpu_usage.total_usage`
Custom multiplier: `1.0E-9`
**Preprocessing**
JSON Path: `$.cpu_stats.cpu_usage.percent_usage`
**Preprocessing**
JSON Path: `$.cpu_stats.cpu_usage.usage_in_kernelmode`
Custom multiplier: `1.0E-9`
**Preprocessing**
JSON Path: `$.cpu_stats.cpu_usage.usage_in_usermode`
Custom multiplier: `1.0E-9`
**Preprocessing**
JSON Path: `$.cpu_stats.online_cpus`
Number of periods with throttling active.
|Dependent item|docker.container_stats.cpu_usage.throttling_periods["{#NAME}"]**Preprocessing**
JSON Path: `$.cpu_stats.throttling_data.periods`
Number of periods when the container hits its throttling limit.
|Dependent item|docker.container_stats.cpu_usage.throttled_periods["{#NAME}"]**Preprocessing**
JSON Path: `$.cpu_stats.throttling_data.throttled_periods`
Aggregate time the container was throttled for in nanoseconds.
|Dependent item|docker.container_stats.cpu_usage.throttled_time["{#NAME}"]**Preprocessing**
JSON Path: `$.cpu_stats.throttling_data.throttled_time`
Custom multiplier: `1.0E-9`
**Preprocessing**
JSON Path: `$.memory_stats.usage`
**Preprocessing**
JSON Path: `$.memory_stats.max_usage`
**Preprocessing**
JSON Path: `$.memory_stats.commitbytes`
**Preprocessing**
JSON Path: `$.memory_stats.commitpeakbytes`
**Preprocessing**
JSON Path: `$.memory_stats.privateworkingset`
Current number of PIDs the container has created.
|Dependent item|docker.container_stats.pids_stats.current["{#NAME}"]**Preprocessing**
JSON Path: `$.pids_stats.current`
**Preprocessing**
JSON Path: `$.networks[*].rx_bytes.sum()`
⛔️Custom on fail: Set value to: `0`
**Preprocessing**
JSON Path: `$.networks[*].rx_packets.sum()`
⛔️Custom on fail: Set value to: `0`
**Preprocessing**
JSON Path: `$.networks[*].rx_errors.sum()`
⛔️Custom on fail: Set value to: `0`
**Preprocessing**
JSON Path: `$.networks[*].rx_dropped.sum()`
⛔️Custom on fail: Set value to: `0`
**Preprocessing**
JSON Path: `$.networks[*].tx_bytes.sum()`
⛔️Custom on fail: Set value to: `0`
**Preprocessing**
JSON Path: `$.networks[*].tx_packets.sum()`
⛔️Custom on fail: Set value to: `0`
**Preprocessing**
JSON Path: `$.networks[*].tx_errors.sum()`
⛔️Custom on fail: Set value to: `0`
**Preprocessing**
JSON Path: `$.networks[*].tx_dropped.sum()`
⛔️Custom on fail: Set value to: `0`
Return low-level information about a container.
|Zabbix agent|docker.container_info["{#NAME}",full]| |Container {#NAME}: Created||Dependent item|docker.container_info.created["{#NAME}"]**Preprocessing**
JavaScript: `The text is too long. Please see the template.`
Discard unchanged with heartbeat: `1d`
**Preprocessing**
JSON Path: `$[?(@.Names[0] == "{#NAME}")].Image.first()`
Discard unchanged with heartbeat: `1d`
**Preprocessing**
JSON Path: `$.RestartCount`
**Preprocessing**
JSON Path: `$.State.Status`
Discard unchanged with heartbeat: `1h`
Container's `HEALTHCHECK`.
|Dependent item|docker.container_info.state.health["{#NAME}"]**Preprocessing**
JavaScript: `The text is too long. Please see the template.`
In range: `1 -> 4`
⛔️Custom on fail: Set value to: `4`
**Preprocessing**
JSON Path: `$.State.Health.FailingStreak`
⛔️Custom on fail: Discard value
Discard unchanged with heartbeat: `1h`
**Preprocessing**
JSON Path: `$.State.Running`
**Preprocessing**
JSON Path: `$.State.Paused`
**Preprocessing**
JSON Path: `$.State.Restarting`
**Preprocessing**
JSON Path: `$.State.OOMKilled`
**Preprocessing**
JSON Path: `$.State.Dead`
**Preprocessing**
JSON Path: `$.State.Pid`
Discard unchanged with heartbeat: `1d`
**Preprocessing**
JSON Path: `$.State.ExitCode`
Discard unchanged with heartbeat: `1d`
**Preprocessing**
JSON Path: `$.State.Error`
Discard unchanged with heartbeat: `1d`
**Preprocessing**
JavaScript: `The text is too long. Please see the template.`
Discard unchanged with heartbeat: `1d`
Time at which the container last terminated.
|Dependent item|docker.container_info.finished["{#NAME}"]**Preprocessing**
JavaScript: `The text is too long. Please see the template.`
Discard unchanged with heartbeat: `1d`
Container health state is unhealthy.
|`count(/Docker by Zabbix agent 2/docker.container_info.state.health["{#NAME}"],2m,,2)>=2`|High|| |Container {#NAME}: Container has been stopped with error code||`last(/Docker by Zabbix agent 2/docker.container_info.state.exitcode["{#NAME}"])>0 and last(/Docker by Zabbix agent 2/docker.container_info.state.running["{#NAME}"])=0`|Average|**Manual close**: Yes| |Container {#NAME}: An error has occurred in the container|Container {#NAME} has an error. Acknowledge to close the problem manually.
|`last(/Docker by Zabbix agent 2/docker.container_info.state.error["{#NAME}"],#1)<>last(/Docker by Zabbix agent 2/docker.container_info.state.error["{#NAME}"],#2) and length(last(/Docker by Zabbix agent 2/docker.container_info.state.error["{#NAME}"]))>0`|Warning|**Manual close**: Yes| ## Feedback Please report any issues with the template at [`https://support.zabbix.com`](https://support.zabbix.com) You can also provide feedback, discuss the template, or ask for help at [`ZABBIX forums`](https://www.zabbix.com/forum/zabbix-suggestions-and-feedback)