Hi,
I'd like to layer two graph plots (in and out traffic) on the same graph using rrdtool::oo wrapper module
you can enter multiple datapoints in one object but my second set of data may not have the same time keys.
therefore, I decided to separate the entering of data into seperate loops. However when populating the outbound hash, the script crashes.
I think I have to create a separate rrd object and then draw them both on the same graph however if anyone sees a quick fix to the code below that doesn't require that. I'm all ears.
here's my code snippet:
sub nfgraph
{
my $hashref=shift;
#my $hashrefout=shift;
my $title=shift;
my $start = timegm(0, 0, 0, 1, $args{month} - 1, $args{year} - 1900)
+;
my $end;
if( 12 == $args{month} )
{
$end = timegm(0, 0, 0, 1, 0, $args{year} - 1900 + 1) - 1;
}
else
{
$end = timegm(0, 0, 0, 1, $args{month}, $args{year} - 1900) - 1;
}
# create an RRD database
my(undef, $tempfname) = tempfile(
DIR => $tempdir,
SUFFIX => '.rrd',
UNLINK => 1,
);
my $rrd = RRDTool::OO->new( file => $tempfname )
or LOGDIE("can't create RRDTool::OO object");
$rrd->create(
start => $start,
data_source => {
name => $title,
type => 'GAUGE',
},
data_source => {
name => 'out',
type => 'GAUGE',
},
archive => {
rows => 500,
cpoints => 12,
cfunc => 'MAX',
},
archive => {
rows => 500,
cpoints => 12,
cfunc => 'MAX',
},
) or LOGDIE("can't create RRD archive");
#DEBUG("created RRD database $tempfname");
my $totalaccum=0;
open (NFIN,">accum$title.csv");
for my $time( sort keys %$hashref )
{
$totalaccum+=$hashref->{$time};
print NFIN "$time,$totalaccum\n";
$rrd->update( time => $time, value=$totalaccum );
}
close(NFIN);
my $totalaccumout=0;
open (NFOUT,">accumout.csv");
for my $otime(sort keys %$hashrefout)
{
$totalaccumout+=$hashrefout->{$otime};
print NFOUT "$otime,$totalaccumout\n";
$rrd->update( time => $otime, values => {out => $totalaccumout
+} );
}
close(NFOUT);
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.