From ba0a868fd4532430f9328250b8b36909b8da1f68 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Wed, 11 Dec 2019 19:09:50 +0100 Subject: [PATCH] Wait for BackupPC_link to run before we take new sizes in our stat So it won't send wrong comp_ratio of size values --- zabbix_scripts/check_backuppc_sudo | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/zabbix_scripts/check_backuppc_sudo b/zabbix_scripts/check_backuppc_sudo index d84195a..cb9a046 100644 --- a/zabbix_scripts/check_backuppc_sudo +++ b/zabbix_scripts/check_backuppc_sudo @@ -64,7 +64,7 @@ if ( $host ) { # Push all the sizes in our data set to compute avg sizes # Exclude backup N°0 as it'll always have much more new data than normal backups # Also exclude if size is not defined. This can happen in BackupPC v3 when - # the link process is waiting for the nightly to finish + # the BackupPC_link process is waiting for the nightly to finish $sizes->add_data($backup->{sizeNew}) unless ( $backup->{num} == 0 || !$backup->{sizeNew} ); $json->{bkp}++; } @@ -73,13 +73,8 @@ if ( $host ) { my $i = ( $bpc_info[-1]->{type} =~ m/^full|incr$/ ) ? -1 : -2; $json->{errors} = $bpc_info[$i]->{xferErrs}; - $json->{new_size} = $bpc_info[$i]->{sizeNew}; $json->{duration} = $bpc_info[$i]->{endTime} - $bpc_info[$i]->{startTime}; $json->{type} = $bpc_info[$i]->{type}; - $json->{comp_ratio} = ( $bpc_info[$i]->{sizeNew} > 0 ) ? - sprintf( "%.2f", 100 - ( $bpc_info[$i]->{sizeNewComp} * 100 / $bpc_info[$i]->{sizeNew} ) ) - : - 0; $json->{new_size_avg} = int $sizes->mean; $json->{new_size_median} = int $sizes->median; @@ -90,6 +85,15 @@ if ( $host ) { $json->{total_size} = $sizes->sum + $json->{full_size} - 2 * $new_size_of_last_full; $json->{age} = time - $bpc_info[$i]->{startTime}; + # For newSize, we need to wait for BackupPC_link to run, which can be delayed + # if a nightly process is running. In this case, use the stats from the previous backup + $i = ( $backup->{sizeNew} ) ? -1 : -2; + $json->{new_size} = $bpc_info[$i]->{sizeNew}; + $json->{comp_ratio} = ( $bpc_info[$i]->{sizeNew} > 0 ) ? + sprintf( "%.2f", 100 - ( $bpc_info[$i]->{sizeNewComp} * 100 / $bpc_info[$i]->{sizeNew} ) ) + : + 0; + $json->{max_errors} = $conf->{MaxXferError} || 0; } } elsif ( $entity ) {