Merge lp:~shufgy/graphite/graphite into lp:~graphite-dev/graphite/main

Proposed by Simon Huggins
Status: Merged
Approved by: Michael Leinartas
Approved revision: 733
Merge reported by: Michael Leinartas
Merged at revision: not available
Proposed branch: lp:~shufgy/graphite/graphite
Merge into: lp:~graphite-dev/graphite/main
Diff against target: 47 lines (+23/-0)
1 file modified
webapp/graphite/render/functions.py (+23/-0)
To merge this branch: bzr merge lp:~shufgy/graphite/graphite
Reviewer Review Type Date Requested Status
Michael Leinartas Pending
Review via email: mp+100088@code.launchpad.net

Description of the change

Add new series function to allow people to graph a series based on criteria in another series.

To post a comment you must log in.
Revision history for this message
Jeff Blaine (jblaine-kickflop) wrote :

Looks reasonable and harmless to me. It's just a matter of the Real Graphite Devs making a decision I guess.

Revision history for this message
Michael Leinartas (mleinartas) wrote :

Sorry for letting this sit so long without comment.

I've delayed merging this primarily because I'm not sure whether this has broad enough use case. It think providing two separate metrics - one to display, one to test with - *might* make it a bit more broad, but it ruins what I think your use case is (correct me if I'm wrong): to use this as a conditional filter on a wildcard with many matches.

I'm going to think on this a bit more to see if I can come up with another more broad way to do a filter like this. If nothing comes to me, I'll just merge it - as Jeff said, it is harmless.

Anyone else who does think they'd use this, please +1

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'webapp/graphite/render/functions.py'
2--- webapp/graphite/render/functions.py 2012-03-25 04:54:03 +0000
3+++ webapp/graphite/render/functions.py 2012-04-05 13:43:30 +0000
4@@ -23,6 +23,7 @@
5 from graphite.logger import log
6 from graphite.render.datalib import fetchData, TimeSeries, timestamp
7 from graphite.render.attime import parseTimeOffset
8+from graphite.render.evaluator import evaluateTarget
9
10 from graphite.events import models
11
12@@ -170,6 +171,27 @@
13
14 return [newSeries[name] for name in newNames]
15
16+def useSeriesAbove(requestContext, seriesList, min, search, replace):
17+ """
18+ 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
19+
20+ 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
21+
22+ .. code-block:: none
23+
24+ &target=useSeriesAbove(ganglia.metric1.reqs,10,"reqs","time")
25+ """
26+ newSeries = []
27+
28+ for series in seriesList:
29+ newname = re.sub(search, replace, series.name)
30+ if max(series) > min:
31+ n = evaluateTarget(requestContext, newname)
32+ if n is not None and len(n) > 0:
33+ newSeries.append(n[0])
34+
35+ return newSeries
36+
37 def averageSeriesWithWildcards(requestContext, seriesList, *position): #XXX
38 """
39 Call averageSeries after inserting wildcards at the given position(s).
40@@ -2333,6 +2355,7 @@
41 'limit' : limit,
42 'sortByMaxima' : sortByMaxima,
43 'sortByMinima' : sortByMinima,
44+ 'useSeriesAbove': useSeriesAbove,
45
46 # Data Filter functions
47 'removeAbovePercentile' : removeAbovePercentile,