Changeset e607684de2bdbf415825c461584e8c8437511ab4

Show
Ignore:
Timestamp:
05/20/10 02:21:24 (5 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
  • lib/Core/DiskFree.pm

    rd1526ca re607684  
    2626 } 
    2727 
     28 Core::DiskFree { 
     29    * : noop 
     30 } 
     31 
    2832=head1 DESCRIPTION 
    2933 
     
    4145 
    4246The 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. 
     47can specify either the mountpoint or the device for the filesystem. If * is 
     48specified, fetch metrics for all mounted filesystems. 
    4449 
    4550=item dfcmd 
     
    4853the default is not sufficient. It is optional and in most cases you do not 
    4954need to set this. 
     55 
     56=item excludes 
     57 
     58This is only used when * is specified for the check name. It contains a regex 
     59of filesystems to exclude from the results. If this isn't specified, a default 
     60regex is used that will exclude various common filesystems that aren't 'real' 
     61such as /proc or swap. 
    5062 
    5163=back 
     
    104116}; 
    105117 
     118sub 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 
    1061471;