parent
e409620384
commit
d7f456d2ea
3 changed files with 78 additions and 0 deletions
@ -0,0 +1,13 @@ |
|||||||
|
# Discover ZFS zpools |
||||||
|
# $1 not used for now |
||||||
|
UserParameter=vfs.zfs.discovery[*],/var/lib/zabbix/bin/disco_zfs |
||||||
|
|
||||||
|
# Type: Agent or Agent (active) |
||||||
|
# Key: vfs.zfs.zpool[pool,item] where pool is the name of the zpool to monitor |
||||||
|
# item can be one of size, alloc, frag, cap, dedup, health |
||||||
|
UserParameter=vfs.zfs.zpool[*],/var/lib/zabbix/bin/check_zfs --zpool=$1 --what=$2 |
||||||
|
|
||||||
|
# Type: Agent or Agent (active) |
||||||
|
# You can also get all the info about a zpool at once, in JSON |
||||||
|
UserParameter=vfs.zfs.zpool.all[*],/var/lib/zabbix/bin/check_zfs --zpool=$1 |
||||||
|
|
@ -0,0 +1,47 @@ |
|||||||
|
#!/usr/bin/perl -w |
||||||
|
|
||||||
|
use strict; |
||||||
|
use warnings; |
||||||
|
use JSON; |
||||||
|
use File::Which; |
||||||
|
use Getopt::Long; |
||||||
|
|
||||||
|
my $json = {}; |
||||||
|
my $pool = undef; |
||||||
|
my $what = undef; |
||||||
|
|
||||||
|
GetOptions( |
||||||
|
"zpool|pool=s" => \$pool, |
||||||
|
"what=s" => \$what |
||||||
|
); |
||||||
|
|
||||||
|
my $zpool = which('zpool'); |
||||||
|
|
||||||
|
if ($what and !$pool){ |
||||||
|
print <<_EOF; |
||||||
|
Usage: |
||||||
|
$0 [--zpool=<name>] [--what=<item>] |
||||||
|
|
||||||
|
<name> is an optional zpool name. If specified, will only output info for this zpool. |
||||||
|
<item> is one of size, alloc, frag, cap, dedup, health and if specified, will only output the corresponding value |
||||||
|
If --what is specified then --zpool is mandatory. |
||||||
|
The default (with no option) is to output all the info of all the zpool in a JSON format |
||||||
|
_EOF |
||||||
|
exit 1; |
||||||
|
} |
||||||
|
|
||||||
|
if ($zpool){ |
||||||
|
my $cmd = "$zpool list -H" . ( ($pool) ? " $pool" : ""); |
||||||
|
foreach (qx($cmd)){ |
||||||
|
#NAME SIZE ALLOC FREE EXPANDSZ FRAG CAP DEDUP HEALTH ALTROOT |
||||||
|
#rpool 464G 7.49G 457G - 2% 1% 1.00x ONLINE - |
||||||
|
if (m/^(?<pool>\w+)\s+(?<size>\d+(\.\d+)?)[MGT]\s+(?<alloc>\d+(\.\d+)?)[MGT]\s+.+\s+(?<frag>\d+(\.\d+)?)%\s+(?<cap>\d+(\.\d+)?)%\s+(?<dedup>\d+(\.\d+)?)x\s+(?<health>\w+)/){ |
||||||
|
$json->{$+{pool}}->{$_} = $+{$_} foreach (grep { $_ ne 'pool' } keys %+); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
if ($what){ |
||||||
|
print ((defined $json->{$pool}->{$what}) ? $json->{$pool}->{$what} : 'ZBX_UNSUPORTED'); |
||||||
|
} else{ |
||||||
|
print to_json($json); |
||||||
|
} |
@ -0,0 +1,18 @@ |
|||||||
|
#!/usr/bin/perl -w |
||||||
|
|
||||||
|
use strict; |
||||||
|
use warnings; |
||||||
|
use JSON; |
||||||
|
use File::Which; |
||||||
|
|
||||||
|
my $json; |
||||||
|
@{$json->{data}} = (); |
||||||
|
my $zpool = which('zpool'); |
||||||
|
|
||||||
|
if ($zpool){ |
||||||
|
foreach (qx($zpool list -H -o name)){ |
||||||
|
chomp; |
||||||
|
push @{$json->{data}}, { ZPOOL => $_ }; |
||||||
|
} |
||||||
|
} |
||||||
|
print to_json($json); |
Loading…
Reference in new issue