root/lib/Core/DiskInodes.pm

Revision d1526ca817ef305f15a4f6418c2699bee9663f51, 2.9 kB (checked in by Mark Harrison <mark@omniti.com>, 4 years ago)

Change modules to use die instead of manually returning an error metric

git-svn-id: https://labs.omniti.com/resmon/branches/resmon2@314 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55

  • Property mode set to 100644
Line 
1 package Core::DiskInodes;
2
3 use strict;
4 use warnings;
5
6 use base 'Resmon::Module';
7
8 use Resmon::ExtComm qw(run_command cache_command);
9
10 =pod
11
12 =head1 NAME
13
14 Core::DiskInodes - Monitor disk inode usage using df
15
16 =head1 SYNOPSIS
17
18  Core::DiskInodes {
19      /    : noop
20      /usr : noop
21      /var : noop
22  }
23
24  Core::DiskInodes {
25      / : dfcmd => /bin/df, dfregex => (\d+)\s+(\d+)\s+(\d+)\s+(\d+)%
26  }
27
28 =head1 DESCRIPTION
29
30 This module monitors the used/free inodes for a filesystem using the df
31 command.
32
33 =head1 CONFIGURATION
34
35 =over
36
37 =item check_name
38
39 The name of the check refers to the filesystem to check the inodes on. It can
40 specify either the mountpoint or the device for the filesystem.
41
42 =item dfcmd
43
44 This specifies the df command (including arguments) to run in the event that
45 the default is not sufficient. It is optional and in most cases you do not
46 need to set this.
47
48 =item dfregex
49
50 This specifies the a regex to match the output of the df command against in
51 the event that the version of df used outputs a different format than is
52 expected by this module. In most cases it is not required and matches are
53 provided for Linux, OpenBSD and Solaris.
54
55 The regex should contain 3 matching groups. They should match the used inodes,
56 free inodes, and percent used respectively.
57
58 =back
59
60 =head1 METRICS
61
62 =over
63
64 =item inodes_used
65
66 A count of the used inodes on the filesystem.
67
68 =item inodes_free
69
70 A count of the free inodes on the filesystem.
71
72 =item used_percent
73
74 The percentage of the total inodes that are used.
75
76 =back
77
78 =cut
79
80 sub new {
81     # This is only needed if you have initialization code. Most of the time,
82     # you can skip the new method and just implement a handler method.
83     my ($class, $check_name, $config) = @_;
84     my $self = $class->SUPER::new($check_name, $config);
85
86     # Come up with a sensible default for the df command args
87     if ($^O eq 'solaris') {
88         $self->{default_dfcmd} = 'df -Fufs -oi';
89         $self->{default_dfregex} = '\d+\s+(\d+)\s+(\d+)\s+(\d+)%';
90     } elsif ($^O eq 'openbsd') {
91         $self->{default_dfcmd} = 'df -i';
92         $self->{default_dfregex} = \
93             '\d+\s+\d+\s+-?\d+\s+\d+%\s+(\d+)\s+(\d+)\s+(\d+)%';
94     } else {
95         $self->{default_dfcmd} = 'df -iP';
96         $self->{default_dfregex} = '\d+\s+(\d+)\s+(\d+)\s+(\d+)%';
97     }
98
99     bless($self, $class);
100     return $self;
101 }
102
103 sub handler {
104     my $self = shift;
105     my $config = $self->{config};
106     my $fs = $self->{check_name};
107     my $dfcmd = $config->{dfcmd} || $self->{default_dfcmd};
108     my $dfregex = $config->{dfregex} || $self->{default_dfregex};
109
110     my $output = run_command("$dfcmd $fs");
111     my ($line) = grep(/$fs\s*/, split(/\n/, $output));
112     if($line =~ /$dfregex/) {
113         return {
114             "used_inodes" => [$1, "i"],
115             "free_inodes" => [$2, "i"],
116             "used_percent" => [$3, "i"]
117         };
118     } else {
119         # We couldn't match the output line
120         die "Unable to get free inode count\n";
121     }
122 };
123
124 1;
Note: See TracBrowser for help on using the browser.