2018-05-22 06:46:10 +08:00
# Regex Processor Plugin
The `regex` plugin transforms tag and field values with regex pattern. If `result_key` parameter is present, it can produce new tags and fields from existing ones.
2019-06-15 06:23:54 +08:00
For tags transforms, if `append` is set to `true` , it will append the transformation to the existing tag value, instead of overwriting it.
2021-11-05 00:45:52 +08:00
For metrics transforms, `key` denotes the element that should be transformed. Furthermore, `result_key` allows control over the behavior applied in case the resulting `tag` or `field` name already exists.
2018-05-22 06:46:10 +08:00
### Configuration:
```toml
[[processors.regex]]
namepass = ["nginx_requests"]
# Tag and field conversions defined in a separate sub-tables
[[processors.regex.tags]]
## Tag to change
key = "resp_code"
## Regular expression to match on a tag value
pattern = "^(\\d)\\d\\d$"
2019-06-14 01:27:17 +08:00
## Matches of the pattern will be replaced with this string. Use ${1}
## notation to use the text of the first submatch.
2018-05-22 06:46:10 +08:00
replacement = "${1}xx"
[[processors.regex.fields]]
2019-06-14 01:27:17 +08:00
## Field to change
2018-05-22 06:46:10 +08:00
key = "request"
## All the power of the Go regular expressions available here
## For example, named subgroups
pattern = "^/api(?P< method > /[\\w/]+)\\S*"
replacement = "${method}"
## If result_key is present, a new field will be created
## instead of changing existing field
result_key = "method"
# Multiple conversions may be applied for one field sequentially
# Let's extract one more value
[[processors.regex.fields]]
key = "request"
pattern = ".*category=(\\w+).*"
replacement = "${1}"
result_key = "search_category"
2021-11-05 00:45:52 +08:00
# Rename metric fields
[[processors.regex.field_rename]]
## Regular expression to match on a field name
pattern = "^search_(\\w+)d$"
## Matches of the pattern will be replaced with this string. Use ${1}
## notation to use the text of the first submatch.
replacement = "${1}"
## If the new field name already exists, you can either "overwrite" the
## existing one with the value of the renamed field OR you can "keep"
## both the existing and source field.
# result_key = "keep"
# Rename metric tags
# [[processors.regex.tag_rename]]
# ## Regular expression to match on a tag name
# pattern = "^search_(\\w+)d$"
# ## Matches of the pattern will be replaced with this string. Use ${1}
# ## notation to use the text of the first submatch.
# replacement = "${1}"
# ## If the new tag name already exists, you can either "overwrite" the
# ## existing one with the value of the renamed tag OR you can "keep"
# ## both the existing and source tag.
# # result_key = "keep"
# Rename metrics
# [[processors.regex.metric_rename]]
# ## Regular expression to match on an metric name
# pattern = "^search_(\\w+)d$"
# ## Matches of the pattern will be replaced with this string. Use ${1}
# ## notation to use the text of the first submatch.
# replacement = "${1}"
2018-05-22 06:46:10 +08:00
```
### Tags:
No tags are applied by this processor.
### Example Output:
```
2021-11-05 00:45:52 +08:00
nginx_requests,verb=GET,resp_code=2xx request="/api/search/?category=plugins& q=regex& sort=asc",method="/search/",category="plugins",referrer="-",ident="-",http_version=1.1,agent="UserAgent",client_ip="127.0.0.1",auth="-",resp_bytes=270i 1519652321000000000
2018-05-22 06:46:10 +08:00
```