Subversion Repositories camp_sysinfo_client_3

Rev

Rev 69 | Rev 244 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

#!/usr/bin/env perl
use warnings;
use strict;  

# Description: ZFS Disk usage

our $VERSION = '1.0';

# ZFS disks module for sysinfo client
# Author: R. W. Rodolico
# Date:  2017-11-24

# gets information on ZFS partitions. Returns them as a hash


BEGIN {
   push @INC, shift;
}

use library;

# the commands this script will use
my %commands = ( 
                  'zpool' => ''
               );
               
# check the commands for validity
foreach my $command ( keys %commands ) {
   $commands{$command} = &validCommandOnSystem( $command );
}

exit 1 unless $commands{ 'zpool' };

my $temp;
my $device;
my @temp;
my $CATEGORY = 'diskinfo';


# process zfs
if ( $commands{'zpool'} ) {
   @temp = qx ( $commands{zpool} list -pH );
#   print join( "\n", @temp ) . "\n";
   foreach $device ( @temp ) {
      chomp $device;
      my ( $name, $size, $allocated, $free, $expandsz, $frag, $cap, $dedup, $health, $altroot ) = split( "\t", $device );
      $size /= 1024;
      $allocated /= 1024;
      $allocated = int( $allocated );
      print "$CATEGORY\t$name\tfstype\tzfs\n"; # next is fs type
      print "$CATEGORY\t$name\tsize\t$size\n"; # total partition size, in k
      print "$CATEGORY\t$name\tused\t$allocated\n"; # disk usage, in k
      print &zfsComponents( $name );
   } # foreach
}

sub zfsComponents {
   my $zpoolName = shift;
   my @lines = qx( $commands{zpool} list -pHv $zpoolName );
   my @result;
   shift @lines; # we already have the first line of info
   my @temp = split( "\t", $lines[0] );
   push @result, "$CATEGORY\t$zpoolName\tlevel\t$temp[1]";
   shift @lines;
   my @out;
   while ( $temp = shift @lines ) {
      @temp = split( "\t", $temp );
      push @out, $temp[1] if defined $temp[1];
   }
   push @result, "$CATEGORY\t$zpoolName\tcomponents\t" . join( " ", @out );
   return join( "\n", @result ) . "\n";
}