Zabbix: Simple file count for Linux

Watch the files count of a dir on Linux with Zabbix.

In EDI based communications you often have a dir where EDI files get saved and wait for processing. Every now and then these processes don’t work and the file count grows. Of course this is only one example, but it’s often handy to have a trigger fire, when a certain folder has more than X files in it.

First edit your Zabbix agent configuration file:
nano /etc/zabbix/zabbix_agentd.conf

And add the following line:
UserParameter=xenadmin.filecount[*],ls -A1 $1 | wc -l

Let me explain the different parts:

UserParameter= Initiates the config optione in the zabbix_agentd.conf configuration file.
xenadmin. Custom prefix you may add, to make your item key unqiue (optional).
filecount Unique item key name.
[*] This key accepts parameters.
ls -A1 $1 | wc -l Command to be executed to evaluate value of the key.
$1 Up to $9 parameters can be used in the command.

Save & close the file and restart your Zabbix agent.

Now switch to your Zabbix frontend and configure a new item. Most of the time you will want to use a new or existing template for this:

This screenshot is just an example, but you’ll get the idea.

With Zabbix 4.0 this feature won’t require a UserParameter anymore, since it will become a native function:
vfs.dir.count[]

Author: Marco

Marco is an IT-System administrator and IT-Consultant with 10+ years experience. He is specialized in the delivery of virtual Apps and Desktops with Citrix solutions. In 2017 he has been awarded Citrix Technology Advocate by Citrix for his community work (#CTA). His second core area is availability & performance monitoring with Zabbix, a leading open-source solution. His employer is the German IT-Company ANAXCO, which is developing a Transport Management Software (TMS) based on Microsoft Dynamics AX. More about Marco

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.