From 45df0fd1f9652662e7173105fcf91bdb7525b947 Mon Sep 17 00:00:00 2001 From: Jehan-Guillaume de Rorthais Date: Fri, 21 Nov 2025 16:14:02 +0100 Subject: [PATCH 1/2] Fix to_size buggy unit conversion Fixes issue #399 --- check_pgactivity | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/check_pgactivity b/check_pgactivity index 263c916..368eb78 100755 --- a/check_pgactivity +++ b/check_pgactivity @@ -730,20 +730,14 @@ sub to_size($) { my $val = shift; my @units = qw{B kB MB GB TB PB EB}; my $size = ''; - my $mod = 0; my $i; return $val if $val =~ /^(-?inf)|(NaN$)/i; - $val = int($val); - for ( $i=0; $i < 6 and abs($val) > 1024; $i++ ) { - $mod = $val%1024; - $val = int( $val/1024 ); + $val = $val / 1024; } - $val = "$val.$mod" unless $mod == 0; - return "${val}$units[$i]"; } From 4aa494f60166feef3812d9a79c8498c06b1271ac Mon Sep 17 00:00:00 2001 From: Jehan-Guillaume de Rorthais Date: Sat, 22 Nov 2025 00:18:59 +0100 Subject: [PATCH 2/2] Fix test --- check_pgactivity | 1 - t/01-temp-files.t | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/check_pgactivity b/check_pgactivity index 368eb78..2aebf29 100755 --- a/check_pgactivity +++ b/check_pgactivity @@ -729,7 +729,6 @@ sub dump_status_file { sub to_size($) { my $val = shift; my @units = qw{B kB MB GB TB PB EB}; - my $size = ''; my $i; return $val if $val =~ /^(-?inf)|(NaN$)/i; diff --git a/t/01-temp-files.t b/t/01-temp-files.t index 213be49..ab8fb8e 100644 --- a/t/01-temp-files.t +++ b/t/01-temp-files.t @@ -278,11 +278,11 @@ SKIP: { qr/^Perfdata *: postgres=[1-9][.0-9]*Fpm$/m, qr/^Perfdata *: postgres=[1-9][.0-9]*[kMGTPE]*Bpm$/m, qr/^Perfdata *: postgres=[1-9][0-9]*Files warn=3 crit=4$/m, - qr/^Perfdata *: postgres=[1-9][.0-9]*[kMGTPE]*B warn=48.102MB crit=64.102MB$/m, + qr/^Perfdata *: postgres=[1-9][.0-9]*[kMGTPE]*B warn=48.099609375MB crit=64.099609375MB$/m, qr/^Perfdata *: template1=[1-9][.0-9]*Fpm$/m, qr/^Perfdata *: template1=[1-9][.0-9]*[kMGTPE]*Bpm$/m, qr/^Perfdata *: template1=[1-9][0-9]*Files warn=3 crit=4$/m, - qr/^Perfdata *: template1=[1-9][.0-9]*[kMGTPE]*B warn=48.102MB crit=64.102MB$/m, + qr/^Perfdata *: template1=[1-9][.0-9]*[kMGTPE]*B warn=48.099609375MB crit=64.099609375MB$/m, ], [ qr/^$/ ], 'test file size and count OK ' @@ -375,7 +375,7 @@ SKIP: { $tbsp2_tmp = "$tbsp2/$tbsp2_tmp/pgsql_tmp"; close $dh; - mkdir $tbsp2_tmp || die "Can't openmkdir $tbsp2_tmp: $!";; + mkdir $tbsp2_tmp || die "Can't openmkdir $tbsp2_tmp: $!"; open my $fh, ">", "$tbsp2_tmp/pgsql_tmp1.1" || die "Can't open $tbsp2_tmp/pgsql_tmp1.1: $!"; print $fh "DATA"x1024; close $fh;