| 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 |
|
| 251 |
rodolico |
15 |
# find our location and use it for searching for libraries
|
| 56 |
rodolico |
16 |
BEGIN {
|
| 251 |
rodolico |
17 |
use FindBin;
|
|
|
18 |
use File::Spec;
|
|
|
19 |
use lib File::Spec->catdir($FindBin::Bin);
|
|
|
20 |
eval( 'use library;' ); die "Could not find library.pm in the code directory\n" if $@;
|
|
|
21 |
eval( 'use Data::Dumper;' );
|
| 56 |
rodolico |
22 |
}
|
|
|
23 |
|
| 251 |
rodolico |
24 |
# check for valid OS.
|
|
|
25 |
exit 1 unless &checkOS( { 'linux' => undef, 'freebsd' => undef } );
|
| 56 |
rodolico |
26 |
|
| 251 |
rodolico |
27 |
# check for required commands, return 2 if they don't exist. Enter an full list of all commands required. If one doesn't exist
|
|
|
28 |
# script returns a 2
|
|
|
29 |
foreach my $command ( 'zpool' ) {
|
|
|
30 |
exit 2 unless &validCommandOnSystem( $command );
|
| 56 |
rodolico |
31 |
}
|
|
|
32 |
|
|
|
33 |
my $temp;
|
|
|
34 |
my $device;
|
|
|
35 |
my @temp;
|
|
|
36 |
my $CATEGORY = 'diskinfo';
|
|
|
37 |
|
|
|
38 |
sub zfsComponents {
|
|
|
39 |
my $zpoolName = shift;
|
| 251 |
rodolico |
40 |
my @lines = qx( zpool list -pHv $zpoolName );
|
| 56 |
rodolico |
41 |
my @result;
|
|
|
42 |
shift @lines; # we already have the first line of info
|
|
|
43 |
my @temp = split( "\t", $lines[0] );
|
|
|
44 |
push @result, "$CATEGORY\t$zpoolName\tlevel\t$temp[1]";
|
|
|
45 |
shift @lines;
|
|
|
46 |
my @out;
|
|
|
47 |
while ( $temp = shift @lines ) {
|
|
|
48 |
@temp = split( "\t", $temp );
|
| 235 |
rodolico |
49 |
push @out, $temp[1] if defined $temp[1];
|
| 56 |
rodolico |
50 |
}
|
|
|
51 |
push @result, "$CATEGORY\t$zpoolName\tcomponents\t" . join( " ", @out );
|
|
|
52 |
return join( "\n", @result ) . "\n";
|
|
|
53 |
}
|
|
|
54 |
|
| 251 |
rodolico |
55 |
# process zfs
|
|
|
56 |
@temp = qx ( zpool list -pH );
|
|
|
57 |
foreach $device ( @temp ) {
|
|
|
58 |
chomp $device;
|
|
|
59 |
my ( $name, $size, $allocated, $free, $expandsz, $frag, $cap, $dedup, $health, $altroot ) = split( "\t", $device );
|
|
|
60 |
$size /= 1024;
|
|
|
61 |
$allocated /= 1024;
|
|
|
62 |
$allocated = int( $allocated );
|
|
|
63 |
print "$CATEGORY\t$name\tfstype\tzfs\n"; # next is fs type
|
|
|
64 |
print "$CATEGORY\t$name\tsize\t$size\n"; # total partition size, in k
|
|
|
65 |
print "$CATEGORY\t$name\tused\t$allocated\n"; # disk usage, in k
|
|
|
66 |
print &zfsComponents( $name );
|
|
|
67 |
} # foreach
|
|
|
68 |
|
|
|
69 |
|