Skip to content

Instantly share code, notes, and snippets.

@jgeurts
Created August 16, 2012 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jgeurts/3372865 to your computer and use it in GitHub Desktop.
Save jgeurts/3372865 to your computer and use it in GitHub Desktop.
Missing statsd dashboard additions to Graphite
# Add to /opt/graphite/webapp/graphite/render/functions.py (Around the "def movingAverage(" line):
def historicalAverage(requestContext, seriesLists, points=7, offset=86400, highPassCount=1, lowPassCount=1):
historicalLists = []
for series in seriesLists:
hlist = []
for i in range(1,points+1):
tShift = str(offset * i) + "s"
shiftedSeries = timeShift(requestContext, [series], tShift)
hlist.append(shiftedSeries[0])
(hlist,start,end,step) = normalize([hlist])
values = (filterAvg(row, highPassCount, lowPassCount) for row in izip(*hlist) )
name = "historicalAverage(%s,%d,%d,%d,%d)" % (series.name, points, offset, highPassCount, lowPassCount)
return [TimeSeries(name,start,end,step,values)]
def filterAvg(row, highPassCount, lowPassCount):
vals = sorted(row)
if (highPassCount > 0):
del vals[:highPassCount]
if (lowPassCount > 0):
del vals[-lowPassCount:]
return safeDiv(safeSum(vals), safeLen(vals))
def fillValue(seriesList, placeholder=0):
for series in seriesList:
series.name = "fillValue(%s, %i)" % (series.name, placeholder)
for i,value in enumerate(series):
if value is None and i != 0:
value = placeholder
series[i] = value
return seriesList
# Search for "# Special functions" and add the following lines around the "'keepLastValue' : keepLastValue," line:
'historicalAverage' : historicalAverage,
'filterAvg' : filterAvg,
'fillValue' : fillValue,
# Restart apache: sudo /etc/init.d/apache2 reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment