Monitoring Linux directory size in Zabbix

One day I needed to monitor the size of a directory in Zabbix and create a trigger so that Zabbix would notify when the directory size increases.

Naturally, a trigger for a small amount of free space on a disk system is already present in the standard Template OS Linux templates (Mounted filesystem discovery), but it was not enough for, for example, a non-rotated log file to occupy almost the entire disk system, in my case, for example, the ABillS developers have an sms module for lack of connection with the SMS server, which could record gigabytes of logs in an hour, I made rotation scripts for some logs, but it is unknown what other files will appear in new versions of ABillS, so monitoring the directory size will not hurt.

A simple command to check directory size:

du -h -s /usr/abills/

I got:

2.7G /usr/abills/

It turns out that you need to trim the last 12 characters, space and the letter G, that is, 14 characters, I did it like this:

du -h -s /usr/abills/ | sed -r 's/(.+).{14}/\1/'

The result is a number that can be passed to Zabbix:

2.7

Next, I opened the /etc/zabbix/zabbix_agentd.conf file and added at the end:

UserParameter=dir_size_usr_abills,du -h -s /usr/abills/ | sed -r 's/(.+).{14}/\1/'

Rebooted zabbix-agent to apply the configuration:

service zabbix-agent restart

Now you can add a data element with the key “dir_size_usr_abills” and the Zabbix agent type to your template, use it to create a graph and, for example, a trigger with the expression:

last(/ixnfo.com_template/dir_size_usr_abills)>3.5

Leave a comment

Leave a Reply