/[cricket]/parse_df.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /parse_df.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by dpavlin, Tue Jul 16 14:39:53 2002 UTC revision 1.7 by dpavlin, Thu Jul 18 10:23:24 2002 UTC
# Line 20  use strict; Line 20  use strict;
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);
# Line 49  target --default-- Line 64  target --default--
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";
# Line 76  EOF Line 91  EOF
91    
92  # dump free %  # dump free %
93  #  #
94  print $df{$mount} || "unknown";  print $df->{$mount} || "unknown";
95  print "\n";  print "\n";

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

  ViewVC Help
Powered by ViewVC 1.1.26