From 315c48ab469320b7fc7aad27d2d6fc31c78113a449a5453cffa1ca9bdac9195d Mon Sep 17 00:00:00 2001 From: Ruediger Oertel Date: Wed, 15 Nov 2017 11:53:02 +0000 Subject: [PATCH] - 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