Subversion Repositories camp_sysinfo_client_3

Rev

Rev 237 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
20 rodolico 1
#!/usr/bin/env perl
2
use warnings;
26 rodolico 3
use strict;  
2 rodolico 4
 
37 rodolico 5
# Description: Disk usage for Unix systems
20 rodolico 6
 
37 rodolico 7
our $VERSION = '1.2';
8
 
20 rodolico 9
# Linux disks module for sysinfo client
10
# Author: R. W. Rodolico
11
# Date:   2016-04-08
12
 
2 rodolico 13
# gets information on disks and partitions. Returns them as a hash
14
# uses standard df -kT and parses the output
15
# skips anything that does not have a device with /dev in it
16
# assumes the structure of the output is:
17
# device fstype size usedSpace availableSpace percentSpace mountPoint
18
# however, the output can sometimes wrap to multi lines, especially if the 
19
# device is long. So, we will replace all newlines with spaces, then 
20
# remove space duplications, then split on spaces and process each item in
21
# turn.
22
# NOTE: this will totally break if you have spaces in your mount point
23
 
24
BEGIN {
25
   push @INC, shift;
26
}
27
 
28
use library;
29
 
30
my $command = &validCommandOnSystem('df');
31
 
32
exit 1 unless $command;
33
 
34
my $CATEGORY = 'diskinfo';
35
 
36
# process physical partitions
37
my $temp = qx/df -kT/; # execute the system command df, returned values in kilobytes, showing file system types
28 rodolico 38
my @temp = split("\n", $temp ); # get array of lines
2 rodolico 39
shift @temp; # get rid of the first line . . . it is nothing but header info
40
$temp = join( ' ', @temp ); # rejoin everything back with spaces
41
$temp =~ s/ +/ /gi; # remove all duplicate spaces
42
@temp = split( ' ', $temp ); # turn it back into an array of space separated values
43
while (@temp) {
44
   my $device = shift @temp; # get the device name
45
   my $output = '';
46
   $output .=  "$CATEGORY\t$device\tfstype\t" . (shift @temp) . "\n"; # next is fs type
47
   $output .=  "$CATEGORY\t$device\tsize\t" . (shift @temp) . "\n"; # total partition size, in k
48
   $output .=  "$CATEGORY\t$device\tused\t" . (shift @temp) . "\n"; # disk usage, in k
49
   shift @temp; # $available, not recorded
50
   shift @temp; # $percent, not recorded
51
   $output .=  "$CATEGORY\t$device\tmount\t" . (shift @temp) . "\n"; # mount point
52
   # now, if it is a /dev device, we add it to the diskInfo hash
53
   print $output if $device =~ m/\/dev/;
54
}