Regex to change metric name

Dear all,
im going crazy to change change a metric name with regex processors.

Im using the below code to change the “metricname” to "metricname_alarms

[[processors.regex]] [[processors.regex.metric_rename]] ## Regular expression to match on an metric name pattern = '([A-Za-z]+)$' ## Replacement expression defining the new name of the metric replacement = '${1}_alarms'
I do not understand why it chnge name but append 3 “_alarms” string to “mtricname”.
Example the metric name is “Hello” and the new metric name is “Hello_alarms_alarms_alarms”

Help!

Your current configuration

pattern = '([A-Za-z]+)$'
replacement = '${1}_alarms'

matches any alphanumeric characters at the end of the string and adds “_alarms”. When applied again, it matches the alphanumeric part before “_alarms” and adds another “_alarms”, resulting in multiple suffixes.

here are two recommended solutions:

Option 1: Use Two Processors in Sequence

This approach uses the namedrop parameter to exclude metrics that already have the “_alarms” suffix:

# First processor to handle metrics that don't already have _alarms suffix
[[processors.regex]]
    namepass = ["*"]
    # Only process metrics that DON'T end with _alarms
    namedrop = ["*_alarms"]
    
    [[processors.regex.metric_rename]]
      pattern = '^(.+)$'
      replacement = '${1}_alarms'

Option 2: Conditional Logic

Conditional logic in the replacement string:

[[processors.regex]]
    namepass = ["*"]
    
    [[processors.regex.metric_rename]]
      pattern = '^(.+)$'
      replacement = '''
      # Use TOML multi-line string format for embedded logic
      if val(".+_alarms$") {
        return name
      }
      return name + "_alarms"
      '''