Enhance ZFS monitoring scripts to retrieve ARC stats
This commit is contained in:
parent
020e7a2818
commit
21fcd4949e
|
@ -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
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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 });
|
||||
|
|
Loading…
Reference in New Issue