File Coverage

blib/lib/Schedule/Load/Reporter/Filesys.pm
Criterion Covered Total %
statement 36 37 97.3
branch 4 6 66.6
condition n/a
subroutine 10 10 100.0
pod 3 3 100.0
total 53 56 94.6


line stmt bran cond sub pod time code
1             # See copyright, etc in below POD section.
2             ######################################################################
3              
4             package Schedule::Load::Reporter::Filesys;
5 1     1   50254 use Schedule::Load qw (:_utils);
  1         3  
  1         143  
6 1     1   5 use Time::HiRes qw (gettimeofday);
  1         2  
  1         4  
7 1     1   1009 use Filesys::DfPortable qw();
  1         1238  
  1         27  
8 1     1   6 use IO::File;
  1         1  
  1         162  
9 1     1   5 use strict;
  1         3  
  1         23  
10 1     1   3 use Carp;
  1         2  
  1         47  
11 1     1   5 use Sys::Hostname;
  1         2  
  1         276  
12              
13             our $Debug;
14              
15             ######################################################################
16             #### Configuration Section
17              
18             ######################################################################
19             #### Methods
20              
21             sub new {
22 1     1 1 537 my $class = shift;
23 1         9 my $self = {_stats => {},
24             filesystems => ['/','/local','/'.hostname],
25             enabled => 1,
26             @_};
27              
28 1         26 return bless $self, $class;
29             }
30              
31 2     2 1 21 sub stats { return $_[0]->{_stats}; }
32              
33             sub poll {
34 2     2 1 1000339 my $self = shift;
35 2 50       15 return if !$self->{enabled};
36              
37             # In the future we may want to track trends, so could see warnings if filling fast!
38 2         4 foreach my $fs (@{$self->{filesystems}}) {
  2         9  
39 6         25 my $df = Filesys::DfPortable::dfportable($fs,1);
40 6 100       347 next if !$df;
41 2         3 my $fsname;
42 2 50       9 if ($fs eq '/') {
43 2         5 $fsname = 'root';
44             } else {
45 0         0 ($fsname = $fs) =~ s/[^a-zA-Z0-9]+//g;
46             }
47 2         11 $self->{_stats}{"fs_${fsname}_size"} = $df->{blocks}; # Total space in bytes
48 2         15 $self->{_stats}{"fs_${fsname}_pct"} = $df->{per}; # Percent full
49             # free/avail are approximately calculatable using the above
50             }
51             }
52              
53             ######################################################################
54             #### Package return
55             1;
56             __END__