Fix zpool iostat as /proc/spl/kstat/zfs/pool/io doesn't exist anymore

This commit is contained in:
Daniel Berteaud 2021-12-16 16:46:43 +01:00
parent 72682f9bad
commit cfdd92b9c6
1 changed files with 13 additions and 6 deletions

View File

@ -163,13 +163,20 @@ sub convert_suffix {
sub get_zpool_stats {
my $pool = shift;
my $stats = {};
return $stats unless (-e "/proc/spl/kstat/zfs/$pool/io");
open STAT, "</proc/spl/kstat/zfs/$pool/io";
while (<STAT>){
if (m/^(?<nread>\d+)\s+(?<nwritten>\d+)\s+(?<reads>\d+)\s+(?<writes>\d+)\s+(?<wtime>\d+)\s+(?<wlentime>\d+)\s+(?<wupdate>\d+)\s+(?<rtime>\d+)\s+(?<rlentime>\d+)\s+(?<rupdate>\d+)\s+(?<wcnt>\d+)\s+(?<rcnt>\d+)/){
$stats->{$_} = $+{$_} foreach (keys %+);
open UPTIME, "</proc/uptime";
$_ = <UPTIME>;
chomp;
my ($uptime , undef) = split;
$uptime = int $uptime;
close UPTIME;
foreach my $line (qx($zpool iostat $pool -pH)){
if ($line =~ m/^$pool\s+\d+\s+\d+\s+(?<reads>\d+)\s+(?<writes>\d+)\s+(?<nread>\d+)\s+(?<nwritten>\d+)/){
# zpool iostat shows average IO since boot, so just multiply it
# by the uptime in seconds to get cumulated IO since boot
# Zabbix server will then be able to calculate the delta between two values
$stats->{$_} = $+{$_} * $uptime foreach (keys %+);
last;
}
}
close STAT;
return $stats;
}