"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "bin/BackupPC_rrdUpdate" between
BackupPC-4.3.2.tar.gz and BackupPC-4.4.0.tar.gz

About: BackupPC is a high-performance, enterprise-grade system for backing up Linux and WinXX PCs and laptops to a server’s disk (http/cgi user interface).

BackupPC_rrdUpdate  (BackupPC-4.3.2):BackupPC_rrdUpdate  (BackupPC-4.4.0)
skipping to change at line 32 skipping to change at line 32
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
#======================================================================== #========================================================================
# #
# Version 4.3.2, released 17 Feb 2020. # Version 4.4.0, released 20 Jun 2020.
# #
# See http://backuppc.sourceforge.net. # See http://backuppc.sourceforge.net.
# #
#======================================================================== #========================================================================
use strict; use strict;
no utf8; no utf8;
use lib "__INSTALLDIR__/lib"; use lib "__INSTALLDIR__/lib";
use BackupPC::Lib qw( :BPC_DT_ALL ); use BackupPC::Lib qw( :BPC_DT_ALL );
use File::Path; use File::Path;
use Data::Dumper; use Data::Dumper;
our(%Info); our(%Info);
die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) ); die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );
my $TopDir = $bpc->TopDir(); my $TopDir = $bpc->TopDir();
my $BinDir = $bpc->BinDir(); my $BinDir = $bpc->BinDir();
my $LogDir = $bpc->LogDir(); my $LogDir = $bpc->LogDir();
skipping to change at line 73 skipping to change at line 74
$reply = $1 if ( $reply =~ /(.*)/s ); $reply = $1 if ( $reply =~ /(.*)/s );
eval($reply); eval($reply);
my $Now = time(); my $Now = time();
my $NowRnd0 = 86400 * int($Now / 86400); my $NowRnd0 = 86400 * int($Now / 86400);
my $NowRnd1 = $NowRnd0 + 86400; my $NowRnd1 = $NowRnd0 + 86400;
my $RRDFile = "$LogDir/poolUsage.rrd"; my $RRDFile = "$LogDir/poolUsage.rrd";
if ( -f $RRDFile ) { if ( -f $RRDFile ) {
my $lastUpdate = $bpc->cmdSystemOrEval([$Conf{RrdToolPath}, "last", $RRDFile ]); my $lastUpdate = $bpc->cmdSystemOrEval([$Conf{RrdToolPath}, "last", $RRDFile ]);
if ($?) { if ( $? ) {
print $lastUpdate; print $lastUpdate;
exit(1); exit(1);
} elsif ($lastUpdate == $NowRnd1) { } elsif ( $lastUpdate == $NowRnd1 ) {
print "skipping repeated RRD update for the same day: last update time i s $lastUpdate\n"; print "skipping repeated RRD update for the same day: last update time i s $lastUpdate\n";
exit(0); exit(0);
} }
} }
RRDUpdate(); RRDUpdate();
RRDGraph(4); RRDGraph(4);
RRDGraph(52); RRDGraph(52);
exit(0); exit(0);
# #
# Feeds pool size data values into an RRD $RRDFile # Feeds pool size data values into an RRD $RRDFile
# #
sub RRDUpdate sub RRDUpdate
{ {
# #
# We store data in RRD with predicted time of next update. # We store data in RRD with predicted time of next update.
# #
if ( !-f $RRDFile ) { if ( !-f $RRDFile ) {
if ( ($err = $bpc->cmdSystemOrEval( if ( (
[ $err = $bpc->cmdSystemOrEval([
$Conf{RrdToolPath}, $Conf{RrdToolPath}, "create",
"create", $RRDFile, $RRDFile, "--step",
"--step", "86400", "86400", "--start",
"--start", "$NowRnd0 - 1d", "$NowRnd0 - 1d", "DS:c3kB:GAUGE:172800:0:U",
"DS:c3kB:GAUGE:172800:0:U", "DS:tpkB:GAUGE:172800:0:U", "DS:p3kB:GAUGE:172800:0:U",
"DS:tpkB:GAUGE:172800:0:U", "DS:p4kB:GAUGE:172800:0:U", "DS:c4kB:GAUGE:172800:0:U",
"DS:p3kB:GAUGE:172800:0:U",
"DS:p4kB:GAUGE:172800:0:U",
"DS:c4kB:GAUGE:172800:0:U",
"RRA:LAST:0:1:732" "RRA:LAST:0:1:732"
])) ) { ])
) ) {
print "$err"; print "$err";
} }
} }
# #
# Calculate pool size totals prior to poolng and compression # Calculate pool size totals prior to poolng and compression
# #
my $sizeTot; my $sizeTot;
foreach my $host ( sort( keys( %{ $bpc->HostInfoRead() } ) ) ) { foreach my $host ( sort(keys(%{$bpc->HostInfoRead()})) ) {
my @Backups = $bpc->BackupInfoRead($host); my @Backups = $bpc->BackupInfoRead($host);
for ( my $i = 0 ; $i < @Backups ; $i++ ) { for ( my $i = 0 ; $i < @Backups ; $i++ ) {
$sizeTot += $Backups[$i]{size} || 0; $sizeTot += $Backups[$i]{size} || 0;
} }
} }
$sizeTot = $sizeTot / 1024; $sizeTot = $sizeTot / 1024;
if ( ($err = $bpc->cmdSystemOrEval( if ( (
[ $err = $bpc->cmdSystemOrEval([
$Conf{RrdToolPath}, $Conf{RrdToolPath},
"update", $RRDFile, "update",
$NowRnd1 . ":" $RRDFile,
. $Info{"cpoolKb"} . ":" $NowRnd1 . ":"
. $sizeTot . ":" . $Info{"cpoolKb"} . ":"
. $Info{"poolKb"} . ":" . $sizeTot . ":"
. $Info{"pool4Kb"} . ":" . $Info{"poolKb"} . ":"
. $Info{"cpool4Kb"} . $Info{"pool4Kb"} . ":"
])) ) { . $Info{"cpool4Kb"}
print "$err"; ])
} else { ) ) {
printf("RRD updated:" print "$err";
. " date %s; cpoolKb %f; total %f;" } else {
. " poolKb %f; pool4Kb %f; cpool4Kb %f\n", printf("RRD updated: date %s; cpoolKb %f; total %f; poolKb %f; pool4Kb %
$NowRnd1, $Info{"cpoolKb"}, $sizeTot, f; cpool4Kb %f\n",
$Info{"poolKb"}, $Info{"pool4Kb"}, $Info{"cpool4Kb"}); $NowRnd1, $Info{"cpoolKb"}, $sizeTot, $Info{"poolKb"}, $Info{"pool4K
b"}, $Info{"cpool4Kb"});
} }
} }
# #
# Generate pool size RRDtool graph image # Generate pool size RRDtool graph image
# #
sub RRDGraph sub RRDGraph
{ {
my($weeks) = @_; my($weeks) = @_;
my($fdOut); my($fdOut);
my @poolMax; my @poolMax;
# #
# Get each pool max value from RRD # Get each pool max value from RRD
# #
$bpc->cmdSystemOrEvalLong( $bpc->cmdSystemOrEvalLong(
[ [
$Conf{RrdToolPath}, $Conf{RrdToolPath}, "graphv",
"graphv", "-", "-", "--end=$NowRnd1",
"--end=$NowRnd1", "--start=end-${weeks}w", "--start=end-${weeks}w", "DEF:p3kB=$RRDFile:p3kB:LAST",
"DEF:p3kB=$RRDFile:p3kB:LAST", "DEF:c3kB=$RRDFile:c3kB:LAST", "DEF:p4kB=$RRDFile:p4kB:LAST",
"DEF:c3kB=$RRDFile:c3kB:LAST", "DEF:c4kB=$RRDFile:c4kB:LAST", "PRINT:p3kB:MAX:%lf",
"DEF:p4kB=$RRDFile:p4kB:LAST", "PRINT:c3kB:MAX:%lf", "PRINT:p4kB:MAX:%lf",
"DEF:c4kB=$RRDFile:c4kB:LAST", "PRINT:c4kB:MAX:%lf",
"PRINT:p3kB:MAX:%lf", ],
"PRINT:c3kB:MAX:%lf", sub {
"PRINT:p4kB:MAX:%lf", if ( $_[0] =~ /^print\[([0-3])\] = "([.,0-9]+)"$/ ) {
"PRINT:c4kB:MAX:%lf", $poolMax[$1] = $2 unless ( $2 == 0 );
], sub { }
if ( $_[0] =~ /^print\[([0-3])\] = "([.,0-9]+)"$/ ) { },
$poolMax[$1] = $2 unless ( $2 == 0 ); 1,
} undef
}, 1, undef); );
my $poolSizeGraph = [ my $poolSizeGraph = [
"$Conf{RrdToolPath}", "$Conf{RrdToolPath}", "graph",
"graph", "-", "-", "--end=$NowRnd1",
"--end=$NowRnd1", "--start=end-${weeks}w", "--start=end-${weeks}w", "--title=BackupPC Pool Size (${weeks} wee
"--title=BackupPC Pool Size (${weeks} weeks)", ks)",
"--vertical-label=", "--vertical-label=", "--width=600",
"--width=600", "--height=100", "--rigid", "--alt-autoscale-max", "--height=100", "--rigid",
"--base=1024", "--logarithmic", "--units=si", "--alt-autoscale-max", "--base=1024",
"--color", "BACK#FFFFFF", "--slope-mode", "--imgformat=PNG", "--logarithmic", "--units=si",
"--font", "TITLE:10:", "--font", "AXIS:8:", "--font", "LEGEND:8:", "--fo "--color", "BACK#FFFFFF",
nt", "UNIT:8:", "--slope-mode", "--imgformat=PNG",
"--font-render-mode", "mono", "--font", "TITLE:10:",
"DEF:p3kB=$RRDFile:p3kB:LAST", "--font", "AXIS:8:",
"DEF:c3kB=$RRDFile:c3kB:LAST", "--font", "LEGEND:8:",
"DEF:p4kB=$RRDFile:p4kB:LAST", "--font", "UNIT:8:",
"DEF:c4kB=$RRDFile:c4kB:LAST", "--font-render-mode", "mono",
"DEF:tpkB=$RRDFile:tpkB:LAST", "DEF:p3kB=$RRDFile:p3kB:LAST", "DEF:c3kB=$RRDFile:c3kB:LAST",
"CDEF:p3B=p3kB,1024,*", "DEF:p4kB=$RRDFile:p4kB:LAST", "DEF:c4kB=$RRDFile:c4kB:LAST",
"CDEF:c3B=c3kB,1024,*", "DEF:tpkB=$RRDFile:tpkB:LAST", "CDEF:p3B=p3kB,1024,*",
"CDEF:p4B=p4kB,1024,*", "CDEF:c3B=c3kB,1024,*", "CDEF:p4B=p4kB,1024,*",
"CDEF:c4B=c4kB,1024,*", "CDEF:c4B=c4kB,1024,*", "CDEF:tpB=tpkB,1024,*"
"CDEF:tpB=tpkB,1024,*"
]; ];
# #
# Draw stacked pool graphs (and legend entry) for non empty pools # Draw stacked pool graphs (and legend entry) for non empty pools
# #
push(@$poolSizeGraph, push(@$poolSizeGraph,
'AREA:p3B#FFADA7:Pool V3 in bytes ', 'AREA:p3B#FFADA7:Pool V3 in bytes ',
'GPRINT:p3B:LAST:Current\\:%8.2lf %s', 'GPRINT:p3B:LAST:Current\\:%8.2lf %s',
'GPRINT:p3B:AVERAGE:Average\\:%8.2lf %s', 'GPRINT:p3B:AVERAGE:Average\\:%8.2lf %s',
'GPRINT:p3B:MAX:Maximum\\:%8.2lf %s\n' 'GPRINT:p3B:MAX:Maximum\\:%8.2lf %s\n')
) if $poolMax[0]; if $poolMax[0];
push(@$poolSizeGraph, push(@$poolSizeGraph,
'AREA:c3B#FFDBA7:CPool V3 in bytes :STACK', 'AREA:c3B#FFDBA7:CPool V3 in bytes :STACK',
'GPRINT:c3B:LAST:Current\\:%8.2lf %s', 'GPRINT:c3B:LAST:Current\\:%8.2lf %s',
'GPRINT:c3B:AVERAGE:Average\\:%8.2lf %s', 'GPRINT:c3B:AVERAGE:Average\\:%8.2lf %s',
'GPRINT:c3B:MAX:Maximum\\:%8.2lf %s\n' 'GPRINT:c3B:MAX:Maximum\\:%8.2lf %s\n')
) if $poolMax[1]; if $poolMax[1];
push(@$poolSizeGraph, push(@$poolSizeGraph,
'AREA:p4B#97E7A5:Pool V4 in bytes :STACK', 'AREA:p4B#97E7A5:Pool V4 in bytes :STACK',
'GPRINT:p4B:LAST:Current\\:%8.2lf %s', 'GPRINT:p4B:LAST:Current\\:%8.2lf %s',
'GPRINT:p4B:AVERAGE:Average\\:%8.2lf %s', 'GPRINT:p4B:AVERAGE:Average\\:%8.2lf %s',
'GPRINT:p4B:MAX:Maximum\\:%8.2lf %s\n' 'GPRINT:p4B:MAX:Maximum\\:%8.2lf %s\n')
) if $poolMax[2]; if $poolMax[2];
push(@$poolSizeGraph, push(@$poolSizeGraph,
'AREA:c4B#95B8DB:CPool V4 in bytes :STACK', 'AREA:c4B#95B8DB:CPool V4 in bytes :STACK',
'GPRINT:c4B:LAST:Current\\:%8.2lf %s', 'GPRINT:c4B:LAST:Current\\:%8.2lf %s',
'GPRINT:c4B:AVERAGE:Average\\:%8.2lf %s', 'GPRINT:c4B:AVERAGE:Average\\:%8.2lf %s',
'GPRINT:c4B:MAX:Maximum\\:%8.2lf %s\n' 'GPRINT:c4B:MAX:Maximum\\:%8.2lf %s\n')
) if $poolMax[3]; if $poolMax[3];
# #
# Draw total line graph # Draw total line graph
# #
push(@$poolSizeGraph, push(@$poolSizeGraph,
'LINE1:tpB#FF0000:Prior to pooling and compression', 'LINE1:tpB#FF0000:Prior to pooling and compression',
'GPRINT:tpB:LAST:Current\\:%8.2lf %s', 'GPRINT:tpB:LAST:Current\\:%8.2lf %s',
'GPRINT:tpB:AVERAGE:Average\\:%8.2lf %s', 'GPRINT:tpB:AVERAGE:Average\\:%8.2lf %s',
'GPRINT:tpB:MAX:Maximum\\:%8.2lf %s\\n' 'GPRINT:tpB:MAX:Maximum\\:%8.2lf %s\\n');
);
if ( !open($fdOut, ">", "$LogDir/poolUsage$weeks.png") ) { if ( !open($fdOut, ">", "$LogDir/poolUsage$weeks.png") ) {
print("Can't open/create $LogDir/poolUsage$weeks.png\n"); print("Can't open/create $LogDir/poolUsage$weeks.png\n");
return; return;
} }
$bpc->cmdSystemOrEvalLong($poolSizeGraph, sub { print $fdOut $_[0] }, 1, und ef); $bpc->cmdSystemOrEvalLong($poolSizeGraph, sub { print $fdOut $_[0] }, 1, und ef);
close($fdOut); close($fdOut);
} }
 End of changes. 15 change blocks. 
83 lines changed or deleted 81 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)