本文整理汇总了Python中graphite.render.datalib.TimeSeries类的典型用法代码示例。如果您正苦于以下问题:Python TimeSeries类的具体用法?Python TimeSeries怎么用?Python TimeSeries使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TimeSeries类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: integral
def integral(requestContext, seriesList):
"""
This will show the sum over time, sort of like a continuous addition function.
Useful for finding totals or trends in metrics that are collected per minute.
Example:
.. code-block:: none
&target=integral(company.sales.perMinute)
This would start at zero on the left side of the graph, adding the sales each
minute, and show the total sales for the time period selected at the right
side, (time now, or the time specified by '&until=').
"""
results = []
for series in seriesList:
newValues = []
current = 0.0
for val in series:
if val is None:
newValues.append(None)
else:
current += val
newValues.append(current)
newName = "integral(%s)" % series.name
newSeries = TimeSeries(newName, series.start, series.end, series.step, newValues)
newSeries.pathExpression = newName
results.append(newSeries)
return results
示例2: test_linearRegression
def test_linearRegression(self):
original = functions.evaluateTarget
try:
# series starts at 60 seconds past the epoch and continues for 600 seconds (ten minutes)
# steps are every 60 seconds
savedSeries = TimeSeries('test.value',180,480,60,[3,None,5,6,None,8]),
functions.evaluateTarget = lambda x, y: savedSeries
# input values will be ignored and replaced by regression function
inputSeries = TimeSeries('test.value',1200,1500,60,[123,None,None,456,None,None,None])
inputSeries.pathExpression = 'test.value'
results = functions.linearRegression({
'startTime': datetime(1970, 1, 1, 0, 20, 0, 0, pytz.timezone(settings.TIME_ZONE)),
'endTime': datetime(1970, 1, 1, 0, 25, 0, 0, pytz.timezone(settings.TIME_ZONE)),
'localOnly': False,
'data': [],
}, [ inputSeries ], '00:03 19700101', '00:08 19700101')
# regression function calculated from datapoints on minutes 3 to 8
expectedResult = [
TimeSeries('linearRegression(test.value, 180, 480)',1200,1500,60,[20.0,21.0,22.0,23.0,24.0,25.0,26.0])
]
self.assertEqual(results, expectedResult)
finally:
functions.evaluateTarget = original
示例3: test_TimeSeries_equal_list_color
def test_TimeSeries_equal_list_color(self):
values = range(0,100)
series1 = TimeSeries("collectd.test-db.load.value", 0, len(values), 1, values)
series1.color = 'white'
series2 = TimeSeries("collectd.test-db.load.value", 0, len(values), 1, values)
series2.color = 'white'
self.assertEqual(series1, series2)
示例4: percentileOfSeries
def percentileOfSeries(requestContext, *args):
levels = []
seriesList = []
for arg in args:
logging.info("Arg: %s", arg)
if isinstance(arg, (int, long, float)):
levels.append(arg)
elif isinstance(arg, basestring):
levels += [float(x) for x in arg.split(";")]
else:
seriesList += arg
logging.info("Levels: %s", levels)
logging.info("Series: %s", seriesList)
result = []
for level in levels:
if levels <= 0:
raise ValueError('The requested percent is required to be greater than 0')
name = 'percentilesOfSeries(%s,%g)' % (seriesList[0].pathExpression, level)
(start, end, step) = functions.normalize([seriesList])[1:]
values = [functions._getPercentile(row, level, False) for row in functions.izip(*seriesList)]
resultSeries = TimeSeries(name, start, end, step, values)
resultSeries.pathExpression = name
result.append(resultSeries)
return result
示例5: derivative
def derivative(requestContext, seriesList):
"""
This is the opposite of the integral function. This is useful for taking a
running total metric and showing how many requests per minute were handled.
Example:
.. code-block:: none
&target=derivative(company.server.application01.ifconfig.TXPackets)
Each time you run ifconfig, the RX and TXPackets are higher (assuming there
is network traffic.) By applying the derivative function, you can get an
idea of the packets per minute sent or received, even though you're only
recording the total.
"""
results = []
for series in seriesList:
newValues = []
prev = None
for val in series:
if None in (prev,val):
newValues.append(None)
prev = val
continue
newValues.append(val - prev)
prev = val
newName = "derivative(%s)" % series.name
newSeries = TimeSeries(newName, series.start, series.end, series.step, newValues)
newSeries.pathExpression = newName
results.append(newSeries)
return results
示例6: test_TimeSeries_equal_list_color_bad2
def test_TimeSeries_equal_list_color_bad2(self):
values = range(0,100)
series1 = TimeSeries("collectd.test-db.load.value", 0, len(values), 1, values)
series2 = TimeSeries("collectd.test-db.load.value", 0, len(values), 1, values)
series1.color = 'white'
with self.assertRaises(AssertionError):
self.assertEqual(series1, series2)
示例7: log
def log(requestContext, seriesList, base=10):
"""
Takes one metric or a wildcard seriesList, a base, and draws the y-axis in logarithmic
format. If base is omitted, the function defaults to base 10.
Example:
.. code-block:: none
&target=log(carbon.agents.hostname.avgUpdateTime,2)
"""
results = []
for series in seriesList:
newValues = []
for val in series:
if val is None:
newValues.append(None)
elif val <= 0:
newValues.append(None)
else:
newValues.append(math.log(val, base))
newName = "log(%s, %s)" % (series.name, base)
newSeries = TimeSeries(newName, series.start, series.end, series.step, newValues)
newSeries.pathExpression = newName
results.append(newSeries)
return results
示例8: sumSeries
def sumSeries(requestContext, *seriesLists):
"""
Short form: sum()
This will add metrics together and return the sum at each datapoint. (See
integral for a sum over time)
Example:
.. code-block:: none
&target=sum(company.server.application*.requestsHandled)
This would show the sum of all requests handled per minute (provided
requestsHandled are collected once a minute). If metrics with different
retention rates are combined, the coarsest metric is graphed, and the sum
of the other metrics is averaged for the metrics with finer retention rates.
"""
try:
(seriesList,start,end,step) = normalize(seriesLists)
except:
return []
#name = "sumSeries(%s)" % ','.join((s.name for s in seriesList))
name = "sumSeries(%s)" % ','.join(set([s.pathExpression for s in seriesList]))
values = ( safeSum(row) for row in izip(*seriesList) )
series = TimeSeries(name,start,end,step,values)
series.pathExpression = name
return [series]
示例9: test_TimeSeries_iterate_valuesPerPoint_2_none_values
def test_TimeSeries_iterate_valuesPerPoint_2_none_values(self):
values = [None, None, None, None, None]
series = TimeSeries("collectd.test-db.load.value", 0, len(values)/2, 1, values)
self.assertEqual(series.valuesPerPoint, 1)
series.consolidate(2)
self.assertEqual(series.valuesPerPoint, 2)
expected = TimeSeries("collectd.test-db.load.value", 0, 5, 1, [None, None, None])
self.assertEqual(list(series), list(expected))
示例10: test_TimeSeries_iterate_valuesPerPoint_2_avg
def test_TimeSeries_iterate_valuesPerPoint_2_avg(self):
values = range(0,100)
series = TimeSeries("collectd.test-db.load.value", 0, len(values)/2, 1, values)
self.assertEqual(series.valuesPerPoint, 1)
series.consolidate(2)
self.assertEqual(series.valuesPerPoint, 2)
expected = TimeSeries("collectd.test-db.load.value", 0, 5, 1, [0.5, 2.5, 4.5, 6.5, 8.5, 10.5, 12.5, 14.5, 16.5, 18.5, 20.5, 22.5, 24.5, 26.5, 28.5, 30.5, 32.5, 34.5, 36.5, 38.5, 40.5, 42.5, 44.5, 46.5, 48.5, 50.5, 52.5, 54.5, 56.5, 58.5, 60.5, 62.5, 64.5, 66.5, 68.5, 70.5, 72.5, 74.5, 76.5, 78.5, 80.5, 82.5, 84.5, 86.5, 88.5, 90.5, 92.5, 94.5, 96.5, 98.5, None])
self.assertEqual(list(series), list(expected))
示例11: test_TimeSeries_iterate_valuesPerPoint_2_min
def test_TimeSeries_iterate_valuesPerPoint_2_min(self):
values = range(0,100)
series = TimeSeries("collectd.test-db.load.value", 0, 5, 1, values, consolidate='min')
self.assertEqual(series.valuesPerPoint, 1)
series.consolidate(2)
self.assertEqual(series.valuesPerPoint, 2)
expected = TimeSeries("collectd.test-db.load.value", 0, 5, 1, range(0,100,2)+[None])
self.assertEqual(list(series), list(expected))
示例12: test_TimeSeries_consolidate
def test_TimeSeries_consolidate(self):
values = list(range(0,100))
series = TimeSeries("collectd.test-db.load.value", 0, len(values)/2, 1, values)
self.assertEqual(series.valuesPerPoint, 1)
series.consolidate(2)
self.assertEqual(series.valuesPerPoint, 2)
示例13: test_TimeSeries_iterate_valuesPerPoint_2_invalid
def test_TimeSeries_iterate_valuesPerPoint_2_invalid(self):
values = range(0,100)
series = TimeSeries("collectd.test-db.load.value", 0, 5, 1, values, consolidate='bogus')
self.assertEqual(series.valuesPerPoint, 1)
series.consolidate(2)
self.assertEqual(series.valuesPerPoint, 2)
expected = TimeSeries("collectd.test-db.load.value", 0, 5, 1, range(0,100,2)+[None])
with self.assertRaisesRegexp(Exception, "Invalid consolidation function: 'bogus'"):
result = list(series)
示例14: test_TimeSeries_iterate_valuesPerPoint_2_none_values
def test_TimeSeries_iterate_valuesPerPoint_2_none_values(self):
values = [None, None, None, None, None]
series = TimeSeries("collectd.test-db.load.value", 0, len(values)/2, 1, values)
self.assertEqual(series.valuesPerPoint, 1)
series.consolidate(2)
self.assertEqual(series.valuesPerPoint, 2)
expected = TimeSeries("collectd.test-db.load.value", 0, 5, 1, [None, None, None])
values = [None, None, None, None, None, 1, 2, 3, 4]
series = TimeSeries("collectd.test-db.load.value", 0, len(values)/2, 1, values, xFilesFactor=0.1)
self.assertEqual(series.valuesPerPoint, 1)
self.assertEqual(series.xFilesFactor, 0.1)
series.consolidate(2)
self.assertEqual(series.valuesPerPoint, 2)
expected = TimeSeries("collectd.test-db.load.value", 0, 5, 1, [None, None, 1, 2.5, 4])
self.assertEqual(list(series), list(expected))
series.xFilesFactor = 0.5
self.assertEqual(list(series), list(expected))
series.xFilesFactor = 0.500001
expected = TimeSeries("collectd.test-db.load.value", 0, 5, 1, [None, None, None, 2.5, None])
self.assertEqual(list(series), list(expected))
series.xFilesFactor = 1
self.assertEqual(list(series), list(expected))
示例15: movingAverage
def movingAverage(requestContext, seriesList, windowSize):
"""
Takes one metric or a wildcard seriesList followed by a number N of datapoints and graphs
the average of N previous datapoints. N-1 datapoints are set to None at the
beginning of the graph.
.. code-block:: none
&target=movingAverage(Server.instance01.threads.busy,10)
"""
for seriesIndex, series in enumerate(seriesList):
newName = "movingAverage(%s,%.1f)" % (series.name, float(windowSize))
newSeries = TimeSeries(newName, series.start, series.end, series.step, [])
newSeries.pathExpression = newName
windowIndex = windowSize - 1
for i in range( len(series) ):
if i < windowIndex: # Pad the beginning with None's since we don't have enough data
newSeries.append( None )
else:
window = series[i - windowIndex : i + 1]
nonNull = [ v for v in window if v is not None ]
if nonNull:
newSeries.append( sum(nonNull) / len(nonNull) )
else:
newSeries.append(None)
seriesList[ seriesIndex ] = newSeries
return seriesList