Aggregate data in Telegraf only by time, not by tags

830 views Asked by At

I use Telegraf to collect data and then write it to InfluxDb. And I would like to aggregate the data into one row. As I know there are a lot of plugins for Telegraf including plugins to aggregate data. I use BasicStats Aggregator Plugin for my purpose. But it has unexpected behavior (unexpected for me). It aggregates rows by their tags but I need aggregation only by timestamp. How can I make this plugin to aggregate rows only by their timestamps? For example I have the following rows:

timestamp=1 tag1=foo field1=3

timestamp=1 tag1=bar field1=1

timestamp=1 tag1=baz field1=4

and for them I would like to get the following aggregated row:

timestamp=1 sum=8

Thank you in advance

1

There are 1 answers

0
Javier Galarza On

I believe you can't aggregate by timestamp with Telegraf's conventional processors or aggregators( like BasicStats ) because of InfluxDB's nature. It is a time-series database and it is indexed by time. But you can aggregate the data with an InfluxDB Query:

SELECT mean("field1") FROM "statsdemo"."telegraf"."my_metric" WHERE time > now()-5m AND time < now() GROUP BY time(2000ms) FILL(null)

Another approach could be using execd aggregator. Just write a script with bash or your favorite programming language that reads from STDIN, aggregate the data by timestamp, and print the result to STDOUT following the influx line protocol. I have never used this aggregator before, but I think it may work.