Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
sysop-bioinformatics
management_scripts
Commits
9681f4a0
Commit
9681f4a0
authored
May 27, 2010
by
Haarst, Jan van
Browse files
Added filtering for relevant users (time based)
parent
63fb3517
Changes
1
Hide whitespace changes
Inline
Side-by-side
cpu2rrd/rrd2imgs.pl
View file @
9681f4a0
#!/usr/bin/perl -w
use
strict
;
use
Sys::
Hostname
;
use
POSIX
;
my
$time
=
strftime
("
%F %T
",
localtime
()
);
my
$rrdtool
=
"
rrdtool
";
%times
=
(
my
$epoch_seconds
=
time
();
my
%times
=
(
"
daily
"
=>
"
",
"
weekly
"
=>
"
--start '-1wk'
",
"
monthly
"
=>
"
--start '-1mon'
",
"
yearly
"
=>
"
--start '-1yr'
",
);
@colors
=
(
my
@files
=
();
my
$searchtime
;
my
$total
;
my
@colors
=
(
"
#0000FF
",
"
#FF0000
",
"
#00FF00
",
...
...
@@ -48,25 +53,53 @@ while (my $file = readdir(DIR)) {
push
(
@files
,
$file
)
if
((
-
f
$file
)
&&
(
$file
=~
m/\.rrd$/
));
}
#loop trough times
foreach
$key
(
sort
keys
%times
){
$counter
=
1
;
$command
=
"
$rrdtool
graph
"
.
$key
.
"
.png --title '
"
.
$key
.
"
@
"
.
hostname
.
"
' --vertical-label 'Percentage CPU'
"
.
$times
{
$key
};
foreach
my
$key
(
sort
keys
%times
){
$searchtime
=
(
1
*
24
*
60
)
if
(
$key
eq
"
daily
");
$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
.=
"
--alt-y-grid
";
$command
.=
"
--lazy
";
#
$command .= " --lazy";
$command
.=
"
--alt-autoscale
";
$command
.=
"
--interlaced
";
$command
.=
"
--imgformat PNG
";
# loop through files
foreach
$file
(
@files
)
{
$vname
=
$file
;
$vname
=~
s/\.rrd$//
;
$command
.=
"
\\\n
DEF:
"
.
$vname
.
"
=
$file
:cpu:AVERAGE
";
$command
.=
"
\\\n
CDEF:
"
.
$vname
.
"
_=
"
.
$vname
.
"
,UN,0,
$vname
,IF
";
$command
.=
"
\\\n
LINE2:
"
.
$vname
.
"
_
"
.
$colors
[(
$counter
%
$#colors
)]
.
"
:
$file
";
$counter
++
;
foreach
my
$file
(
sort
@files
)
{
my
(
$file_readtime
)
=
(
stat
(
$file
))[
9
];
if
((
$searchtime
>=
$epoch_seconds
-
$file_readtime
)
){
#print $key,"\t",$file,"\t",($epoch_seconds-$file_readtime),"\n";
my
$vname
=
"
X_
"
.
$file
;
my
$file_short
=
$file
;
$vname
=~
s/\.rrd$//
;
$file_short
=~
s/\.rrd$//
;
$command
.=
"
\\\n
DEF:
"
.
$vname
.
"
=
$file
:cpu:AVERAGE
";
$command
.=
"
\\\n
CDEF:
"
.
$vname
.
"
_=
"
.
$vname
.
"
,UN,0,
$vname
,IF
";
$command
.=
"
\\\n
LINE2:
"
.
$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 .= " \\\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: $?
";
#print $command."\n";
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment