Select downsample function based on the condition

We are collecting electrical data from sensors and storing into influxdb with telegraf as a collector. We are clubbing all the measurements in one. Some of the measurements are counter values and others are normal instantaneous data.

Sample Data Format

Reading,SensorId=Value MeasurementId=Value MeasurementId=Value timestamp
Reading,SensorId=123123 2001=12345454 2002=45.56 1519209815

Where 2001, 2002 are the unique identifier of electrical parameters like kWH, kW etc.

Now we want to downsample the data to 15 mins using CONTINUOUS QUERY. The data is a mixture of counters and instantaneous parameter and for the downsampling different functions need to be applied based on the field_id. The parameter type we are storing in the Postgres whether it’s counter or instantaneous.

counter field_ids = derivative()
instantaneous field_ids = mean()

So how to specify these condition in Continuous Query. What is the best way to achieve this?

@HardikSondagar, great question! Right now, most people are writing large continuous queries where each field has the aggregate applied to it.

This method works well when there are fewer fields, but takes longer as the number of fields grows.

Another method is to create a Kapacitor task to do this. While it still depends on the number of fields, it at least moves the workload off of the db.

We’ve been working on this issue, and you can find details on how to set up the CQ and the surrounding issues on this GitHub issue.

I hope that helps!