Changeset e607684de2bdbf415825c461584e8c8437511ab4
- Timestamp:
- 05/20/10 02:21:24
(8 years ago)
- Author:
- Mark Harrison <mark@omniti.com>
- git-committer:
- Mark Harrison <mark@omniti.com> 1274322084 +0000
- git-parent:
[d710bcb9b19ab354fa6cbab08cbe91dcee175e86]
- git-author:
- Mark Harrison <mark@omniti.com> 1274322084 +0000
- Message:
Convert Core::DiskFree? to support wildcard checks (refs #8)
git-svn-id: https://labs.omniti.com/resmon/branches/resmon2@387 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
rd1526ca |
re607684 |
|
26 | 26 | } |
---|
27 | 27 | |
---|
| 28 | Core::DiskFree { |
---|
| 29 | * : noop |
---|
| 30 | } |
---|
| 31 | |
---|
28 | 32 | =head1 DESCRIPTION |
---|
29 | 33 | |
---|
… | … | |
41 | 45 | |
---|
42 | 46 | The name of the check refers to the filesystem to check the free space on. It |
---|
43 | | can specify either the mountpoint or the device for the filesystem. |
---|
| 47 | can specify either the mountpoint or the device for the filesystem. If * is |
---|
| 48 | specified, fetch metrics for all mounted filesystems. |
---|
44 | 49 | |
---|
45 | 50 | =item dfcmd |
---|
… | … | |
48 | 53 | the default is not sufficient. It is optional and in most cases you do not |
---|
49 | 54 | need to set this. |
---|
| 55 | |
---|
| 56 | =item excludes |
---|
| 57 | |
---|
| 58 | This is only used when * is specified for the check name. It contains a regex |
---|
| 59 | of filesystems to exclude from the results. If this isn't specified, a default |
---|
| 60 | regex is used that will exclude various common filesystems that aren't 'real' |
---|
| 61 | such as /proc or swap. |
---|
50 | 62 | |
---|
51 | 63 | =back |
---|
… | … | |
104 | 116 | }; |
---|
105 | 117 | |
---|
| 118 | sub wildcard_handler { |
---|
| 119 | my $self = shift; |
---|
| 120 | my $config = $self->{config}; |
---|
| 121 | my $dfcmd = $config->{dfcmd} || $self->{default_dfcmd}; |
---|
| 122 | my $excludes = $config->{excludes}; |
---|
| 123 | if (!defined $excludes) { |
---|
| 124 | # Exclude some default 'fake' filesystems |
---|
| 125 | $excludes = "^(none|swap|proc|ctfs|mnttab|objfs|fd)\$"; |
---|
| 126 | } |
---|
| 127 | my $metrics = {}; |
---|
| 128 | |
---|
| 129 | my $output = run_command("$dfcmd"); |
---|
| 130 | for my $line (split /\n/, $output) { |
---|
| 131 | if($line =~ /^(\S+)\s+\d+\s+(\d+)\s+(\d+)\s+(\d+)%/) { |
---|
| 132 | my ($fs, $used, $free, $percent) = ($1, $2, $3, $4); |
---|
| 133 | next if $fs =~ /$excludes/; |
---|
| 134 | $metrics->{$fs} = { |
---|
| 135 | "used_KB" => [$used, "i"], |
---|
| 136 | "free_KB" => [$free, "i"], |
---|
| 137 | "used_percent" => [$percent, "i"] |
---|
| 138 | }; |
---|
| 139 | } |
---|
| 140 | } |
---|
| 141 | if (!%$metrics) { |
---|
| 142 | die "Unable to get free space\n"; |
---|
| 143 | } |
---|
| 144 | return $metrics; |
---|
| 145 | } |
---|
| 146 | |
---|
106 | 147 | 1; |
---|