Skip to content

Commit

Permalink
Add a grep function that returns metrics that match a regular expression
Browse files Browse the repository at this point in the history
The opposite behavior of exclude
  • Loading branch information
nightfly19 committed Apr 28, 2013
1 parent e72fcb6 commit 4d449d7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions webapp/content/js/composer_widgets.js
Expand Up @@ -959,6 +959,7 @@ function createFunctionsMenu() {
{text: 'sortByMinima', handler: applyFuncToEach('sortByMinima')},
{text: 'limit', handler: applyFuncToEachWithInput('limit', 'Limit to first ___ of a list of metrics')},
{text: 'Exclude', handler: applyFuncToEachWithInput('exclude', 'Exclude metrics that match a regular expression')}
{text: 'Grep', handler: applyFuncToEachWithInput('grep', 'Exclude metrics that don\'t match a regular expression')}
]
}, {
text: 'Special',
Expand Down
15 changes: 15 additions & 0 deletions webapp/graphite/render/functions.py
Expand Up @@ -2312,6 +2312,21 @@ def exclude(requestContext, seriesList, pattern):
return [s for s in seriesList if not regex.search(s.name)]


def grep(requestContext, seriesList, pattern):
"""
Takes a metric or a wildcard seriesList, followed by a regular expression
in double quotes. Excludes metrics that don't match the regular expression.
Example:
.. code-block:: none
&target=grep(servers*.instance*.threads.busy,"server02")
"""
regex = re.compile(pattern)
return [s for s in seriesList if regex.search(s.name)]


def smartSummarize(requestContext, seriesList, intervalString, func='sum', alignToFrom=False):
"""
Smarter experimental version of summarize.
Expand Down

0 comments on commit 4d449d7

Please sign in to comment.