Skip to content

Commit

Permalink
Merge in https://github.com/obfuscurity/graphite @b070a4d and @a915ff2
Browse files Browse the repository at this point in the history
Add function aliasByMetric
typo, found by RedKrieg
  • Loading branch information
mleinart committed Apr 22, 2012
1 parent 84f61bd commit c4a9bd9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions webapp/content/js/composer_widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,7 @@ function createFunctionsMenu() {
text: 'Special',
menu: [
{text: 'Set Legend Name', handler: applyFuncToEachWithInput('alias', 'Enter a legend label for this graph target', {quote: true})},
{text: 'Set Legend Name By Metric', handler: applyFuncToEach('aliasByMetric')},
{text: 'Add Value to Legend Name',
menu: [
{text: "Last Value", handler: applyFuncToEach('legendValue', '"last"')},
Expand Down
2 changes: 1 addition & 1 deletion webapp/graphite/browser/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def json_response(nodes, request=None):
#json = str(nodes) #poor man's json encoder for simple types
json_data = json.dumps(nodes)
if jsonp:
response = HttpResponse("%s(%s)" % (jsonp, json_data),mimetype="test/javascript")
response = HttpResponse("%s(%s)" % (jsonp, json_data),mimetype="text/javascript")
else:
response = HttpResponse(json_data,mimetype="application/json")
response['Pragma'] = 'no-cache'
Expand Down
14 changes: 14 additions & 0 deletions webapp/graphite/render/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,19 @@ def aliasByNode(requestContext, seriesList, *nodes):
series.name = '.'.join(metric_pieces[n] for n in nodes)
return seriesList

def aliasByMetric(requestContext, seriesList):
"""
Takes a seriesList and applies an alias derived from the base metric name.
.. code-block:: none
&target=aliasByMetric(carbon.agents.graphite.creates)
"""
for series in seriesList:
series.name = series.name.split('.')[-1]
return seriesList

def legendValue(requestContext, seriesList, *valueTypes):
"""
Takes one metric or a wildcard seriesList and a string in quotes.
Expand Down Expand Up @@ -2388,6 +2401,7 @@ def pieMinimum(requestContext, series):
'alias' : alias,
'aliasSub' : aliasSub,
'aliasByNode' : aliasByNode,
'aliasByMetric' : aliasByMetric,
'cactiStyle' : cactiStyle,
'color' : color,
'alpha' : alpha,
Expand Down

0 comments on commit c4a9bd9

Please sign in to comment.