Fix backups total size computation when there's only one full

tags/zabbix-agent-addons-0.2.98-1
Daniel Berteaud 5 years ago
parent bcf313009b
commit 810f192184
  1. 34
      zabbix_scripts/check_backuppc_sudo

@ -58,23 +58,23 @@ if ( $host ) {
# Skip partial or active backups # Skip partial or active backups
next if ( $backup->{type} !~ m/^full|incr$/ ); next if ( $backup->{type} !~ m/^full|incr$/ );
if ( $backup->{type} eq "full" ) { if ( $backup->{type} eq "full" ) {
$json->{full_size} = $backup->{size}; $json->{full_size} = $backup->{size};
$new_size_of_last_full = $backup->{sizeNew}; $new_size_of_last_full = $backup->{sizeNew} if $backup->{num} > 0;
} }
# Push all the sizes in our data set to compute avg sizes # 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 # 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 # Also exclude if size is not defined. This can happen in BackupPC v3 when
# the BackupPC_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} ); $sizes->add_data($backup->{sizeNew}) if ( $backup->{num} > 0 && $backup->{sizeNew} );
$json->{bkp}++; $json->{bkp}++;
} }
# Ignore the last backup if it's not full or incr (which means it's either partial or active) # Ignore the last backup if it's not full or incr (which means it's either partial or active)
my $i = ( $bpc_info[-1]->{type} =~ m/^full|incr$/ ) ? -1 : -2; my $i = ( $bpc_info[-1]->{type} =~ m/^full|incr$/ ) ? -1 : -2;
$json->{errors} = $bpc_info[$i]->{xferErrs}; $json->{errors} = $bpc_info[$i]->{xferErrs};
$json->{duration} = $bpc_info[$i]->{endTime} - $bpc_info[$i]->{startTime}; $json->{duration} = $bpc_info[$i]->{endTime} - $bpc_info[$i]->{startTime};
$json->{type} = $bpc_info[$i]->{type}; $json->{type} = $bpc_info[$i]->{type};
$json->{new_size_avg} = int $sizes->mean; $json->{new_size_avg} = int $sizes->mean;
$json->{new_size_median} = int $sizes->median; $json->{new_size_median} = int $sizes->median;
@ -90,8 +90,8 @@ if ( $host ) {
# For newSize, we need to wait for BackupPC_link to run, which can be delayed # 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 # if a nightly process is running. In this case, use the stats from the previous backup
$i = ( $backup->{sizeNew} ) ? -1 : -2; $i = ( $backup->{sizeNew} ) ? -1 : -2;
$json->{new_size} = $bpc_info[$i]->{sizeNew}; $json->{new_size} = $bpc_info[$i]->{sizeNew};
$json->{comp_ratio} = ( $bpc_info[$i]->{sizeNew} > 0 ) ? $json->{comp_ratio} = ( $bpc_info[$i]->{sizeNew} > 0 ) ?
sprintf( "%.2f", 100 - ( $bpc_info[$i]->{sizeNewComp} * 100 / $bpc_info[$i]->{sizeNew} ) ) sprintf( "%.2f", 100 - ( $bpc_info[$i]->{sizeNewComp} * 100 / $bpc_info[$i]->{sizeNew} ) )
: :
0; 0;
@ -117,13 +117,13 @@ if ( $host ) {
$json->{hosts}++; $json->{hosts}++;
my $hostConf = $bpc->ConfigDataRead($host); my $hostConf = $bpc->ConfigDataRead($host);
my $conf = { %$mainConf, %$hostConf }; my $conf = { %$mainConf, %$hostConf };
my $freq = ( $conf->{FullPeriod} > $conf->{IncrPeriod} ) ? $conf->{IncrPeriod} : $conf->{FullPeriod}; my $freq = ( $conf->{FullPeriod} > $conf->{IncrPeriod} ) ? $conf->{IncrPeriod} : $conf->{FullPeriod};
my $host_duration = 0; my $host_duration = 0;
my $host_bkp_num = 0; my $host_bkp_num = 0;
my $host_new_size = 0; my $host_new_size = 0;
my $host_full_size = 0; my $host_full_size = 0;
my $host_new_size_of_last_full = 0; my $host_new_size_of_last_full = 0;
foreach my $backup ( $bpc->BackupInfoRead( $host ) ) { foreach my $backup ( $bpc->BackupInfoRead( $host ) ) {
@ -132,9 +132,9 @@ if ( $host ) {
# Save the total size of the last full backup # Save the total size of the last full backup
if ( $backup->{type} eq 'full' ) { if ( $backup->{type} eq 'full' ) {
$host_full_size = $backup->{size}; $host_full_size = $backup->{size};
$host_new_size_of_last_full = $backup->{sizeNew}; $host_new_size_of_last_full = $backup->{sizeNew} if $backup->{num} > 0;
} }
$host_new_size += $backup->{sizeNew} unless ( $backup->{num} == 0 || !$backup->{sizeNew} ); $host_new_size += $backup->{sizeNew} if ( $backup->{num} > 0 && $backup->{sizeNew} );
$entity_total_new += $backup->{sizeNew}; $entity_total_new += $backup->{sizeNew};
$entity_total_comp += $backup->{sizeNewComp}; $entity_total_comp += $backup->{sizeNewComp};

Loading…
Cancel
Save