Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE]: Added function multiplySeriesWithWildcards #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions webapp/graphite/render/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,38 @@ def sumSeriesWithWildcards(requestContext, seriesList, *position): #XXX

return [newSeries[name] for name in newNames]

def multiplySeriesWithWildcards(requestContext, seriesList, *position): #XXX
"""
Call multiplySeries after inserting wildcards at the given position(s).

Example:

.. code-block:: none

&target=multiplySeriesWithWildcards([web.host-[0-7].avg-response.value, web.host-[0-7].total-request.value], 2,3)

This would be the equivalent of
``target=multiplySeries(web.host-0.avg-response.value, web.host-0.total-request.value)&target=multiplySeries(web.host-1.avg-response.value, web.host-1.total-request.value)...``

"""
if type(position) is int:
positions = [position]
else:
positions = position

newSeries = {}
newNames = list()

for series in seriesList:
newname = '.'.join(map(lambda x: x[1], filter(lambda i: i[0] not in positions, enumerate(series.name.split('.')))))
if newname in newSeries.keys():
newSeries[newname] = multiplySeries(requestContext, (newSeries[newname], series))[0]
else:
newSeries[newname] = series
newNames.append(newname)
newSeries[newname].name = newname
return [newSeries[name] for name in newNames]

def averageSeriesWithWildcards(requestContext, seriesList, *position): #XXX
"""
Call averageSeries after inserting wildcards at the given position(s).
Expand Down Expand Up @@ -3234,6 +3266,7 @@ def pieMinimum(requestContext, series):
'stddevSeries' : stddevSeries,
'avg' : averageSeries,
'sumSeriesWithWildcards': sumSeriesWithWildcards,
'multiplySeriesWithWildcards': multiplySeriesWithWildcards,
'averageSeriesWithWildcards': averageSeriesWithWildcards,
'minSeries' : minSeries,
'maxSeries' : maxSeries,
Expand Down