Aggregate continuous queries for counters

time
influxdb
#1

Hi,

I have a measurement looks like this:

hits   host
1       server_a
1       server_a
1       server_b

I want to aggregate it into per second like

hits   host
2      server_a
1       server_b

WHat’s my best approach to do this?

Everytime I try SELECT COUNT(hits), host … GROUP BY influxdb says

ERR: error parsing query: mixing aggregate and non-aggregate queries is not supported
#2

The problem is that host (assuming host is a tag) can’t be used with an aggregate. In order preserve your tags and aggregate along the host dimension, have a GROUP BY *

SELECT count(hits) as hits 
FROM <measurement> 
WHERE <time condition> 
GROUP BY time(1s), * 
1 Like
#3

Hello Katy,

Thanks for the reply, I am actually trying to create a CQ by downsampling hits fields by aggregate by every 1 seconds.

However, my main problem is that I lost all tags info like the host in the above example.

I am trying to get

SELECT COUNT(hits) as hits, host FROM ... GROUP BY time(1s), host

but it does not work.

Influxdb will result

ERR: error parsing query: mixing aggregate and non-aggregate queries is not supported

#4

OK now I get it, Influxdb will automatically add tags if GROUP BY time(1s), *. Case closed.

2 Likes