implement replaceAlias() function, #287

This commit is contained in:
Alexander Zobnin
2017-04-17 13:25:02 +03:00
parent 0e318e719a
commit df1c3e7ef4
12 changed files with 139 additions and 55 deletions

View File

@@ -158,3 +158,35 @@ Examples:
```
setAlias(Zabbix busy [a-zA-Z]+)
```
### replaceAlias
```
replaceAlias(pattern, newAlias)
```
Replace metric name using pattern. Pattern is regex or regular string. If regex is used, following special replacement patterns are supported:
|Pattern | Inserts|
----------|---------
|$$ | Inserts a "$". |
|$& | Inserts the matched substring. |
|$` | Inserts the portion of the string that precedes the matched substring. |
|$' | Inserts the portion of the string that follows the matched substring. |
|$n | Where n is a non-negative integer less than 100, inserts the nth parenthesized submatch string, provided the first argument was a RegExp object. |
For more detais see [String.prototype.replace()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) function.
Examples:
```
CPU system time
replaceAlias(/CPU (.*) time/, $1) -> system
backend01: CPU system time
replaceAlias(/CPU (.*) time/, $1) -> backend01: system
backend01: CPU system time
replaceAlias(/.*CPU (.*) time/, $1) -> system
backend01: CPU system time
replaceAlias(/(.*): CPU (.*) time/, $1 - $2) -> backend01 - system
```