Custom functions¶
Just like with storage finders, it is possible to extend Graphite-Render to add custom processing functions.
To give an example, let’s implement a function that reverses the time series, placing old values at the end and recent values at the beginning.
# reverse.py
def reverseSeries(requestContex, seriesList):
reverse = []
for series in seriesList:
reverse.append(TimeSeries(series.name, series.start, series.end,
series.step, series[::-1]))
return reverse
The first argument, requestContext, holds some information about the
request parameters. seriesList is the list of paths found for the request
target.
Once you’ve created your function, declare it in a dictionnary:
ReverseFunctions = {
'reverseSeries': reverseSeries,
}
Add your module to the Graphite-Render Python path and add it to the configuration:
functions:
- graphite_render.functions.SeriesFunctions
- graphite_render.functions.PieFunctions
- reverse.ReverseFunctions