Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revisionBoth sides next revision | ||
monitors:diskstat.pl [2019/02/12 16:28] – [Changelog] wnelis | monitors:diskstat.pl [2019/02/12 17:35] – [diskstat.pl] wnelis | ||
---|---|---|---|
Line 5: | Line 5: | ||
^ Requirements | Perl, Linux | | ^ Requirements | Perl, Linux | | ||
^ Download | None | | ^ Download | None | | ||
- | ^ Last Update | 2012-04-02 | | + | ^ Last Update | 2019-02-12 | |
===== Description ===== | ===== Description ===== | ||
Line 33: | Line 33: | ||
=== Server side === | === Server side === | ||
- | At the Xymon server, the status message from script diskstat.pl is to be handled by script rrd_status.pl. This is accomplished by merging | + | At the Xymon server, |
< | < | ||
- | [rrdstatus] | + | TEST2RRD+=", |
- | ENVFILE / | + | GRAPHS+=",diskstat:: |
- | NEEDS xymond | + | |
- | CMD xymond_channel --channel=status --log=$XYMONSERVERLOGS/ | + | |
</ | </ | ||
- | |||
- | Install the following script, named rrd_status.pl, | ||
- | |||
- | <hidden onHidden=" | ||
- | <code perl> | ||
- | # | ||
- | # | ||
- | # This script handles a list of NCVs, send by a Xymon client, and prepares it to | ||
- | # be stored in an RRA. This script is used in cases in which a fixed-size group | ||
- | # of two or more values should be put together into a single RRA. The algorithm | ||
- | # is specific for each test / client. | ||
- | # | ||
- | # This script is invoked with three parameters: the name of the host, the name | ||
- | # of the test and the name of the file containing the message sent by the | ||
- | # client, containing the NCVs to be handled. | ||
- | # | ||
- | use strict; | ||
- | |||
- | # | ||
- | # Installation constants. | ||
- | # ----------------------- | ||
- | # | ||
- | # %Struct defines the datasets of the various tests. | ||
- | # | ||
- | my %Struct= ( | ||
- | diskstat => [ # Must be sorted! | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | ) ; # of %Struct | ||
- | |||
- | # | ||
- | # Global variables. | ||
- | # ----------------- | ||
- | # | ||
- | my ( $HostName, $TestName, $FileName )= @ARGV ; | ||
- | # | ||
- | my %Var= () ; # Save area measurements | ||
- | my ( $Line, @Line ) ; # List of values of one measurement | ||
- | my $key ; # Loop control variable | ||
- | |||
- | |||
- | # | ||
- | # Main program. | ||
- | # ------------- | ||
- | # | ||
- | |||
- | # | ||
- | # Handle test " | ||
- | # | ||
- | # An attempt has been undertaken to make this code a little bit more general. | ||
- | # The name of an NCV should consist of two names separated by "/" | ||
- | # name becomes (part of) the name of the RRA, the second name becomes the | ||
- | # name of the DS. The DS-ses are written in sorted order. | ||
- | # | ||
- | if ( $TestName eq " | ||
- | open( FH, "<", | ||
- | while ( <FH> ) { | ||
- | chomp ; | ||
- | next unless m/ | ||
- | $Var{$1}{$2}= $3 ; | ||
- | } # of while | ||
- | close( FH ) ; | ||
- | |||
- | print @{$Struct{$TestName}} ; | ||
- | foreach $key ( sort keys %Var ) { | ||
- | @Line= () ; | ||
- | push @Line, $Var{$key}{$_} | ||
- | print " | ||
- | print join( ":", | ||
- | } # of foreach | ||
- | } # of if | ||
- | |||
- | exit 0 ; | ||
- | </ | ||
- | </ | ||
The results are displayed in 4 graphs, named [diskstat], [diskstat0], | The results are displayed in 4 graphs, named [diskstat], [diskstat0], | ||
Line 240: | Line 154: | ||
</ | </ | ||
- | Define the diskstat graphs to be multi-graphs, which should show only one disk per graph, | + | Define the diskstat graphs to be multi-graphs with the following modification in ~xymon/ |
< | < | ||
CGI_SVC_OPTS=" | CGI_SVC_OPTS=" | ||
- | </ | ||
- | and the following modifications in ~xymon/ | ||
- | < | ||
- | TEST2RRD=" | ||
- | GRAPHS=" | ||
</ | </ | ||
Line 263: | 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 285: | 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 324: | 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 342: | 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 361: | Line 270: | ||
$Stats{$Disk}[0]= $Disks{$Disk}{Name} ; | $Stats{$Disk}[0]= $Disks{$Disk}{Name} ; | ||
$Result.= "& | $Result.= "& | ||
- | $Color= " | + | $Color |
} # of foreach | } # of foreach | ||
# | # | ||
Line 372: | 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 383: | 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 390: | 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 409: | 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 . " | ||
Line 447: | Line 365: | ||
===== To do ===== | ===== To do ===== | ||
- | An option is to rework this script to send a trends-message to Xymon in stead of a status message. | + | An option is to rework this script to send a trends-message to Xymon in stead of a status message. |
===== Changelog ===== | ===== Changelog ===== | ||
Line 453: | Line 371: | ||
* **2012-04-02** | * **2012-04-02** | ||
* Initial release | * Initial release | ||
- | * **2019-2-12** | + | * **2019-02-12** |
* Use Devmon format to pass the statistics to xymon / RRD in stead of the NCV format. | * Use Devmon format to pass the statistics to xymon / RRD in stead of the NCV format. | ||