Regex parsing in telegraf

Hi team,

I am new to the telegraf and I wondering if I can achieve this by Regex Processor or other Processor. My input is a statsd format metrics like this, where {job_name}_start is a dynamic filed and job_name can be some different values:


I can convert it to Influx message by telegraf statsd plugin with template "measurement.field”, so the InfluxDB protocol metrics would be

metrics_namespace, {job_name}_start = 100

I want o further parse field {job_name}_start so that the field can have static name called “job_start”, and ca have another tag called job_name, to hold actual {job_name} value. So the the metrics I want is:

metrics_namespace, job_start = 100, job_name = {job_name}

How can I achieve that? I try to use Regex Processor Plugin. But not sure how to generate new tag based on measurement name. Any help is much appreciated

Thanks a lot


The regex processor works on the values of string fields, so that isn’t the route to go.

I would probably user a starlark processor to loop through the fields, find the one with a _start in the name and then make the changes. Something like:

  source = '''
def apply(metric):
    for k, v in metric.fields.items():
        if "_start" in k:
            metric.fields["job_start"] = v
            metric.tags["job_name"] = k.rstrip("_start")

    return metric

This removes the old field, adds it back as “job_start” and then creates a new tag with the string of the key without the _start.

This would convert:

metrics_namespace my_job_start=100 1661540791000000000


metrics_namespace,job_name=my_job job_start=100 1661541352000000000

Does that help?

Thanks so much @jpowers That works really well for my needs.

1 Like