Skip to content

Nagios Plugin check_filecount

Davide Madrisan edited this page Aug 31, 2022 · 3 revisions

check_filecount - returns the number of files found in one or more directories

[/etc/nrpe.d/check_filecount]
command[check_filecount]=/usr/lib/nagios/plugins/check_filecount -r -f -w 200 -c 250 /var/tmp/myapp
Usage note
This plugin returns the number of files in one or more directories.
Copyright (C) 2022 Davide Madrisan <[email protected]>

Usage:
  check_filecount [-w COUNTER] [-c COUNTER] [-f] [-H] [-l] [-r] [-u] \
        [-s SIZE] [-t AGE] [-n PATTERN] DIR [DIR...]
Options:
  -f, --regular-only       count regular files only
  -H, --include-hidden     do not skip the hidden files
  -l, --ignore-symlinks    ignore symlinks
  -n, --name               only count files that match PATTERN
  -r, --recursive          check recursively each subdirectory
  -s, --size               count only files of a specific size
  -t, --time               count only files of a specific age
  -u, --ignore-unknown     ignore file with type unknown
  -w, --warning COUNTER    warning threshold
  -c, --critical COUNTER   critical threshold
  -v, --verbose   show details for command-line debugging (Nagios may truncate output)
  -h, --help      display this help and exit
  -V, --version   output version information and exit
Note:
  By default, this plugin counts the directories and files (of every type)
  found in DIR, in a non recursive way.  The hidden files are ignored.
  Option "name".
    Only count files that match PATTERN, where PATTERN is a shell-like wildcard
    as understood by fnmatch(3).  Only the filename is checked against the
    pattern, not the entire path.
  Option "size".
    When SIZE is a positive number, only files that are at least this big
    are counted.  If SIZE is a negative number, this is inversed, i. e.
    only files smaller than the absolute value of SIZE are counted.
    A "multiplier" may be added: b (byte), k (kilobyte), m (megabyte),
    g (gigabyte), t (terabyte), and p (petabyte).  Please note that
    there are 1000 bytes in a kilobyte, not 1024.
  Option "time".
    If AGE is greater than zero, only files that haven't been touched in the
    last AGE seconds are counted.  If AGE is a negative number, this is
    inversed.  The number can also be followed by a "multiplier" to easily
    specify a larger timespan.  Valid multipliers are s (second), m (minute),
    h (hour), d (day), w (week), and y (year).
Examples:
  check_filecount -l -r /tmp
  check_filecount -w 150 -c 200 -f -r /var/log/myapp /tmp/myapp
  check_filecount -w 10 -c 15 -f -r -s -10.5k /tmp/myapp
  check_filecount -r -t -1h /tmp/myapp   # files modified in the last hour
  check_filecount -f -n "myapp-202207*.log" /var/log/myapp
Example of output
> /usr/lib/nagios/plugins/check_filecount -w 3500 -c 4000 -f -r /tmp /var/tmp
filecount OK - total number of files: 896 | /tmp_total=93 /tmp_regular=93 /tmp_unknown=0 /var/tmp_total=803 /var/tmp_regular=803 /var/tmp_unknown=0