Enhance ZFS monitoring scripts to retrieve ARC stats

This commit is contained in:
Daniel Berteaud 2019-10-11 11:41:05 +02:00
parent 020e7a2818
commit 21fcd4949e
3 changed files with 23 additions and 3 deletions

View File

@ -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

View File

@ -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=<name>|--dataset=<fs zvol or snap>|--sanoid=<snapshot|capacity|health>]
@ -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, '</proc/spl/kstat/zfs/' . $stats;
while (<STATS>){
next unless (m/^(\w+)\s+4\s+(\d+)$/);
$json->{$1} = $2;
}
}
print to_json($json, { pretty => $pretty }) . "\n";

View File

@ -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 });