1 minute read (172 words).

Incorrect LXC monitoring values with Zabbix


Linux

Zabbix is by far the best monitoring solution available however when I moved from Hyper-V 2016 to Proxmox and LXC, I noticed that the standard Linux templates pulled incorrect values for CPU, RAM and Disk usage. Given the way LXC works, the values were actually the hosts.

I did some Googling and found an excellent project on Github which provided an XML template and Zabbix Agent UserParameters for calculating the values correctly.

kvaps/zabbix-linux-container-template: Zabbix template for LXC container (github.com)

Simply add the following to your agents config file and import the template.

vi /etc/zabbix/zabbix_agentd.conf
### UserParameters for LXC Monitoring
UserParameter=ct.memory.size[*],free -b | awk '$ 1 == "Mem:" {total=$ 2; used=($ 3+$ 5); pused=(($ 3+$ 5)*100/$ 2); free=$ 4; pfree=($ 4*100/$ 2); shared=$ 5; buffers=$ 6; cache=$ 6; available=($ 6+$ 7); pavailable=(($ 6+$ 7)*100/$ 2); if("$1" == "") {printf("%.0f", total )} else {printf("%.0f", $1 "" )} }'
UserParameter=ct.swap.size[*],free -b | awk '$ 1 == "Swap:" {total=$ 2; used=$ 3; free=$ 4; pfree=($ 4*100/$ 2); pused=($ 3*100/$ 2); if("$1" == "") {printf("%.0f", free )} else {printf("%.0f", $1 "" )} }'
UserParameter=ct.cpu.load[*],uptime | awk -F'[, ]+' '{avg1=$(NF-2); avg5=$(NF-1); avg15=$(NF)}{print $2/'$(nproc)'}'


Share via Twitter LinkedIn Facebook Email