--- Begin Message ---
package: cricket
version: 0.70-2(potato) and 1.0.2-15(woody)
tags: patch
I noticed in the cricket docs, that when using mtargets, you can specify an
mtargets-ops of avg(). However, the code does not support this.
Once that was fixed, I was also motivated to fix the case where in mtargets
mode, it only showed the combined values for the current values. It now
displays combined values for current, average, and max.
Patch attached for 0.70-2 and 1.0.2-15 against grapher.cgi. The one for
1.0.2-15 has a fuzz of 2, as I editted the diff for 0.70-2, to make it work
with 1.0.2-15.
On second thought, the way the combined Max numbers are generated may not be
the best, but the patch makes it simple to not do the Max numbers.
-- 0.70-2
--- grapher.cgi Wed Aug 1 16:55:29 2001
+++ /usr/share/cricket/grapher.cgi Wed Aug 1 16:56:35 2001
@@ -765,7 +765,7 @@
my(%dsDescr, @units, @dsnum, @dsnames, $rrdfile, $rrd);
my($order) = 0;
my($printOnce)=0;
- my(%str);
+ my(%strV, %strA, %strM);
my($thisName);
foreach $thisName (@mtargets) {
@@ -846,6 +846,27 @@
}
}
+ my($show) = isTrue(graphParam($gRef, 'show-avg-max', 1));
+ $show = 0 if (! defined($show));
+
+ my($mmax);
+ if ($show) {
+ if (! defined($scale)) {
+ $scale = "1,*";
+ }
+
+ my(@args) = (
+ "/dev/null",
+ "DEF:ds0=$rrdfile:ds$dsnum:AVERAGE",
+ "DEF:ds1=$rrdfile:ds$dsnum:MAX",
+ "CDEF:sds0=ds0,$scale",
+ "CDEF:sds1=ds1,$scale",
+ "PRINT:sds0:AVERAGE:\%f",
+ "PRINT:sds1:MAX:\%f" );
+
+ ($mmax, undef, undef) = RRDs::graph @args;
+ }
+
# save the numbers for later, when we'll add them
if ($isMTargetsOps) {
# we set NaN's to 0 since it's better
@@ -853,7 +874,9 @@
# (This assumes we mostly get a few or no NaN's when we are
# adding a big list of numbers. YMMV.)
$value = 0 if (isnan($value));
- push @{$str{$dsname}}, $value;
+ push @{$strV{$dsname}}, $value;
+ push @{$strA{$dsname}}, $mmax->[0];
+ push @{$strM{$dsname}}, $mmax->[1];
}
if ((defined($value)) && (!$isMTargetsOps)) {
@@ -867,26 +890,6 @@
}
$i++;
- my($show) = isTrue(graphParam($gRef, 'show-avg-max', 1));
- $show = 0 if (! defined($show));
-
- my($mmax);
- if ($show) {
- if (! defined($scale)) {
- $scale = "1,*";
- }
-
- my(@args) = (
- "/dev/null",
- "DEF:ds0=$rrdfile:ds$dsnum:AVERAGE",
- "DEF:ds1=$rrdfile:ds$dsnum:MAX",
- "CDEF:sds0=ds0,$scale",
- "CDEF:sds1=ds1,$scale",
- "PRINT:sds0:AVERAGE:\%f",
- "PRINT:sds1:MAX:\%f" );
-
- ($mmax, undef, undef) = RRDs::graph @args;
- }
print "<td>";
if (defined($color)) {
@@ -950,21 +953,24 @@
usedColor($color);
}
- my(@values) = @{$str{$dsname}};
- $MTargetsOps = convertOps($MTargetsOps, $#values+1);
- my($calc) = join(',', @values, $MTargetsOps);
+ my (@outvalues);
+ foreach ($strV{$dsname}, $strA{$dsname}, $strM{$dsname}) {
+ my(@values) = @{$_};
+ $MTargetsOps = convertOps2($MTargetsOps, $#values+1);
+ my($calc) = join(',', @values, $MTargetsOps);
- # Now do the operation on this to end up with a value
- my($rpn) = new RPN;
- my($res) = $rpn->run($calc);
- my($value);
- if (! defined($res)) {
- Warn("Problem performing operation.");
- $value = "?";
- } else {
- $value = $res;
+ # Now do the operation on this to end up with a value
+ my($rpn) = new RPN;
+ my($res) = $rpn->run($calc);
+ my($value);
+ if (! defined($res)) {
+ Warn("Problem performing operation.");
+ $value = "?";
+ } else {
+ $value = $res;
+ }
+ push @outvalues, $value;
}
-
my($space) = graphParam($gRef, 'space', ' ');
my($unit) = graphParam($gRef, 'y-axis', '');
$unit = graphParam($gRef, 'units', $unit);
@@ -975,8 +981,8 @@
$precision = 0;
}
- $value = prepareValue($value, $dosi, $bytes, $precision,
- $space, $unit);
+ @outvalues = map(prepareValue($_, $dosi, $bytes, $precision,
+ $space, $unit), @outvalues);
# only allow three columns... if more, add a new row.
if ($i > 3) {
@@ -991,7 +997,10 @@
} else {
print $legend;
}
- print ": $value";
+ print " (for the day): <br><b>Cur</b>: $outvalues[0]<br>";
+ print " <b>Avg</b>: $outvalues[1]<br>";
+ print " <b>Max</b>: $outvalues[2]<br>";
+
if (exists($dsDescr{$dsname})) {
print " <a href=\"#$dsname\">[ ? ]</a>";
} else {
@@ -1844,14 +1853,33 @@
sub convertOps {
my($mto, $num) = @_;
- if (lc($mto) eq 'sum()') {
+ if (lc($mto) eq 'sum()' || lc($mto) eq 'sum2()' || lc($mto) eq 'avg()') {
my($i, @plusses);
for ($i = 0; $i < $num-1; $i++) {
push @plusses, '+';
}
+ if (lc($mto) eq 'avg()') {
+ push @plusses, $num, '/';
+ }
return join(',', @plusses);
}
return $mto;
+}
+
+sub convertOps2 {
+ my($mto, $num) = @_;
+ if (lc($mto) eq 'sum2()') {
+ my($i, @plusses);
+ for ($i = 0; $i < $num-1; $i++) {
+ push @plusses, '+';
+ }
+ if (lc($mto) eq 'avg()') {
+ push @plusses, $num, '/';
+ }
+ return join(',', @plusses);
+ } else {
+ return ( convertOps( $mto, $num ) );
+ }
}
sub makeInstMap {
-- 1.0.2-15
--- grapher.cgi Wed Aug 1 16:55:29 2001
+++ /usr/share/cricket/grapher.cgi Wed Aug 1 16:56:35 2001
@@ -766,7 +766,7 @@
my(%dsDescr, @units, @dsnum, @dsnames, $rrdfile, $rrd);
my($order) = 0;
my($printOnce)=0;
- my(%str);
+ my(%strV, %strA, %strM);
my($thisName);
foreach $thisName (@mtargets) {
@@ -847,6 +847,27 @@
}
}
+ my($show) = isTrue(graphParam($gRef, 'show-avg-max', 1));
+ $show = 0 if (! defined($show));
+
+ my($mmax);
+ if ($show) {
+ if (! defined($scale)) {
+ $scale = "1,*";
+ }
+
+ my(@args) = (
+ "/dev/null",
+ "DEF:ds0=$rrdfile:ds$dsnum:AVERAGE",
+ "DEF:ds1=$rrdfile:ds$dsnum:MAX",
+ "CDEF:sds0=ds0,$scale",
+ "CDEF:sds1=ds1,$scale",
+ "PRINT:sds0:AVERAGE:\%f",
+ "PRINT:sds1:MAX:\%f" );
+
+ ($mmax, undef, undef) = RRDs::graph @args;
+ }
+
# save the numbers for later, when we'll add them
if ($isMTargetsOps) {
# we set NaN's to 0 since it's better
@@ -854,7 +875,9 @@
# (This assumes we mostly get a few or no NaN's when we are
# adding a big list of numbers. YMMV.)
$value = 0 if (isnan($value));
- push @{$str{$dsname}}, $value;
+ push @{$strV{$dsname}}, $value;
+ push @{$strA{$dsname}}, $mmax->[0];
+ push @{$strM{$dsname}}, $mmax->[1];
}
if ((defined($value)) && (!$isMTargetsOps)) {
@@ -868,26 +891,6 @@
}
$i++;
- my($show) = isTrue(graphParam($gRef, 'show-avg-max', 1));
- $show = 0 if (! defined($show));
-
- my($mmax);
- if ($show) {
- if (! defined($scale)) {
- $scale = "1,*";
- }
-
- my(@args) = (
- "/dev/null",
- "DEF:ds0=$rrdfile:ds$dsnum:AVERAGE",
- "DEF:ds1=$rrdfile:ds$dsnum:MAX",
- "CDEF:sds0=ds0,$scale",
- "CDEF:sds1=ds1,$scale",
- "PRINT:sds0:AVERAGE:\%lf",
- "PRINT:sds1:MAX:\%lf" );
-
- ($mmax, undef, undef) = RRDs::graph @args;
- }
print "<td>";
if (defined($color)) {
@@ -951,21 +954,24 @@
usedColor($color);
}
- my(@values) = @{$str{$dsname}};
- $MTargetsOps = convertOps($MTargetsOps, $#values+1);
- my($calc) = join(',', @values, $MTargetsOps);
+ my (@outvalues);
+ foreach ($strV{$dsname}, $strA{$dsname}, $strM{$dsname}) {
+ my(@values) = @{$_};
+ $MTargetsOps = convertOps2($MTargetsOps, $#values+1);
+ my($calc) = join(',', @values, $MTargetsOps);
- # Now do the operation on this to end up with a value
- my($rpn) = new RPN;
- my($res) = $rpn->run($calc);
- my($value);
- if (! defined($res)) {
- Warn("Problem performing operation.");
- $value = "?";
- } else {
- $value = $res;
+ # Now do the operation on this to end up with a value
+ my($rpn) = new RPN;
+ my($res) = $rpn->run($calc);
+ my($value);
+ if (! defined($res)) {
+ Warn("Problem performing operation.");
+ $value = "?";
+ } else {
+ $value = $res;
+ }
+ push @outvalues, $value;
}
-
my($space) = graphParam($gRef, 'space', ' ');
my($unit) = graphParam($gRef, 'y-axis', '');
$unit = graphParam($gRef, 'units', $unit);
@@ -976,8 +982,8 @@
$precision = 0;
}
- $value = prepareValue($value, $dosi, $bytes, $precision,
- $space, $unit);
+ @outvalues = map(prepareValue($_, $dosi, $bytes, $precision,
+ $space, $unit), @outvalues);
# only allow three columns... if more, add a new row.
if ($i > 3) {
@@ -992,7 +998,10 @@
} else {
print $legend;
}
- print ": $value";
+ print " (for the day): <br><b>Cur</b>: $outvalues[0]<br>";
+ print " <b>Avg</b>: $outvalues[1]<br>";
+ print " <b>Max</b>: $outvalues[2]<br>";
+
if (exists($dsDescr{$dsname})) {
print " <a href=\"#$dsname\">[ ? ]</a>";
} else {
@@ -1600,6 +1609,21 @@
return $mto;
}
+sub convertOps2 {
+ my($mto, $num) = @_;
+ if (lc($mto) eq 'sum2()') {
+ my($i, @plusses);
+ for ($i = 0; $i < $num-1; $i++) {
+ push @plusses, '+';
+ }
+ if (lc($mto) eq 'avg()') {
+ push @plusses, $num, '/';
+ }
+ return join(',', @plusses);
+ } else {
+ return ( convertOps( $mto, $num ) );
+ }
+}
sub makeInstMap {
my($ins, $inst) = @_;
--- End Message ---