Chapter 25. Determining File and Directory Sizes

For a specific example of a Perl plugin, we will look at check_du.pl.[296] It is used to determine the size of specified files or directories and to check whether the total size lies within preset thresholds. To do this, it calls the system program du:

user@linux:~$ du -cs /var/spool/var/log
26524   /var/spool
745640  /var/log
772164  total

When used with the -s option, du does not list all the individual subdirectories but just shows the total size. -c adds up individual values to reach a total size.

At the beginning, the plugin generates a new new Nagios::Plugin object with the new constructor so that it can make use of the functions of the module:

#!/usr/bin/perl -w use strict; use warnings; use FindBin; ...

Get Nagios, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.