| 56 |
rodolico |
1 |
#!/usr/bin/env perl
|
|
|
2 |
use warnings;
|
|
|
3 |
use strict;
|
|
|
4 |
|
|
|
5 |
# Description: ZFS Disk usage
|
|
|
6 |
|
|
|
7 |
our $VERSION = '1.0';
|
|
|
8 |
|
|
|
9 |
# ZFS disks module for sysinfo client
|
|
|
10 |
# Author: R. W. Rodolico
|
|
|
11 |
# Date: 2017-11-24
|
|
|
12 |
|
|
|
13 |
# gets information on ZFS partitions. Returns them as a hash
|
|
|
14 |
|
| 58 |
rodolico |
15 |
|
| 56 |
rodolico |
16 |
BEGIN {
|
|
|
17 |
push @INC, shift;
|
|
|
18 |
}
|
|
|
19 |
|
|
|
20 |
use library;
|
|
|
21 |
|
|
|
22 |
# the commands this script will use
|
|
|
23 |
my %commands = (
|
|
|
24 |
'zpool' => ''
|
|
|
25 |
);
|
|
|
26 |
|
|
|
27 |
# check the commands for validity
|
|
|
28 |
foreach my $command ( keys %commands ) {
|
|
|
29 |
$commands{$command} = &validCommandOnSystem( $command );
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
exit 1 unless $commands{ 'zpool' };
|
|
|
33 |
|
|
|
34 |
my $temp;
|
|
|
35 |
my $device;
|
|
|
36 |
my @temp;
|
|
|
37 |
my $CATEGORY = 'diskinfo';
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
# process zfs
|
|
|
41 |
if ( $commands{'zpool'} ) {
|
|
|
42 |
@temp = qx ( $commands{zpool} list -pH );
|
|
|
43 |
# print join( "\n", @temp ) . "\n";
|
|
|
44 |
foreach $device ( @temp ) {
|
|
|
45 |
chomp $device;
|
|
|
46 |
my ( $name, $size, $allocated, $free, $expandsz, $frag, $cap, $dedup, $health, $altroot ) = split( "\t", $device );
|
|
|
47 |
$size /= 1024;
|
|
|
48 |
$allocated /= 1024;
|
|
|
49 |
$allocated = int( $allocated );
|
|
|
50 |
print "$CATEGORY\t$name\tfstype\tzfs\n"; # next is fs type
|
|
|
51 |
print "$CATEGORY\t$name\tsize\t$size\n"; # total partition size, in k
|
|
|
52 |
print "$CATEGORY\t$name\tused\t$allocated\n"; # disk usage, in k
|
|
|
53 |
print &zfsComponents( $name );
|
|
|
54 |
} # foreach
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
sub zfsComponents {
|
|
|
58 |
my $zpoolName = shift;
|
|
|
59 |
my @lines = qx( $commands{zpool} list -pHv $zpoolName );
|
|
|
60 |
my @result;
|
|
|
61 |
shift @lines; # we already have the first line of info
|
|
|
62 |
my @temp = split( "\t", $lines[0] );
|
|
|
63 |
push @result, "$CATEGORY\t$zpoolName\tlevel\t$temp[1]";
|
|
|
64 |
shift @lines;
|
|
|
65 |
my @out;
|
|
|
66 |
while ( $temp = shift @lines ) {
|
|
|
67 |
@temp = split( "\t", $temp );
|
| 235 |
rodolico |
68 |
push @out, $temp[1] if defined $temp[1];
|
| 56 |
rodolico |
69 |
}
|
|
|
70 |
push @result, "$CATEGORY\t$zpoolName\tcomponents\t" . join( " ", @out );
|
|
|
71 |
return join( "\n", @result ) . "\n";
|
|
|
72 |
}
|
|
|
73 |
|