From 21fcd4949e7ce10906e5c8a9b91bbd9151013afe Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Fri, 11 Oct 2019 11:41:05 +0200 Subject: [PATCH] Enhance ZFS monitoring scripts to retrieve ARC stats --- zabbix_conf/zfs.conf | 4 ++++ zabbix_scripts/check_zfs | 14 +++++++++++++- zabbix_scripts/disco_zfs | 8 ++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/zabbix_conf/zfs.conf b/zabbix_conf/zfs.conf index 6e7074a..6f69d6e 100644 --- a/zabbix_conf/zfs.conf +++ b/zabbix_conf/zfs.conf @@ -13,3 +13,7 @@ UserParameter=vfs.zfs.dataset.info[*],/var/lib/zabbix/bin/check_zfs --dataset=$1 # Type: Agent or Agent (active) # Sanoïd snapshot monitoring UserParameter=vfs.zfs.sanoid.check[*],/var/lib/zabbix/bin/check_zfs --sanoid=$1 + +# Type: Agent or Agent (active) +# ARC stats +UserParameter=vfs.zfs.stats.all[*],/var/lib/zabbix/bin/check_zfs --stats=$1 diff --git a/zabbix_scripts/check_zfs b/zabbix_scripts/check_zfs index d333ff8..9c47901 100644 --- a/zabbix_scripts/check_zfs +++ b/zabbix_scripts/check_zfs @@ -10,12 +10,14 @@ my $json = {}; my $pool = undef; my $dataset = undef; my $sanoidmon = undef; +my $stats = undef; my $pretty = 0; GetOptions( "zpool|pool=s" => \$pool, "dataset=s" => \$dataset, "sanoid=s" => \$sanoidmon, + "stats=s" => \$stats, "pretty" => \$pretty ); @@ -34,7 +36,7 @@ if (defined $sanoidmon and not grep { $_ eq $sanoidmon } qw(snapshot capacity he die 'ZBX_NOTSUPPOTED'; } -if (not $pool and not $dataset and not $sanoidmon){ +if (not $pool and not $dataset and not $sanoidmon and not $stats){ print <<_EOF; Usage: $0 [--zpool=|--dataset=|--sanoid=] @@ -74,6 +76,16 @@ if ($pool){ } elsif ($sanoidmon){ print qx($sanoid --monitor-$sanoidmon); exit $?; +} elsif ($stats){ + if (not -e '/proc/spl/kstat/zfs/' . $stats){ + print 'ZBX_NOTSUPPORTED'; + exit 0; + } + open STATS, '){ + next unless (m/^(\w+)\s+4\s+(\d+)$/); + $json->{$1} = $2; + } } print to_json($json, { pretty => $pretty }) . "\n"; diff --git a/zabbix_scripts/disco_zfs b/zabbix_scripts/disco_zfs index 231a711..f5bb56d 100644 --- a/zabbix_scripts/disco_zfs +++ b/zabbix_scripts/disco_zfs @@ -22,6 +22,7 @@ my $fs = 0; my $zvol = 0; my $snap = 0; my $sanoidmon = 0; +my $arcstats = 0; my $pretty = 0; GetOptions( @@ -30,13 +31,14 @@ GetOptions( "zvols|volumes" => \$zvol, "snapshots" => \$snap, "sanoid" => \$sanoidmon, + "arcstats" => \$arcstats, "pretty" => \$pretty ); -if ($fs or $zvol or $snap or $sanoidmon){ +if ($fs or $zvol or $snap or $sanoidmon or $arcstats){ $pools = 0; } -if ($pools + $fs + $zvol + $snap + $sanoidmon != 1){ +if ($pools + $fs + $zvol + $snap + $sanoidmon + $arcstats != 1){ die "One and only one type of discovery should be provided\n"; } if ($sanoidmon and not $sanoid){ @@ -69,5 +71,7 @@ if ($pools){ } } elsif ($sanoidmon){ push @{$json->{data}}, { '{#ZFS_SANOID}' => $_ } foreach (qw(snapshot capacity health)); +} elsif ($arcstats){ + push @{$json->{data}}, { '{#ZFS_STATS}' => 'arcstats' }; } print to_json($json, { pretty => $pretty });