← Back to team overview

graphite-dev team mailing list archive

[Merge] lp:~shufgy/graphite/graphite into lp:graphite

 

Simon Huggins has proposed merging lp:~shufgy/graphite/graphite into lp:graphite.

Requested reviews:
  graphite-dev (graphite-dev)

For more details, see:
https://code.launchpad.net/~shufgy/graphite/graphite/+merge/100088

Add new series function to allow people to graph a series based on criteria in another series.
-- 
https://code.launchpad.net/~shufgy/graphite/graphite/+merge/100088
Your team graphite-dev is requested to review the proposed merge of lp:~shufgy/graphite/graphite into lp:graphite.
=== modified file 'webapp/graphite/render/functions.py'
--- webapp/graphite/render/functions.py	2012-03-25 04:54:03 +0000
+++ webapp/graphite/render/functions.py	2012-03-30 09:27:15 +0000
@@ -23,6 +23,7 @@
 from graphite.logger import log
 from graphite.render.datalib import fetchData, TimeSeries, timestamp
 from graphite.render.attime import parseTimeOffset
+from graphite.render.evaluator import evaluateTarget
 
 from graphite.events import models
 
@@ -170,6 +171,27 @@
 
   return [newSeries[name] for name in newNames]
 
+def useSeriesAbove(requestContext, seriesList, min, search, replace):
+  """
+  Given one series, compares it against min and if it is more than min, applies the regular expression against the metric to plot a related metric
+
+  e.g. given ganglia.metric1.reqs,10,'reqs','time' it will plot the response time metric only when the corresponding request/s metric is > 10
+
+  .. code-block:: none
+
+    &target=useSeriesAbove(ganglia.metric1.reqs,10,"reqs","time")
+  """
+  newSeries = []
+
+  for series in seriesList:
+    newname = re.sub(search, replace, series.name)
+    if max(series) > min:
+      n = evaluateTarget(requestContext, newname)
+      if n is not None and len(n) > 0:
+        newSeries.append(n[0])
+
+  return newSeries
+
 def averageSeriesWithWildcards(requestContext, seriesList, *position): #XXX
   """
   Call averageSeries after inserting wildcards at the given position(s).
@@ -2333,6 +2355,7 @@
   'limit' : limit,
   'sortByMaxima' : sortByMaxima,
   'sortByMinima' : sortByMinima,
+  'useSeriesAbove': useSeriesAbove,
 
   # Data Filter functions
   'removeAbovePercentile' : removeAbovePercentile,


Follow ups