本文整理汇总了Python中graphite.render.datalib.TimeSeries.insert方法的典型用法代码示例。如果您正苦于以下问题:Python TimeSeries.insert方法的具体用法?Python TimeSeries.insert怎么用?Python TimeSeries.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graphite.render.datalib.TimeSeries
的用法示例。
在下文中一共展示了TimeSeries.insert方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: stdev
# 需要导入模块: from graphite.render.datalib import TimeSeries [as 别名]
# 或者: from graphite.render.datalib.TimeSeries import insert [as 别名]
def stdev(requestContext, seriesList, time):
"""
Takes one metric or a wildcard seriesList followed by an integer N.
Draw the Standard Deviation of all metrics passed for the past N datapoints.
Example:
.. code-block:: none
&target=stddev(server*.instance*.threads.busy,30)
"""
count = 0
for series in seriesList:
stddevs = TimeSeries("stddev(%s,%.1f)" % (series.name, float(time)), series.start, series.end, series.step, [])
stddevs.pathExpression = "stddev(%s,%.1f)" % (series.name, float(time))
avg = safeDiv(safeSum(series[:time]), time)
if avg is not None:
sumOfSquares = sum(map(lambda(x): x * x, [v for v in series[:time] if v is not None]))
(sd, sumOfSquares) = doStdDev(sumOfSquares, 0, 0, time, avg)
stddevs.append(sd)
else:
stddevs.append(None)
for (index, el) in enumerate(series[time:]):
if el is None:
continue
toDrop = series[index]
if toDrop is None:
toDrop = 0
s = safeSum([safeMul(time, avg), el, -toDrop])
avg = safeDiv(s, time)
if avg is not None:
(sd, sumOfSquares) = doStdDev(sumOfSquares, toDrop, series[index+time], time, avg)
stddevs.append(sd)
else:
stddevs.append(None)
for i in range(0, time-1):
stddevs.insert(0, None)
seriesList[count] = stddevs
count = count + 1
return seriesList