[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#107413: marked as done (sum() for mtargets doesn't do Avg:)



Your message dated Sun, 19 Jan 2025 22:46:42 +0100
with message-id <Z41yws_70IourigE@per.namespace.at>
and subject line Re: Bug#107413: [noreply@sourceforge.net: [ cricket-Patches-450175 ] Support for avg() in mtargets-ops]
has caused the Debian Bug report #107413,
regarding sum() for mtargets doesn't do Avg:
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact owner@bugs.debian.org
immediately.)


-- 
107413: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=107413
Debian Bug Tracking System
Contact owner@bugs.debian.org with problems
--- 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 ---
--- Begin Message ---
Source: cricket
Source-Version: 1.0.4-1

On Thu, Jan 29, 2004 at 02:51:17PM -0800, Matt Zimmerman wrote:
> This is in regard to the patch you submitted for avg() in mtargets-ops.  Can
> you confirm whether 1.0.4 does what you want?

Lets assume it does.

--- End Message ---

Reply to: