Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | Next revisionBoth sides next revision | ||
monitors:diskstat.pl [2019/02/12 16:43] – [To do] wnelis | monitors:diskstat.pl [2019/02/12 17:35] – [diskstat.pl] wnelis | ||
---|---|---|---|
Line 172: | Line 172: | ||
# | # | ||
# This script determines some elementary disk statistics, which are (also) | # This script determines some elementary disk statistics, which are (also) | ||
- | # accessible via CLI command `iostat`. Pseudo file / | + | # accessible via CLI command `iostat`. Pseudo file / |
- | # as primary source of information. | + | # primary source of information. |
# | # | ||
# This script does not have any memory by design. It only reports the values | # This script does not have any memory by design. It only reports the values | ||
- | # found in / | + | # found in / |
- | # a more appropiate unit. In most cases, the difference with the value in | + | # more appropiate unit. In most cases, the difference with the value in the |
- | # the previous pass is of interest. These differences are computed by RRD, | + | # previous pass is of interest. These differences are computed by RRD, prior to |
- | # prior to saving the values. | + | # saving the values. |
# | # | ||
# Written by W.J.M. Nelis, wim.nelis@nlr.nl, | # Written by W.J.M. Nelis, wim.nelis@nlr.nl, | ||
# | # | ||
use strict ; | use strict ; | ||
- | use POSIX qw/ strftime / ; # Format time | + | use Time:: |
- | use lib "/path/to/ | + | use lib "/usr/lib/ |
use diskstat ; # Import list of devices to check | use diskstat ; # Import list of devices to check | ||
Line 194: | Line 194: | ||
# Define the parameters to reach the Xymon server. | # Define the parameters to reach the Xymon server. | ||
# | # | ||
- | my $XyDisp= $ENV{XYMONSERVERHOSTNAME} ; # Name of monitor server | + | my $XyDisp= $ENV{XYMSRV} ; # Name of monitor server |
my $XySend= $ENV{XYMON} ; # Monitor interface program | my $XySend= $ENV{XYMON} ; # Monitor interface program | ||
my $FmtDate= " | my $FmtDate= " | ||
| | ||
+ | my $XyTest= ' | ||
# | # | ||
my $Server= `hostname` ; chomp $Server ; | my $Server= `hostname` ; chomp $Server ; | ||
- | my $Now= strftime( $FmtDate, | + | my $Now= localtime ; # Timestamp of tests |
+ | $Now= $Now-> | ||
# | # | ||
my $InpFil= '/ | my $InpFil= '/ | ||
- | my $Test= ' | ||
# | # | ||
- | # Define the name of each dataset and the unit conversion factor. As most | + | # Define the name of each dataset and the unit conversion factor. As most of the |
- | # of the datasets are defined to be of type DERIVED, the value passed to | + | # datasets are defined to be of type DERIVED, the value passed to RRD must be an |
- | # RRD must be an integer number. Thus the times expressed in [ms] are *not* | + | # integer number. Thus the times expressed in [ms] are *not* converted to [s]. |
- | # converted to [s]. | + | |
# | # | ||
my @DS= ( # Define parameters of the datasets | my @DS= ( # Define parameters of the datasets | ||
- | [ ' | + | [ ' |
- | [ ' | + | [ ' |
- | [ ' | + | [ ' |
- | [ ' | + | [ ' |
- | [ ' | + | [ ' |
- | [ ' | + | [ ' |
- | [ ' | + | [ ' |
- | [ ' | + | [ ' |
- | [ ' | + | [ ' |
- | [ ' | + | [ ' |
- | [ ' | + | [ ' |
- | [ ' | + | [ ' |
) ; | ) ; | ||
Line 233: | Line 233: | ||
# | # | ||
- | # Function ReadStatistics retrieves the disk usage statistics for the | + | # Function ReadStatistics retrieves the disk usage statistics for the disks and |
- | # disks and partitions mentioned in %Disk. | + | # partitions mentioned in %Disk. |
# | # | ||
sub ReadStatistics() { | sub ReadStatistics() { | ||
Line 251: | Line 251: | ||
chomp ; | chomp ; | ||
@Field= split ; # Extract all fields | @Field= split ; # Extract all fields | ||
- | next unless | + | next unless |
if ( @Field != 14 ) { | if ( @Field != 14 ) { | ||
$Result.= "& | $Result.= "& | ||
Line 270: | Line 270: | ||
$Stats{$Disk}[0]= $Disks{$Disk}{Name} ; | $Stats{$Disk}[0]= $Disks{$Disk}{Name} ; | ||
$Result.= "& | $Result.= "& | ||
- | $Color= " | + | $Color |
} # of foreach | } # of foreach | ||
# | # | ||
Line 281: | Line 281: | ||
# | # | ||
- | # Function BuildRrdData | + | # Function BuildRrdData |
- | # patterns, which are recognised by Xymon and ultimately | + | # Xymon to write the values to an RRD. The names of the mountpoints are adapted |
- | # of the mountpoints are adapted to match the Xymon conventions. | + | # to match the Xymon conventions. |
# | # | ||
sub BuildRrdData() { | sub BuildRrdData() { | ||
- | my $Disk ; # Loop control variable | ||
my $Rra ; # Part of name of RRA | my $Rra ; # Part of name of RRA | ||
my $Val ; # Value of one statistic | my $Val ; # Value of one statistic | ||
Line 292: | Line 291: | ||
$Result.= "< | $Result.= "< | ||
- | $Result.= "< | + | $Result.= "< |
- | foreach $Disk ( sort keys %Stats ) { | + | foreach my $ds ( @DS ) { |
+ | next if $$ds[2] eq '' | ||
+ | $Result.= " | ||
+ | } | ||
+ | chop $Result ; # Remove trailing space | ||
+ | $Result.= " | ||
+ | |||
+ | foreach | ||
$ar= $Stats{$Disk} ; # Ref to array | $ar= $Stats{$Disk} ; # Ref to array | ||
$Rra= $$ar[0] ; # Mountpoint of disk | $Rra= $$ar[0] ; # Mountpoint of disk | ||
Line 299: | Line 305: | ||
$Rra=~ s/\//,/g ; # '/' | $Rra=~ s/\//,/g ; # '/' | ||
+ | $Result.= "$Rra " ; | ||
for ( my $i= 1 ; $i<= 11 ; $i++ ) { | for ( my $i= 1 ; $i<= 11 ; $i++ ) { | ||
$Val= $Stats{$Disk}[$i] ; | $Val= $Stats{$Disk}[$i] ; | ||
if ( $Val eq ' | if ( $Val eq ' | ||
- | $Result.= | + | $Result.= |
} else { | } else { | ||
$Val= $Val * $DS[$i][1] ; # Unit conversion | $Val= $Val * $DS[$i][1] ; # Unit conversion | ||
- | $Result.= sprintf( "%s/%s : %d\n", $Rra, $DS[$i][0], $Val ) ; | + | $Result.= sprintf( "%d:", $Val ) ; |
} # of else | } # of else | ||
} # of for | } # of for | ||
+ | chop $Result ; # Remove trailing colon | ||
+ | $Result.= " | ||
} # of foreach | } # of foreach | ||
- | $Result.= ' | + | $Result.= ' |
} # of BuildRrdData | } # of BuildRrdData | ||
Line 318: | Line 327: | ||
# | # | ||
if ( scalar(keys %Disks) ) { | if ( scalar(keys %Disks) ) { | ||
- | ReadStatistics ; # Read disk statistics | + | ReadStatistics() ; # Read disk statistics |
- | BuildRrdData ; # Format measurements for Xymon / RRD | + | BuildRrdData() ; # Format measurements for Xymon / RRD |
} else { | } else { | ||
$Result= "There are no disks defined to monitor\n" | $Result= "There are no disks defined to monitor\n" | ||
} # of else | } # of else | ||
- | $Result= " | + | $Result= " |
"Disk and partition statistics\n\n" | "Disk and partition statistics\n\n" | ||
$Result . " | $Result . " |