From ad7c36b6de125dca536707026beb4400940db79d Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Fri, 20 Sep 2019 12:39:51 +0200 Subject: [PATCH] Revert to suffix conversion for ZFS error count zpool status -p is only supported since ZoL 0.8.0, so, to monitor older servers, we need to do this without -p --- zabbix_scripts/check_zfs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/zabbix_scripts/check_zfs b/zabbix_scripts/check_zfs index cac4140..8183af7 100644 --- a/zabbix_scripts/check_zfs +++ b/zabbix_scripts/check_zfs @@ -81,7 +81,7 @@ sub get_zpool_errors { }; my $i = 0; my $index = {}; - foreach my $line (qx($zpool status -p $pool)){ + foreach my $line (qx($zpool status $pool)){ # Output looks like # pool: rpool # state: ONLINE @@ -110,11 +110,11 @@ sub get_zpool_errors { chomp($line); $line =~ s/\s+/ /g; $errors->{$index->{$i-1}} .= $line; - } elsif ($line =~ m/\s+[a-zA-Z0-9_\-]+\s+[A-Z]+\s+(?\d+(\.\d+)?)\s+(?\d+(\.\d+)?)\s+(?\d+(\.\d+)?)/){ + } elsif ($line =~ m/\s+[a-zA-Z0-9_\-]+\s+[A-Z]+\s+(?\d+(\.\d+)?)(?[KMT])?\s+(?\d+(\.\d+)?)(?[KMT])?\s+(?\d+(\.\d+)?)(?[KMT])?/){ # And here, we count the number of read, write and checksum errors - $errors->{read_errors} += $+{'read'}; - $errors->{write_errors} += $+{'write'}; - $errors->{cksum_errors} += $+{'cksum'}; + $errors->{read_errors} += convert_suffix($+{'read'},$+{'read_suffix'}); + $errors->{write_errors} += convert_suffix($+{'write'},$+{'write_suffix'}); + $errors->{cksum_errors} += convert_suffix($+{'write'},$+{'write_suffix'}); } $i++; } @@ -123,6 +123,22 @@ sub get_zpool_errors { return $errors; } +# Error counter can be suffixed. Apply this suffix to get raw error numbers +sub convert_suffix { + my $val = shift; + my $suf = shift; + if (!$suf){ + return $val; + } elsif ($suf eq 'K'){ + $val *= 1000; + } elsif ($suf eq 'M') { + $val *= 1000000; + } elsif ($suf eq 'T') { + $val *= 1000000000; + } + return $val; +} + sub get_zpool_stats { my $pool = shift; my $stats = {};