INT 21h

Hi, I am Vladimir Smagin, SysAdmin and Kaptain. Telegram Email / GIT / Thingiverse / RSS / GPG

Zabbix automatic discovery and monitoring Docker containers

№ 9617 В разделе "Sysadmin" от December 2nd, 2018,
В подшивках: , ,

At first, you need to install jq utility to generate JSON in bash. You are SA, you know how to do it.

JSON you want to receive from agent looks like:

{"data":[{"{#CONTAINER}":"git"},{"{#CONTAINER}":"ark_storage_api"},{"{#CONTAINER}":"telegram-microblog-poster"},{"{#CONTAINER}":"telegram-microblog-site"},{"{#CONTAINER}":"mqtt-zabbix-agent"},{"{#CONTAINER}":"sbnc"},{"{#CONTAINER}":"mqtt-bus"},{"{#CONTAINER}":"zabbix-server"},{"{#CONTAINER}":"telegram-post-bot"},{"{#CONTAINER}":"mat-generator"},{"{#CONTAINER}":"ark-log-server"},{"{#CONTAINER}":"zabbix-panel"},{"{#CONTAINER}":"splash"},{"{#CONTAINER}":"mariadb"},{"{#CONTAINER}":"postgres"}]}

Create new custom config on target host /etc/zabbix/zabbix_agentd.d/docker.conf [download]

UserParameter=docker.running[*],docker ps -a -f status=running -f name="$1" | grep "$1$"
UserParameter=docker.containers_running,docker ps -f status=running -q|wc -l
UserParameter=docker.containers_all,docker ps -a -q|wc -l
UserParameter=docker.discovery,echo -n "$(docker ps -a -q --format='{{.Names}}')"|/usr/bin/jq -R -s -c '{data:  split("\n") | map({"{#CONTAINER}": (.)}) }'

You can import my xml with template, or create your own below.

Sample graph in my template

Now create new template “Template Docker containers” with Application “Docker” and discovery rule “Docker containers discovery”. Just like on screenshot below.

Now create templates for Item and Trigger

At last step assign newly created template to your monitored host.

Great! Now you can see statuses and receive alerts.

7 комментариев »

7 responses to “Zabbix automatic discovery and monitoring Docker containers”

  1. Ruslan says:

    в правиле обнаружений ошибка – Value should be a JSON object.

  2. 21h says:

    а точно именно json отдается?

  3. Axet says:

    something is wrong

    Invalid discovery rule value: cannot parse as a valid JSON object: invalid object format, expected opening character ‘{‘ or ‘[‘ at: ‘3proxy
    registry |/usr/bin/jq -R -s -c {data: split(”
    “) | map({“{#CONTAINER}”: (.)}) }’

  4. 21h says:

    my config https://paste.ubuntu.com/p/2vNg6ZPKz8/
    may be something wrong with your containers list, please paste it to https://paste.ubuntu.com/

  5. S1str says:

    Ошибка скорее всего из-за того что нет прав на запуск команды

  6. Влад says:

    Почему не срабатывает тригер?

  7. 21h says:

    Влад, спасибо за помощь в поиске бага, обновил конфиг.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Яндекс.Метрика

Fortune cookie: I ain't got no quarrel with them Viet Congs. -- Muhammad Ali