This is the implementation of Zabbix Agent specifically for dynamic nature of Docker container monitoring and it works in active mode only, It's using two methods of collecting data from Docker, over the Docker Daemon API and through sysfs.
Tested and developed on Zabbix 3.2
NOTICE: This is not replacement for standard Zabbix Agent.
To start monitoring you need to do the following:
Running Zabbix Docker Agent on any instance will auto-create Host (Docker Instance) on Zabbix. Zabbix-Docker-Agent is sending periodically information about all running containers which is stored base64 encoded under item "Docker Groups and Containers" key "docker.instanceDiscovery".
zabbixDockerDiscovery is responsible for digesting docker.instanceDiscovery item data and:
Configuration is passed to Zabbix Docker Agent (agent) through environment variables. Two other things beside required env variables is sysfs cgroups directory and Docker Daemon socket which needs to be mounted as volume.
On some Linux systems required pseudo file system is located in /cgroup (e.g. AWS ECS) while on the other it might be in /sys/fs/cgroup/.
$ ls /cgroup/
blkio cpu cpuacct cpuset devices freezer hugetlb memory perf_even
$ ls /sys/fs/cgroup/
blkio/ cpu/ cpuacct/ cpuset/ devices/ freezer/ hugetlb/ memory/ net_cls/ net_prio/ perf_event/ pids/
It needs to be mounted inside agent container under /cgroupfs (e.g. -v /cgroup:/cgroupfs or -v /sys/fs/cgroup:/cgroupfs).
| First Header | Required | Default | Description |
|---|---|---|---|
| DOCKERHOST | Yes | Hostname used on Zabbix server for Docker Instance | |
| ZBX_SERVER_HOST | Yes | ||
| ZBX_SERVER_PORT | No | 10051 | |
| HOSTMETADATA | No | DockerInstance | |
| MAX_WORKERS | No | 5 | |
| CGROUPS_DIR | No | /cgroupfs | Directory where cgroup fs is mounted in container |
| LABELS | No | Docker labels used to create Zabbix Groups | |
| LOGLEVEL | No | INFO | CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET |
pip3 install zabbix-docker-agent
*/15 * * * * /usr/local/bin/zabbixDockerDiscovery 2>&1 >/dev/null
Easiest way to run the Zabbix Docker Agent is to start it as a container on the server instance that you want to monitor.
docker run -d --restart always --name zabbixAgent \
-e DOCKERHOST=$HOSTNAME \
-e ZBX_SERVER_HOST=zabbix-server.foo.bar \
-e LABELS="MyCluster,MyService" \
-v /cgroup:/cgroupfs \
-v /var/run/docker.sock:/var/run/docker.sock \
akomic/zabbix-docker-agent:0.2.3
docker run -d --restart always --name zabbixAgent \
-e DOCKERHOST=$(curl -s http://169.254.169.254/latest/meta-data/instance-id) \
-e ZBX_SERVER_HOST=zabbix-server.foo.bar \
-e LABELS="StackName,com.amazonaws.ecs.task-definition-family" \
-v /cgroup:/cgroupfs \
-v /var/run/docker.sock:/var/run/docker.sock \
akomic/zabbix-docker-agent:0.2.3
Edit and run zabbixDockerDiscovery on Zabbix Server.
docker exec -it zabbixAgent zabbixAgentd -t
Content type
Image
Digest
Size
76.1 MB
Last updated
about 9 years ago
docker pull akomic/zabbix-docker-agent