20 |
my $ssh = shift @ARGV || ""; |
my $ssh = shift @ARGV || ""; |
21 |
my $mount = shift @ARGV || "/"; |
my $mount = shift @ARGV || "/"; |
22 |
|
|
23 |
my %df; |
# do we have Cache::FileCache installed? |
24 |
|
|
25 |
|
my $USE_CACHE = 0; |
26 |
|
eval("use Cache::FileCache;"); |
27 |
|
if (! $@) { $USE_CACHE = 1; } |
28 |
|
|
29 |
|
my $df; |
30 |
|
|
31 |
|
my $cache = new Cache::FileCache() if ($USE_CACHE); |
32 |
|
|
33 |
sub parse_df { |
sub parse_df { |
34 |
my $ssh = shift @_; |
my $ssh = shift @_; |
35 |
open(DF,"$ssh df -k |") || die "$ssh df: $!"; |
if ($USE_CACHE) { |
36 |
|
print STDERR " [using cache] "; |
37 |
|
$df = $cache->get( $ssh ); |
38 |
|
return if (defined $df); |
39 |
|
print STDERR " [cache miss] "; |
40 |
|
} |
41 |
|
open(DF,"$ssh df -klP |") || die "$ssh df: $!"; |
42 |
while(<DF>) { |
while(<DF>) { |
43 |
chomp; |
chomp; |
44 |
my ($node,$total,$used,$aval,$use_pcnt,$mount) = split(/\s+/,$_,6); |
my ($node,$total,$used,$aval,$use_pcnt,$mount) = split(/\s+/,$_,6); |
45 |
if ($use_pcnt && $use_pcnt =~ s/(\d+)%/$1/) { |
if ($use_pcnt && $use_pcnt =~ s/(\d+)%/$1/) { |
46 |
# print STDERR "$_\n"; |
# print STDERR "$_\n"; |
47 |
# $df{$mount}=$use_pcnt; |
# $df->{$mount}=$use_pcnt; |
48 |
$df{$mount}=$used * 100 / $total if ($total != 0); |
$df->{$mount}=$used * 100 / $total if ($total != 0); |
49 |
# print $df{$mount}," == $use_pcnt\n"; |
# print $df->{$mount}," == $use_pcnt\n"; |
50 |
} |
} |
51 |
} |
} |
52 |
close(DF); |
close(DF); |
53 |
|
$cache->set( $ssh, $df, "1 min" ) if ($USE_CACHE); |
54 |
} |
} |
55 |
|
|
56 |
parse_df($ssh); |
parse_df($ssh); |
64 |
EOF |
EOF |
65 |
my @targets; |
my @targets; |
66 |
|
|
67 |
foreach my $mnt (keys %df) { |
foreach my $mnt (keys %{$df}) { |
68 |
my $target = $mnt; |
my $target = $mnt; |
69 |
if ($mnt eq "/") { |
if ($mnt eq "/") { |
70 |
$target = "root"; |
$target = "root"; |
91 |
|
|
92 |
# dump free % |
# dump free % |
93 |
# |
# |
94 |
print $df{$mount} || "unknown"; |
print $df->{$mount} || "unknown"; |
95 |
print "\n"; |
print "\n"; |