Keep the last reported value rather than 'no data' ?

Asked by TTimo

I have a process that reports data fairly irregularly, is it possible to "continue" that data as the lastest reported value? I still want to use the default 1 minute resolution, so I can know *when* the event happened, and what value it was at to monitor long term trends.

Question information

Language:
English Edit question
Status:
Answered
For:
Graphite Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
chrismd (chrismd) said :
#1

Not presently but it would be pretty simple to add a function to do so. I will create a bug to track this and it should be done for the next release.

Revision history for this message
hydralien (hydralien) said :
#2

Hi,

I just faced the same problem and found this ticket. From the attached bug I found out that changes are done and merged, so I tried the trunk code. So the function works, but I think in a rather weird way. Meaning, it does what it's designed for, keeping last value till the new value found, but it makes plot staircased which is I believe not the desired behavior. Would be nice if Graphite could draw a direct line from previous point to the current one, pretending a set of averaged values between those points.

Actually, I've added following diff to the functions to do what I need. Sorry if it looks ugly - this is my first Python code.

=== modified file 'webapp/web/render/functions.py'
--- webapp/web/render/functions.py 2009-08-07 18:05:06 +0000
+++ webapp/web/render/functions.py 2009-08-13 14:25:55 +0000
@@ -22,6 +22,12 @@
   if not safeValues: return None
   return sum(safeValues)

+def safeSub(a,b):
+ if a is None and b is None: return None
+ if a is None: return None
+ if b is None: return a
+ return a - b
+
 def safeDiff(values):
   safeValues = [v for v in values if v is not None]
   if not safeValues: return None
@@ -106,6 +112,27 @@
       series[i] = value
   return seriesList

+def averageLastValue(seriesList):
+ for series in seriesList:
+ series.name = "averageLastValue(%s)" % (series.name)
+ i = 0
+ addition = None
+ series_length = len(series)
+ while i < series_length:
+ value = series[i]
+ if (value is None) and (addition is None) and (i > 0) and (series[i-1] is not None):
+ j = i + 1
+ while (j < series_length) and (addition is None):
+ if series[j] is not None:
+ addition = safeDiv(safeSub(series[j], series[i-1]), j - i)
+ j += 1
+ if (value is None):
+ series[i] = safeSum([series[i-1], addition])
+ else:
+ addition = None
+ i += 1
+ return seriesList
+
 def asPercent(seriesList1,seriesList2orNumber):
   assert len(seriesList1) == 1, "asPercent series arguments must reference *exactly* 1 series"
   series1 = seriesList1[0]
@@ -318,4 +345,5 @@
   'lastAbove' : lastAbove,
   'highestMean' : highestMean,
   'highestLast' : highestLast,
+ 'averageLastValue' : averageLastValue,
 }

Revision history for this message
hydralien (hydralien) said :
#3

Sorry, didn't notice it's solved. I'll repost it to another question.

Can you help with this problem?

Provide an answer of your own, or ask TTimo for more information if necessary.

To post a message you must log in.