monitors:diskstat.pl

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
monitors:diskstat.pl [2019/02/12 16:25] – [Installation] wnelismonitors:diskstat.pl [2019/02/16 17:53] (current) – [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 16: Line 16:
 ===== Installation ===== ===== Installation =====
  
-At the client side, script diskstat.pl and module diskstat.pm need to be installed and one configuration file needs to be modified. At the server side, two scripts need to be installed and four configuration files of Xymon need to be modified.+At the client side, script diskstat.pl and module diskstat.pm need to be installed and one configuration file needs to be modified. At the server side, one script needs to be installed and four configuration files of Xymon need to be modified.
  
 === Client side === === Client side ===
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 the following configuration into file ~xymon/server/etc/tasks.cfg:+At the Xymon server, it must be configured that this test uses the Devmon formatTherefore add the following two lines to ~xymon/server/etc/xymonserver.cfg or write them in a file named ~xymon/server/etc/xymonserver.d/diskstat.cfg:
  
 <code> <code>
-[rrdstatus] +TEST2RRD+=",diskstat=devmon" 
-  ENVFILE /path/to/xymon/server/etc/xymonserver.cfg +GRAPHS+=",diskstat::1,diskstat0::1,diskstat1::1,diskstat2::1"
-  NEEDS xymond +
-  CMD xymond_channel --channel=status --log=$XYMONSERVERLOGS/rrd-status.log xymond_rrd --extra-tests=diskstat --extra-script=/path/to/xymon/server/ext/rrd_status.pl --rrddir=$XYMONVAR/rrd+
 </code> </code>
- 
-Install the following script, named rrd_status.pl, in directory ~xymon/server/ext. However, it could be that there is already a script with a similar purpose for other tests: in that case you should merge it with the script below. 
- 
-<hidden onHidden="Show rrd_status.pl ⇲" onVisible="Hide rrd_status.pl ⇱"> 
-<code perl> 
-#!/usr/bin/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! 
-                "DS:IoQueue:GAUGE:600:0:U\n"  , 
-                "DS:IoTime:DERIVE:600:0:U\n"  , 
-                "DS:IoWTime:DERIVE:600:0:U\n" , 
-                "DS:RdAmount:DERIVE:600:0:U\n", 
-                "DS:RdMerge:DERIVE:600:0:U\n"   , 
-                "DS:RdRequest:DERIVE:600:0:U\n"   , 
-                "DS:RdTime:DERIVE:600:0:U\n"  , 
-                "DS:WrAmount:DERIVE:600:0:U\n", 
-                "DS:WrMerge:DERIVE:600:0:U\n"   , 
-                "DS:WrRequest:DERIVE:600:0:U\n"   , 
-                "DS:WrTime:DERIVE:600:0:U\n"   ] 
-   ) ;  # 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 "diskstat". 
-# 
-# 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 "/". The first 
-# 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 "diskstat" ) { 
-  open( FH, "<", $FileName )    or die ; 
-  while ( <FH> ) { 
-    chomp ; 
-    next                        unless m/^([\w\.\,-]+)\/(\w+)\s+:\s+(U|[\d\.]+)\s*$/ ; 
-    $Var{$1}{$2}= $3 ; 
-  }  # of while 
-  close( FH ) ; 
- 
-  print @{$Struct{$TestName}} ; 
-  foreach $key ( sort keys %Var ) { 
-    @Line= () ; 
-    push @Line, $Var{$key}{$_}  foreach ( sort keys %{$Var{$key}} ) ; 
-    print "$TestName.$key.rrd\n" ; 
-    print join( ":", @Line ) . "\n" ; 
-  }  # of foreach 
-}  # of if 
- 
-exit 0 ; 
-</code> 
-</hidden> 
  
 The results are displayed in 4 graphs, named [diskstat], [diskstat0], [diskstat1] and [diskstat2]. These graphs are multi-graphs and use script genlgt.pl to generate the graph title. The results are displayed in 4 graphs, named [diskstat], [diskstat0], [diskstat1] and [diskstat2]. These graphs are multi-graphs and use script genlgt.pl to generate the graph title.
Line 240: Line 154:
 </code> </code>
  
-Define the diskstat graphs to be multi-graphs, which should show only one disk per graph, with the following modification in ~xymon/server/etc/cgioptions.cfg+Define the diskstat graphs to be multi-graphs with the following modification in ~xymon/server/etc/cgioptions.cfg:
 <code> <code>
 CGI_SVC_OPTS="... --multigraphs=diskstat,diskstat0,diskstat1,diskstat2" CGI_SVC_OPTS="... --multigraphs=diskstat,diskstat0,diskstat1,diskstat2"
