From 6e8dcaed6718dd78dd3b090d918c50bb33dfa38aaadc4853acecef108297c261 Mon Sep 17 00:00:00 2001 From: Ruediger Oertel Date: Tue, 14 Nov 2017 16:13:21 +0000 Subject: [PATCH 1/3] check_iostat pass warn and crit levels to performance data OBS-URL: https://build.opensuse.org/package/show/server:monitoring/monitoring-plugins-sar-perf?expand=0&rev=10 --- check_iostat | 57 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/check_iostat b/check_iostat index f46678c..8a11f77 100644 --- a/check_iostat +++ b/check_iostat @@ -58,10 +58,10 @@ getopts('d:w:c:W:C:X:Y:hv', \%opts); my $disk = $opts{'d'}; my $warning = $opts{'w'}; my $critical = $opts{'c'}; -my $warning_iowait = $opts{'W'}; -my $critical_iowait = $opts{'C'}; -my $warning_util = $opts{'X'}; -my $critical_util = $opts{'Y'}; +my $warn_iowait = $opts{'W'}; +my $crit_iowait = $opts{'C'}; +my $warn_util = $opts{'X'}; +my $crit_util = $opts{'Y'}; VERSION_MESSAGE() if $opts{'v'}; HELP_MESSAGE() if $opts{'h'}; @@ -92,12 +92,12 @@ if ($warn_tps > $crit_tps || $warn_read > $crit_read || $warn_written > $crit_wr HELP_MESSAGE(); } -if ($warning_iowait && $critical_iowait && $warning_iowait > $critical_iowait) { +if ($warn_iowait && $crit_iowait && $warn_iowait > $crit_iowait) { warn "ERROR: critical iowait level must be higher than warning level\n"; HELP_MESSAGE(); } -if ($warning_util && $critical_util && $warning_util > $critical_util) { +if ($warn_util && $crit_util && $warn_util > $crit_util) { warn "ERROR: critical utilization level must be higher than warning level\n"; HELP_MESSAGE(); } @@ -137,12 +137,12 @@ if ($tps >= $warn_tps || $kbread >= $warn_read || $kbwritten >= $warn_written) { $status = 1; } -if ($warning_iowait && $iowait >= $warning_iowait) { +if ($warn_iowait && $iowait >= $warn_iowait) { $msg = "WARNING"; $status = 1; } -if ($warning_util && $util >= $warning_util) { +if ($warn_util && $util >= $warn_util) { $msg = "WARNING"; $status = 1; } @@ -152,18 +152,53 @@ if ($tps >= $crit_tps || $kbread >= $crit_read || $kbwritten >= $crit_written) { $status = 2; } -if ($critical_iowait && $iowait >= $critical_iowait) { +if ($crit_iowait && $iowait >= $crit_iowait) { $msg = "CRITICAL"; $status = 2; } -if ($critical_util && $iowait >= $critical_util) { +if ($crit_util && $util >= $crit_util) { $msg = "CRITICAL"; $status = 2; } +my $p_tps = $tps; +if ($warn_tps) { + $p_tps .= ";$warn_tps"; + if ($crit_tps) { + $p_tps .= ";$crit_tps"; + } +} +my $p_kbread = $kbread; +if ($warn_read) { + $p_kbread .= ";$warn_read"; + if ($crit_read) { + $p_kbread .= ";$crit_read"; + } +} +my $p_kbwritten = $kbwritten; +if($warn_written) { + $p_kbwritten .= ";$warn_written"; + if ($crit_written) { + $p_kbwritten .= ";$crit_written"; + } +} +my $p_iowait = $iowait; +if ($warn_iowait) { + $p_iowait .= ";$warn_iowait"; + if ($crit_iowait) { + $p_iowait .= ";$crit_iowait"; + } +} +my $p_util = $util; +if ($warn_util) { + $p_util .= ";$warn_util"; + if ($crit_util) { + $p_util .= ";$crit_util"; + } +} # Printing the results: -print "$msg - I/O stats tps=$tps KB_read/s=$kbread KB_written/s=$kbwritten iowait=$iowait util=$util | 'tps'=$tps; 'KB_read/s'=$kbread; 'KB_written/s'=$kbwritten; 'iowait'=$iowait; 'util'=$util\n"; +print "$msg - I/O stats tps=$tps KB_read/s=$kbread KB_written/s=$kbwritten iowait=$iowait util=$util | 'tps'=$p_tps; 'KB_read/s'=$p_kbread; 'KB_written/s'=$p_kbwritten; 'iowait'=$p_iowait; 'util'=$p_util\n"; # Bye! exit $status; From 77bb1e171ad3a60d9f58b8407d042db98aedcb807b3da80c1bedfc10f2cf2998 Mon Sep 17 00:00:00 2001 From: Ruediger Oertel Date: Tue, 14 Nov 2017 16:28:21 +0000 Subject: [PATCH 2/3] - check_iostat: pass warning and critical level to perfdata - use iostat fields r/s and w/s for tps calculation OBS-URL: https://build.opensuse.org/package/show/server:monitoring/monitoring-plugins-sar-perf?expand=0&rev=11 --- check_iostat | 4 ++-- monitoring-plugins-sar-perf.changes | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/check_iostat b/check_iostat index 8a11f77..69b86f0 100644 --- a/check_iostat +++ b/check_iostat @@ -33,7 +33,7 @@ sub VERSION_MESSAGE { sub HELP_MESSAGE { print "\n\tThis plugin shows the I/O usage of the specified disk, using the iostat external program.\n"; print "\tIt prints three statistics: Transactions per second (tps), Kilobytes per second\n"; - print "tread from the disk (KB_read/s) and and written to the disk (KB_written/s)\n\n"; + print "read from the disk (KB_read/s) and and written to the disk (KB_written/s)\n\n"; print "$progname:\n\t-d \t\tDevice to be checked (without the full path, eg. sda)\n"; print "\t\t\t\t(also accepted are device mapper names)\n"; print "\t-c ,,\tSets the CRITICAL level for tps, KB_read/s and KB_written/s, respectively\n"; @@ -121,7 +121,7 @@ while () { $seen_disk++; next if $seen_disk < 2; my (@stats) = split ('\s+', $_); - ($rps,$wps,$kbread,$kbwritten,$util) = @stats[1,2,5,6,13]; + ($rps,$wps,$kbread,$kbwritten,$util) = @stats[3,4,5,6,13]; $tps = $rps + $wps; last; } diff --git a/monitoring-plugins-sar-perf.changes b/monitoring-plugins-sar-perf.changes index 9a76db6..a78ae3d 100644 --- a/monitoring-plugins-sar-perf.changes +++ b/monitoring-plugins-sar-perf.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Tue Nov 14 17:27:19 CET 2017 - ro@suse.de + +- check_iostat: pass warning and critical level to perfdata +- use iostat fields r/s and w/s for tps calculation + ------------------------------------------------------------------- Mon Apr 24 12:33:08 CEST 2017 - ro@suse.de From 315c48ab469320b7fc7aad27d2d6fc31c78113a449a5453cffa1ca9bdac9195d Mon Sep 17 00:00:00 2001 From: Ruediger Oertel Date: Wed, 15 Nov 2017 11:53:02 +0000 Subject: [PATCH 3/3] - check_iostat: get field numbers from iostat dynamically by parsing header line (r/s and w/s fields move between versions) OBS-URL: https://build.opensuse.org/package/show/server:monitoring/monitoring-plugins-sar-perf?expand=0&rev=12 --- check_iostat | 21 ++++++++++++++++++++- monitoring-plugins-sar-perf.changes | 6 ++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/check_iostat b/check_iostat index 69b86f0..9cf0894 100644 --- a/check_iostat +++ b/check_iostat @@ -105,6 +105,11 @@ if ($warn_util && $crit_util && $warn_util > $crit_util) { my ($tps,$rps,$wps,$kbread,$kbwritten,$iowait,$util); my $seen_usage = 0; my $seen_disk = 0; +my $field_rps = 3; +my $field_wps = 4; +my $field_rmbps = 5; +my $field_wmbps = 6; +my $field_util = 13; # Doing the actual check: open (IOSTAT,"-|","$iostat -kx $disk 5 2"); @@ -117,11 +122,25 @@ while () { $iowait = $stats[4]; next; } + if (/^Device:/) { + my @hdrs = split('\s+', $_); + my ($search_rps) = grep { $hdrs[$_] eq "r/s" } 0..$#hdrs; + $field_rps = $search_rps if $search_rps; + my ($search_wps) = grep { $hdrs[$_] eq "w/s" } 0..$#hdrs; + $field_wps = $search_wps if $search_wps; + my ($search_rmbps) = grep { $hdrs[$_] eq "rkB/s" } 0..$#hdrs; + $field_rmbps = $search_rmbps if $search_rmbps; + my ($search_wmbps) = grep { $hdrs[$_] eq "wkB/s" } 0..$#hdrs; + $field_wmbps = $search_wmbps if $search_wmbps; + my ($search_util) = grep { $hdrs[$_] eq "%util" } 0..$#hdrs; + $field_util = $search_util if $search_util; + next; + } if (/^$disk /) { $seen_disk++; next if $seen_disk < 2; my (@stats) = split ('\s+', $_); - ($rps,$wps,$kbread,$kbwritten,$util) = @stats[3,4,5,6,13]; + ($rps,$wps,$kbread,$kbwritten,$util) = @stats[$field_rps,$field_wps,$field_rmbps,$field_wmbps,$field_util]; $tps = $rps + $wps; last; } diff --git a/monitoring-plugins-sar-perf.changes b/monitoring-plugins-sar-perf.changes index a78ae3d..8c3a5a5 100644 --- a/monitoring-plugins-sar-perf.changes +++ b/monitoring-plugins-sar-perf.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Wed Nov 15 12:52:11 CET 2017 - ro@suse.de + +- check_iostat: get field numbers from iostat dynamically + by parsing header line (r/s and w/s fields move between versions) + ------------------------------------------------------------------- Tue Nov 14 17:27:19 CET 2017 - ro@suse.de