graphite-dev team mailing list archive
-
graphite-dev team
-
Mailing list archive
-
Message #02337
[Merge] lp:~janosch-woschitz/graphite/graphite into lp:graphite
Janosch Woschitz has proposed merging lp:~janosch-woschitz/graphite/graphite into lp:graphite.
Requested reviews:
graphite-dev (graphite-dev)
For more details, see:
https://code.launchpad.net/~janosch-woschitz/graphite/graphite/+merge/99718
I added an optional parameter to the hitcount function which aligns the series results to the interval (similar to alignToFrom in smartSummarize function).
This allows the user to use a relative time range in the dashboard but the data points of the series will be plotted on the expected interval steps (e.g. if the interval is 1 day, it will align each data point to start of the day and also calculate the value for the whole day).
Please feel free to ask if any further questions occur.
--
https://code.launchpad.net/~janosch-woschitz/graphite/graphite/+merge/99718
Your team graphite-dev is requested to review the proposed merge of lp:~janosch-woschitz/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-28 12:47:48 +0000
@@ -2059,7 +2059,7 @@
return results
-def hitcount(requestContext, seriesList, intervalString):
+def hitcount(requestContext, seriesList, intervalString, alignToInterval = False):
"""
Estimate hit counts from a list of time series.
@@ -2075,6 +2075,28 @@
delta = parseTimeOffset(intervalString)
interval = int(delta.seconds + (delta.days * 86400))
+ if alignToInterval:
+ DAY = 86400
+ HOUR = 3600
+ MINUTE = 60
+
+ requestContext = requestContext.copy()
+ s = requestContext['startTime']
+ if interval >= DAY:
+ requestContext['startTime'] = datetime(s.year, s.month, s.day)
+ elif interval >= HOUR:
+ requestContext['startTime'] = datetime(s.year, s.month, s.day, s.hour)
+ elif interval >= MINUTE:
+ requestContext['startTime'] = datetime(s.year, s.month, s.day, s.hour, s.minute)
+
+ for i,series in enumerate(seriesList):
+ newSeries = evaluateTarget(requestContext, series.pathExpression)[0]
+ intervalCount = int((series.end - series.start) / interval)
+ series[0:len(series)] = newSeries
+ series.start = newSeries.start
+ series.end = newSeries.start + (intervalCount * interval) + interval
+ series.step = newSeries.step
+
for series in seriesList:
length = len(series)
step = int(series.step)
@@ -2117,8 +2139,8 @@
else:
newValues.append(None)
- newName = 'hitcount(%s, "%s")' % (series.name, intervalString)
- newSeries = TimeSeries(newName, newStart, series.end, interval, newValues)
+ newName = 'hitcount(%s, "%s"%s)' % (series.name, intervalString, alignToInterval and ", true" or "")
+ newSeries = TimeSeries(newName, newStart, series.end, interval, newValues)
newSeries.pathExpression = newName
results.append(newSeries)