-</code> 
-and the following modifications in ~xymon/server/etc/xymonserver.cfg: 
-<code> 
-TEST2RRD="...,diskstat" 
-GRAPHS="...,diskstat::1,diskstat0::1,diskstat1::1,diskstat2::1" 
 </code> </code>
  
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 /proc/diskstats is used +# accessible via CLI command `iostat`. Pseudo file /proc/diskstats is used as 
-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 /proc/diskstat to Xymon, although it does convert some values to +# found in /proc/diskstat to Xymon, although it does convert some values to a 
-more appropiate unit. In most cases, the difference with the value in +# more appropriate 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, 201103 # Written by W.J.M. Nelis, wim.nelis@nlr.nl, 201103
 # #
 use strict ; use strict ;
-use POSIX qw/ strftime / ; # Format time +use Time::Piece ; # Format time 
-use lib "/path/to/xymon/client/ext" ;+use lib "/usr/lib/xymon/client/ext" ;
 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= "%Y.%m.%d %H:%M:%S" ; # Default date format my $FmtDate= "%Y.%m.%d %H:%M:%S" ; # Default date format
    $FmtDate= $ENV{XYMONDATEFORMAT} if defined $ENV{XYMONDATEFORMAT} ;    $FmtDate= $ENV{XYMONDATEFORMAT} if defined $ENV{XYMONDATEFORMAT} ;
 +my $XyTest= 'diskstat' ; # Name of test
 # #
 my $Server= `hostname` ;  chomp $Server ; my $Server= `hostname` ;  chomp $Server ;
-my $Now= strftime( $FmtDate, localtime ; # Timestamp of tests+my $Now= localtime ;                    # Timestamp of tests 
 +   $Now= $Now->strftime( $FmtDate ) ;
 # #
 my $InpFil= '/proc/diskstats' ; # Input file name my $InpFil= '/proc/diskstats' ; # Input file name
-my $Test= 'diskstat' ; # Name of test 
 # #
-# Define the name of each dataset and the unit conversion factor. As most +# Define the name of each data-set, the unit conversion factor and the RRD type
-of the datasets are defined to be of type DERIVED, the value passed to +Note that RRD requires that the values of type 'DERIVE' are integer. If 
-# RRD must be an integer number. Thus the times expressed in [ms] are *not* +however floating point numbers are used, the RRD type must be set to 
-converted to [s].+'DDERIVE'.
 # #
 my @DS= ( # Define parameters of the datasets my @DS= ( # Define parameters of the datasets
-    [ 'Name'     ,   1 ], #  0 - Name of disk / partition +    [ 'Name'     ,     1, ''        ], #  0 - Name of disk / partition 
-    [ 'RdRequest',   1 ], #  1 - Read requests +    [ 'RdRequest',     1, 'DERIVE'  ], #  1 - Read requests 
-    [ 'RdMerge'   1 ], #  2 - Read request merges +    [ 'RdMerge'     1, 'DERIVE'  ], #  2 - Read request merges 
-    [ 'RdAmount' , 512 ], #  3 - Sectors read +    [ 'RdAmount'  512, 'DERIVE'  ], #  3 - Sectors read 
-    [ 'RdTime'   ,   1 ], #  4 - Time spent reading [ms] +    [ 'RdTime'   , 0.001, 'DDERIVE' ], #  4 - Time spent reading [ms] 
-    [ 'WrRequest',   1 ], #  5 - Write requests +    [ 'WrRequest',     1, 'DERIVE'  ], #  5 - Write requests 
-    [ 'WrMerge'   1 ], #  6 - Write request merges +    [ 'WrMerge'     1, 'DERIVE'  ], #  6 - Write request merges 
-    [ 'WrAmount' , 512 ], #  7 - Sectors written +    [ 'WrAmount'  512, 'DERIVE'  ], #  7 - Sectors written 
-    [ 'WrTime'   ,   1 ], #  8 - Time spent writing [ms] +    [ 'WrTime'   , 0.001, 'DDERIVE' ], #  8 - Time spent writing [ms] 
-    [ 'IoQueue'   1 ], #  9 - Length of I/O queue +    [ 'IoQueue'     1, 'GAUGE'   ], #  9 - Length of I/O queue 
-    [ 'IoTime'   ,   1,], # 10 - Time spent for I/O [ms] +    [ 'IoTime'   , 0.001'DDERIVE' ], # 10 - Time spent for I/O [ms] 
-    [ 'IoWTime'   1,] # 11 - Time weighted with (9)+    [ 'IoWTime' 0.001'DDERIVE' ] # 11 - Time weighted with (9)
 ) ; ) ;
  
