Commit 9681f4a0 authored by Haarst, Jan van's avatar Haarst, Jan van
Browse files

Added filtering for relevant users (time based)

parent 63fb3517
#!/usr/bin/perl -w #!/usr/bin/perl -w
use strict;
use Sys::Hostname; use Sys::Hostname;
use POSIX; use POSIX;
my $time=strftime("%F %T", localtime() ); my $time=strftime("%F %T", localtime() );
my $rrdtool= "rrdtool"; my $rrdtool= "rrdtool";
%times=( my $epoch_seconds=time();
my %times=(
"daily" => " ", "daily" => " ",
"weekly" => "--start '-1wk'", "weekly" => "--start '-1wk'",
"monthly" => "--start '-1mon'", "monthly" => "--start '-1mon'",
"yearly" => "--start '-1yr'", "yearly" => "--start '-1yr'",
); );
@colors=( my @files=();
my $searchtime;
my $total;
my @colors=(
"#0000FF", "#0000FF",
"#FF0000", "#FF0000",
"#00FF00", "#00FF00",
...@@ -48,25 +53,53 @@ while (my $file = readdir(DIR)) { ...@@ -48,25 +53,53 @@ while (my $file = readdir(DIR)) {
push (@files,$file) if ((-f $file) && ($file =~ m/\.rrd$/)); push (@files,$file) if ((-f $file) && ($file =~ m/\.rrd$/));
} }
#loop trough times #loop trough times
foreach $key(sort keys %times){ foreach my $key(sort keys %times){
$counter = 1; $searchtime = (1*24*60) if ($key eq "daily");
$command = "$rrdtool graph ".$key.".png --title '".$key."@".hostname."' --vertical-label 'Percentage CPU' ".$times{$key}; $searchtime = (7*24*60) if ($key eq "weekly");
$searchtime = (30*24*60) if ($key eq "monthly");
$searchtime = (365*24*60) if ($key eq "yearly");
my $counter = 1;
my $SUM_command="CDEF:TOTAL_SUM=";
my $command = "$rrdtool graph ".$key.".png --title '".$key."@".hostname."' --vertical-label 'Percentage CPU' ".$times{$key};
$command .= " --width 500 --height 250"; $command .= " --width 500 --height 250";
$command .= " --alt-y-grid"; $command .= " --alt-y-grid";
$command .= " --lazy"; #$command .= " --lazy";
$command .= " --alt-autoscale"; $command .= " --alt-autoscale";
$command .= " --interlaced"; $command .= " --interlaced";
$command .= " --imgformat PNG"; $command .= " --imgformat PNG";
# loop through files # loop through files
foreach $file (@files) { foreach my $file (sort @files) {
$vname = $file; my ($file_readtime) = (stat ($file))[9];
$vname =~ s/\.rrd$//; if (($searchtime >= $epoch_seconds-$file_readtime) ){
$command .= " \\\nDEF:".$vname."=$file:cpu:AVERAGE"; #print $key,"\t",$file,"\t",($epoch_seconds-$file_readtime),"\n";
$command .= " \\\nCDEF:".$vname."_=".$vname.",UN,0,$vname,IF";
$command .= " \\\nLINE2:".$vname."_".$colors[($counter % $#colors)].":$file"; my $vname = "X_".$file;
$counter++; my $file_short = $file;
$vname =~ s/\.rrd$//;
$file_short =~ s/\.rrd$//;
$command .= " \\\nDEF:".$vname."=$file:cpu:AVERAGE";
$command .= " \\\nCDEF:".$vname."_=".$vname.",UN,0,$vname,IF";
$command .= " \\\nLINE2:".$vname."_".$colors[($counter % $#colors)].":$file_short";
$SUM_command.=$vname."_,";
#if ($counter == 1){
# $total = "CDEF:total_cpu=".$vname;
#}else{
# $total .= ",".$vname.",+";
#};
$counter++;
}
} }
#$command .= " \\\nCOMMENT:\\\'".$time."\\\'"; #$command .= " \\\nCOMMENT:\\\'".$time."\\\'";
#$command .= " \\\n".$total;
#$command .= " \\\nAREA:total_cpu#339999:Total";
#$command .= " \\\nGPRINT:total_cpu:Total\\ CPU\\ is\\ \%9.2lfA";
chop($SUM_command);
my @list=split(',', $SUM_command);
$SUM_command .= ',+' x scalar(@list);
$SUM_command = " \\\n".$SUM_command;
#print "$SUM_command\n";
#$command .= $SUM_command;
system($command) == 0 or die "system $command failed: $?"; system($command) == 0 or die "system $command failed: $?";
#print $command."\n"; #print $command."\n";
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment