Python twisted.internet.defer.succeed() Examples
The following are 30
code examples of twisted.internet.defer.succeed().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
twisted.internet.defer
, or try the search function
.
Example #1
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def lowestAverage(requestContext, seriesList, n): """ Takes one metric or a wildcard seriesList followed by an integer N. Out of all metrics passed, draws only the bottom N metrics with the lowest average value for the time period specified. Example: .. code-block:: none &target=lowestAverage(server*.instance*.threads.busy,5) Draws the bottom 5 servers with the lowest average value. """ yield defer.succeed(None) returnValue( sorted( seriesList, key=lambda s: safeDiv( safeSum(s), safeLen(s)))[ :n])
Example #2
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def maxSeries(requestContext, *seriesLists): """ Takes one metric or a wildcard seriesList. For each datapoint from each metric passed in, pick the maximum value and graph it. Example: .. code-block:: none &target=maxSeries(Server*.connections.total) """ yield defer.succeed(None) (seriesList, start, end, step) = normalize(seriesLists) name = "maxSeries(%s)" % formatPathExpressions(seriesList) values = (safeMax(row) for row in izip(*seriesList)) series = TimeSeries(name, start, end, step, values) series.pathExpression = name returnValue([series])
Example #3
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def absolute(requestContext, seriesList): """ Takes one metric or a wildcard seriesList and applies the mathematical abs function to each datapoint transforming it to its absolute value. Example: .. code-block:: none &target=absolute(Server.instance01.threads.busy) &target=absolute(Server.instance*.threads.busy) """ yield defer.succeed(None) for series in seriesList: series.name = "absolute(%s)" % (series.name) series.pathExpression = series.name for i, value in enumerate(series): series[i] = safeAbs(value) returnValue(seriesList)
Example #4
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def multiplySeries(requestContext, *seriesLists): """ Takes two or more series and multiplies their points. A constant may not be used. To multiply by a constant, use the scale() function. Example: .. code-block:: none &target=multiplySeries(Series.dividends,Series.divisors) """ yield defer.succeed(None) (seriesList, start, end, step) = normalize(seriesLists) if len(seriesList) == 1: returnValue(seriesList) name = "multiplySeries(%s)" % ','.join([s.name for s in seriesList]) product = imap(lambda x: safeMul(*x), izip(*seriesList)) resultSeries = TimeSeries(name, start, end, step, product) resultSeries.pathExpression = name returnValue([resultSeries])
Example #5
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def scale(requestContext, seriesList, factor): """ Takes one metric or a wildcard seriesList followed by a constant, and multiplies the datapoint by the constant provided at each point. Example: .. code-block:: none &target=scale(Server.instance01.threads.busy,10) &target=scale(Server.instance*.threads.busy,10) """ yield defer.succeed(None) for series in seriesList: series.name = "scale(%s,%g)" % (series.name, float(factor)) series.pathExpression = series.name for i, value in enumerate(series): series[i] = safeMul(value, factor) returnValue(seriesList)
Example #6
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def cumulative(requestContext, seriesList, consolidationFunc='sum'): """ Takes one metric or a wildcard seriesList, and an optional function. Valid functions are 'sum', 'average', 'min', and 'max' Sets the consolidation function to 'sum' for the given metric seriesList. Alias for :func:`consolidateBy(series, 'sum') <graphite.render.functions.consolidateBy>` .. code-block:: none &target=cumulative(Sales.widgets.largeBlue) """ yield defer.succeed(None) result = yield consolidateBy(requestContext, seriesList, 'sum') returnValue(result)
Example #7
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def aliasByNode(requestContext, seriesList, *nodes): """ Takes a seriesList and applies an alias derived from one or more "node" portion/s of the target name. Node indices are 0 indexed. .. code-block:: none &target=aliasByNode(ganglia.*.cpu.load5,1) """ cb_pattern = re.compile(r"{([^,]+\,)*([^,])+}") mp_pattern = re.compile(r"(?:.*\()?(?P<name>[-\w*\.]+)(?:,|\)?.*)?") substitution = 'UNKNOWN' yield defer.succeed(None) if isinstance(nodes, int): nodes = [nodes] for series in seriesList: curly_brackets = cb_pattern.search(series.name) if curly_brackets: substitution = curly_brackets.groups()[-1] metric_pieces = mp_pattern.search(cb_pattern.sub(substitution, series.name)).groups()[0].split('.') series.name = '.'.join(metric_pieces[n] for n in nodes) returnValue(seriesList)
Example #8
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def color(requestContext, seriesList, theColor): """ Assigns the given color to the seriesList Example: .. code-block:: none &target=color(collectd.hostname.cpu.0.user, 'green') &target=color(collectd.hostname.cpu.0.system, 'ff0000') &target=color(collectd.hostname.cpu.0.idle, 'gray') &target=color(collectd.hostname.cpu.0.idle, '6464ffaa') """ yield defer.succeed(None) for series in seriesList: series.color = theColor returnValue(seriesList)
Example #9
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def minimumAbove(requestContext, seriesList, n): """ Takes one metric or a wildcard seriesList followed by a constant n. Draws only the metrics with a minimum value above n. Example: .. code-block:: none &target=minimumAbove(system.interface.eth*.packetsSent,1000) This would only display interfaces which sent more than 1000 packets/min. """ yield defer.succeed(None) results = [] for series in seriesList: if min(series) > n: results.append(series) returnValue(results)
Example #10
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def maximumBelow(requestContext, seriesList, n): """ Takes one metric or a wildcard seriesList followed by a constant n. Draws only the metrics with a maximum value below n. Example: .. code-block:: none &target=maximumBelow(system.interface.eth*.packetsSent,1000) This would only display interfaces which sent less than 1000 packets/min. """ yield defer.succeed(None) result = [] for series in seriesList: if max(series) <= n: result.append(series) returnValue(result)
Example #11
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def minimumBelow(requestContext, seriesList, n): """ Takes one metric or a wildcard seriesList followed by a constant n. Draws only the metrics with a minimum value below n. Example: .. code-block:: none &target=minimumBelow(system.interface.eth*.packetsSent,1000) This would only display interfaces which at one point sent less than 1000 packets/min. """ yield defer.succeed(None) result = [] for series in seriesList: if min(series) <= n: result.append(series) returnValue(result)
Example #12
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def highestCurrent(requestContext, seriesList, n): """ Takes one metric or a wildcard seriesList followed by an integer N. Out of all metrics passed, draws only the N metrics with the highest value at the end of the time period specified. Example: .. code-block:: none &target=highestCurrent(server*.instance*.threads.busy,5) Draws the 5 servers with the highest busy threads. """ yield defer.succeed(None) returnValue(sorted(seriesList, key=safeLast)[-n:])
Example #13
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def currentAbove(requestContext, seriesList, n): """ Takes one metric or a wildcard seriesList followed by an integer N. Out of all metrics passed, draws only the metrics whose value is above N at the end of the time period specified. Example: .. code-block:: none &target=currentAbove(server*.instance*.threads.busy,50) Draws the servers with more than 50 busy threads. """ yield defer.succeed(None) returnValue([series for series in seriesList if safeLast(series) >= n])
Example #14
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def currentBelow(requestContext, seriesList, n): """ Takes one metric or a wildcard seriesList followed by an integer N. Out of all metrics passed, draws only the metrics whose value is below N at the end of the time period specified. Example: .. code-block:: none &target=currentBelow(server*.instance*.threads.busy,3) Draws the servers with less than 3 busy threads. """ yield defer.succeed(None) returnValue([series for series in seriesList if safeLast(series) <= n])
Example #15
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def highestAverage(requestContext, seriesList, n): """ Takes one metric or a wildcard seriesList followed by an integer N. Out of all metrics passed, draws only the top N metrics with the highest average value for the time period specified. Example: .. code-block:: none &target=highestAverage(server*.instance*.threads.busy,5) Draws the top 5 servers with the highest average value. """ yield defer.succeed(None) returnValue( sorted(seriesList, key=lambda s: safeDiv(safeSum(s), safeLen(s)))[-n:])
Example #16
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def highestMax(requestContext, seriesList, n): """ Takes one metric or a wildcard seriesList followed by an integer N. Out of all metrics passed, draws only the N metrics with the highest maximum value in the time period specified. Example: .. code-block:: none &target=highestMax(server*.instance*.threads.busy,5) Draws the top 5 servers who have had the most busy threads during the time period specified. """ yield defer.succeed(None) result_list = sorted(seriesList, key=lambda s: max(s))[-n:] returnValue(sorted(result_list, key=lambda s: max(s), reverse=True))
Example #17
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def averageAbove(requestContext, seriesList, n): """ Takes one metric or a wildcard seriesList followed by an integer N. Out of all metrics passed, draws only the metrics with an average value above N for the time period specified. Example: .. code-block:: none &target=averageAbove(server*.instance*.threads.busy,25) Draws the servers with average values above 25. """ yield defer.succeed(None) returnValue([series for series in seriesList if safeDiv( safeSum(series), safeLen(series)) >= n])
Example #18
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def averageOutsidePercentile(requestContext, seriesList, n): """ Removes functions lying inside an average percentile interval """ yield defer.succeed(None) averages = [] for s in seriesList: averages.append(safeDiv(safeSum(s), safeLen(s))) if n < 50: n = 100 - n lowPercentile = _getPercentile(averages, 100 - n) highPercentile = _getPercentile(averages, n) returnValue([s for s in seriesList if not lowPercentile < safeDiv( safeSum(s), safeLen(s)) < highPercentile])
Example #19
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def limit(requestContext, seriesList, n): """ Takes one metric or a wildcard seriesList followed by an integer N. Only draw the first N metrics. Useful when testing a wildcard in a metric. Example: .. code-block:: none &target=limit(server*.instance*.memory.free,5) Draws only the first 5 instance's memory free. """ yield defer.succeed(None) returnValue(seriesList[0:n])
Example #20
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def sortByMaxima(requestContext, seriesList): """ Takes one metric or a wildcard seriesList. Sorts the list of metrics by the maximum value across the time period specified. Useful with the &areaMode=all parameter, to keep the lowest value lines visible. Example: .. code-block:: none &target=sortByMaxima(server*.instance*.memory.free) """ yield defer.succeed(None) def compare(x, y): return cmp(max(y), max(x)) seriesList.sort(compare) returnValue(seriesList)
Example #21
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def useSeriesAbove(requestContext, seriesList, value, search, replace): """ Compares the maximum of each series against the given `value`. If the series maximum is greater than `value`, the regular expression search and replace is applied against the series name to plot a related metric e.g. given useSeriesAbove(ganglia.metric1.reqs,10,'reqs','time'), the response time metric will be plotted only when the maximum value of the corresponding request/s metric is > 10 .. code-block:: none &target=useSeriesAbove(ganglia.metric1.reqs,10,"reqs","time") """ yield defer.succeed(None) newSeries = [] for series in seriesList: newname = re.sub(search, replace, series.name) if max(series) > value: n = yield evaluateTarget(requestContext, newname) if n is not None and len(n) > 0: newSeries.append(n[0]) returnValue(newSeries)
Example #22
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def fallbackSeries(requestContext, seriesList, fallback): """ Takes a wildcard seriesList, and a second fallback metric. If the wildcard does not match any series, draws the fallback metric. Example: .. code-block:: none &target=fallbackSeries(server*.requests_per_second, constantLine(0)) Draws a 0 line when server metric does not exist. """ yield defer.succeed(None) if len(seriesList) > 0: returnValue(seriesList) else: returnValue(fallback)
Example #23
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def drawAsInfinite(requestContext, seriesList): """ Takes one metric or a wildcard seriesList. If the value is zero, draw the line at 0. If the value is above zero, draw the line at infinity. If the value is null or less than zero, do not draw the line. Useful for displaying on/off metrics, such as exit codes. (0 = success, anything else = failure.) Example: .. code-block:: none drawAsInfinite(Testing.script.exitCode) """ yield defer.succeed(None) for series in seriesList: series.options['drawAsInfinite'] = True series.name = 'drawAsInfinite(%s)' % series.name returnValue(seriesList)
Example #24
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def lineWidth(requestContext, seriesList, width): """ Takes one metric or a wildcard seriesList, followed by a float F. Draw the selected metrics with a line width of F, overriding the default value of 1, or the &lineWidth=X.X parameter. Useful for highlighting a single metric out of many, or having multiple line widths in one graph. Example: .. code-block:: none &target=lineWidth(server01.instance01.memory.free,5) """ yield defer.succeed(None) for series in seriesList: series.options['lineWidth'] = width returnValue(seriesList)
Example #25
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def dashed(requestContext, *seriesList): """ Takes one metric or a wildcard seriesList, followed by a float F. Draw the selected metrics with a dotted line with segments of length F If omitted, the default length of the segments is 5.0 Example: .. code-block:: none &target=dashed(server01.instance01.memory.free,2.5) """ yield defer.succeed(None) if len(seriesList) == 2: dashLength = seriesList[1] else: dashLength = 5 for series in seriesList[0]: series.name = 'dashed(%s, %d)' % (series.name, dashLength) series.options['dashed'] = dashLength returnValue(seriesList[0])
Example #26
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def constantLine(requestContext, value): """ Takes a float F. Draws a horizontal line at value F across the graph. Example: .. code-block:: none &target=constantLine(123.456) """ yield defer.succeed(None) name = "constantLine(%s)" % str(value) start = int(epoch(requestContext['startTime'])) end = int(epoch(requestContext['endTime'])) step = (end - start) / 1.0 series = TimeSeries(str(value), start, end, step, [value, value]) series.pathExpression = name returnValue([series])
Example #27
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def threshold(requestContext, value, label=None, color=None): """ Takes a float F, followed by a label (in double quotes) and a color. (See ``bgcolor`` in the render\_api_ for valid color names & formats.) Draws a horizontal line at value F across the graph. Example: .. code-block:: none &target=threshold(123.456, "omgwtfbbq", red) """ yield defer.succeed(None) series = constantLine(requestContext, value)[0] if label: series.name = label if color: series.color = color returnValue([series])
Example #28
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def identity(requestContext, name): """ Identity function: Returns datapoints where the value equals the timestamp of the datapoint. Useful when you have another series where the value is a timestamp, and you want to compare it to the time of the datapoint, to render an age Example: .. code-block:: none &target=identity("The.time.series") This would create a series named "The.time.series" that contains points where x(t) == t. """ yield defer.succeed(None) step = 60 start = int(epoch(requestContext["startTime"])) end = int(epoch(requestContext["endTime"])) values = range(start, end, step) series = TimeSeries(name, start, end, step, values) series.pathExpression = 'identity("%s")' % name returnValue([series])
Example #29
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def countSeries(requestContext, *seriesLists): """ Draws a horizontal line representing the number of nodes found in the seriesList. .. code-block:: none &target=countSeries(carbon.agents.*.*) """ yield defer.succeed(None) (seriesList, start, end, step) = normalize(seriesLists) name = "countSeries(%s)" % formatPathExpressions(seriesList) values = (int(len(row)) for row in izip(*seriesList)) series = TimeSeries(name, start, end, step, values) series.pathExpression = name returnValue([series])
Example #30
Source File: functions.py From worker with GNU General Public License v3.0 | 6 votes |
def removeEmptySeries(requestContext, seriesList): """ Takes one metric or a wildcard seriesList. Out of all metrics passed, draws only the metrics with not empty data Example: .. code-block:: none &target=removeEmptySeries(server*.instance*.threads.busy) Draws only live servers with not empty data. """ yield defer.succeed(None) returnValue([series for series in seriesList if safeIsNotEmpty(series)])