Line 324: Line 234:
  
 # #
-# 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 252:
       chomp ;       chomp ;
       @Field= split ; # Extract all fields       @Field= split ; # Extract all fields
-      next unless defined $Disks{$Field[2]} ;+      next unless exists $Disks{$Field[2]} ;
       if ( @Field != 14 ) {       if ( @Field != 14 ) {
  $Result.= "&yellow Format of statistics of $Field[2] is wrong\n" ;  $Result.= "&yellow Format of statistics of $Field[2] is wrong\n" ;
Line 361: Line 271:
       $Stats{$Disk}[0]= $Disks{$Disk}{Name} ;       $Stats{$Disk}[0]= $Disks{$Disk}{Name} ;
       $Result.= "&yellow No statistics found for $Disk\n" ;       $Result.= "&yellow No statistics found for $Disk\n" ;
-      $Color= "yellow" ;+      $Color  = "yellow" ;
     }  # of foreach     }  # of foreach
  #  #
Line 372: Line 282:
  
 # #
-# Function BuildRrdData converts the list of values into a list of NCV +# Function BuildRrdData reports the values in Devmon format to Xymon, causing 
-patterns, which are recognised by Xymon and ultimately RRD. The names +# Xymon to write the values to an RRD. The names of the mount-points 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 292:
  
   $Result.= "<!-- linecount=" . scalar(keys %Stats) . " -->\n" ;   $Result.= "<!-- linecount=" . scalar(keys %Stats) . " -->\n" ;
-  $Result.= "<!--\n" ; # Hide measurements in HTML comment +  $Result.= "<!--DEVMON RRD: diskstat 0 0\n" ; 
-  foreach $Disk ( sort keys %Stats ) {+  foreach my $ds ( @DS ) { 
 +    next if $$ds[2] eq ''
 +    $Result.= "DS:$$ds[0]:$$ds[2]:600:0:U " ; 
 +  }  of foreach 
 +  chop $Result ; # Remove trailing space 
 +  $Result.= "\n"
 + 
 +  foreach my $Disk ( sort keys %Stats ) {
     $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 306:
     $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 'U' ) {       if ( $Val eq 'U' ) {
- $Result.= sprintf( "%s/%s : U\n", $Rra, $DS[$i][0] ) ;+ $Result.= 'U:' ;
       } 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 ) ;+ if ( $DS[$i][2] eq 'DDERIVE' ) { 
 +   $Result.= sprintf( "%.3f:", $Val ) ; 
 + } else { 
 +   $Result.= sprintf( "%d:", $Val ) ; 
 + }  # of else
       }  # of else       }  # of else
     }  # of for     }  # of for
 +    chop $Result ; # Remove trailing colon
 +    $Result.= "\n" ;
   }  # of foreach   }  # of foreach
-  $Result.= '-->' ;+  $Result.= '-->' ; # End of Devmon format
 }  # of BuildRrdData }  # of BuildRrdData
  
Line 409: Line 332:
 # #
 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= "\"status $Server.$Test $Color $Now\n" .+$Result= "\"status $Server.$XyTest $Color $Now\n" .
  "Disk and partition statistics\n\n" .  "Disk and partition statistics\n\n" .
  $Result . "\"\n" ;  $Result . "\"\n" ;
Line 447: Line 370:
  
 ===== 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 advantage is that there is no need any more for script rrd_status.pl, a disadvantage might be the lack of a column named 'diskstat'.+An option is to rework this script to send a trends-message to Xymon in stead of a status message. The lack of a column named 'diskstat' might be an advantage for some.
  
 ===== Changelog ===== ===== Changelog =====
Line 453: Line 376:
   * **2012-04-02**   * **2012-04-02**
     * Initial release     * Initial release
 +  * **2019-02-12**
 +    * Use Devmon format to pass the statistics to xymon / RRD in stead of the NCV format.
  
  • monitors/diskstat.pl.1549988759.txt.gz
  • Last modified: 2019/02/12 16:25
  • by wnelis