9 df - Munin plugin to monitor disk usage
 
  11 =head1 APPLICABLE SYSTEMS
 
  13 Every Linux system with df installed.
 
  17 The plugin excludes per default the following special, read-only or
 
  18 dynamically allocating file systems from graphing:
 
  20   none unknown rootfs iso9660 squashfs udf romfs ramfs debugfs cgroup_root
 
  22 To change this set the environment variable "exclude" with a list of
 
  23 space separated fs types.  The environment variables "warning" and
 
  24 "critical" sets the percentage from which Munin starts to warn about
 
  27 This configuration snipplet is an example with the defaults:
 
  30     env.exclude none unknown rootfs iso9660 squashfs udf romfs ramfs debugfs cgroup_root devtmpfs
 
  34 Put it in a file in /etc/munin/plugin-conf.d/ and restart the munin-node.
 
  36 You may specify filesystem specific warning and critical levels:
 
  38     env._dev_sda2_warning 98
 
  39     env._dev_sda2_critical 99
 
  41 Devices can be explicitly included or excluded based on their mountpoint or
 
  42 device name using the include_re and exclude_re environment variables.  These
 
  43 environment variables are parsed as whitespace separated regular expressions.
 
  44 For example, if you wish to ignore the filesystem on /dev/sda2 and all
 
  45 filesystems mounted under /var except /var/tmp, these rules would achieve this:
 
  47     env.include_re ^/var/tmp$
 
  48     env.exclude_re /dev/sda2 ^/var/
 
  50 Please note that these expressions are tried against both mountpoints and
 
  51 device names, therefore broad matches could potentially filter out desired
 
  52 devices.  Anchoring is also useful for avoiding false positives (as seen in the
 
  53 example), but not strictly necessary.  Testing with munin-run is always a good
 
  56 Also note that a mountpoint that is excluded by filesystem type but included by
 
  57 RE will not be included.
 
  61 Link this plugin to /etc/munin/plugins/ and restart the munin-node.
 
  66   #%# capabilities=autoconf
 
  70 Uses device names instead of mount points to identify mounted
 
  85 # For these devices use the mount point, the device is useless
 
  86 my %usemntpt = ( tmpfs => 1, none => 1, udev => 1, simfs => 1 );
 
  88 my $exclude = $ENV{'exclude'} || 'none unknown rootfs iso9660 squashfs udf romfs ramfs debugfs cgroup_root devtmpfs';
 
  89 my $dfopts  = "-P -l ".join(' -x ',('',split('\s+',$exclude)));
 
  91 my $mode = ($ARGV[0] or "print");
 
  93 # Compile REs from env
 
  95 if (defined $ENV{include_re}) {
 
  96     foreach my $re (split m{\s+}, $ENV{include_re}) {
 
  97         push @include_re, qr/$re/;
 
 101 if (defined $ENV{exclude_re}) {
 
 102     foreach my $re (split m{\s+}, $ENV{exclude_re}) {
 
 103         push @exclude_re, qr/$re/;
 
 111     foreach my $re (@include_re) {
 
 112         return 0 if ($name =~ $re or $mountpt =~ $re);
 
 115     foreach my $re (@exclude_re) {
 
 116         return 1 if ($name =~ $re or $mountpt =~ $re);
 
 122 if ($mode eq 'autoconf' ) {
 
 123     if (`/usr/bin/perl $0` eq '' ) {
 
 124         print "no (no devices to monitor)\n";
 
 131 if ($mode eq 'config' ) {
 
 133     print "graph_title Disk usage in percent\n";
 
 134     print "graph_args --upper-limit 100 -l 0\n";
 
 135     print "graph_vlabel %\n";
 
 136     print "graph_scale no\n";
 
 137     print "graph_category disk\n";
 
 141 open (DF,"df $dfopts 2>/dev/null | tail -n+2 | sort -k6 |") or die "Unable to open pipe from df: $!";
 
 142 #<DF>; # Skip the header
 
 147     my ($name, undef, $used, $avail, undef, $mountpt, undef) = split(/\s+/, $_, 7);
 
 149     next if skip($name, $mountpt);
 
 151     # Calculate percentage used
 
 153     $ps = ($used / ($used+$avail)) * 100 if $used;
 
 155     $name = $mountpt; # if defined($usemntpt{$name}) && $usemntpt{$name};
 
 156     $name = clean_fieldname($name);
 
 158     if($mode eq 'config') {
 
 159         print $name, ".label ", $mountpt, "\n";
 
 160         print_thresholds($name,undef,undef,92,98);
 
 162         print $name, ".value ", $ps, "\n";
 
 167 # vim: ft=perl : sw=4 : ts=4 : et