Group By field?

Hello,

I have a VPS monitor system with influxdb and in one field (status) I store the current status of the VPS (running, stopped or suspended) and I store it in Influx as a string (I could but I didn’t assigned a numerical value for each state) and to display a grafana counter I have to know how many VPSs are in each state, you know, how many VPSs are running, stopped and suspended and I don’t know how to do the query, does someone knows how to get this.

Thanks.

I dunno your schema, but perhaps something like:
select count(“state”) from MEAS group by(time) where “state” = 'running’
precisely replace MEAS and time with your actual values.

I’ve done this:

SELECT count("status") AS "count_status" FROM "general" WHERE time > now() - 1h AND  "status"='running' group by time(30s) fill(previous)

But on the first seconds of every 30s “group by” the returned count is less than real because not all the nodes have submitted the data yet, and I don’t know how to solve that.

You can’t solve that. If there is no data from nodes, then how would you like solve that? Predict the data? :slight_smile:
It seems you are trying to break causality here.
You just have to wait… or adjust your query to something like that to ensure all the data is in there:
...WHERE time > now() - 1h AND time < now() - 1m.....

Well, as the documentation shows the fill(previous) should report the value from the previous time interval for time intervals with no data if I made a subquery where I get the status of each VPS for the time range and I use fill previous I would get a consistent serie, but I don’t know why it does not work.

This query:
SELECT last("status") AS "status" FROM "tbh_vps"."autogen"."general" WHERE time > now() - 5m GROUP BY time(30s), "id" FILL(previous)

Returns a matrix of the last 11 states of the VPS on every 30 seconds, but when I try this:

SELECT count("status") FROM (SUBQUERIE) WHERE "status" = 'running' group by time(30s)

It does not work, and I don’t understand why, becouse if I remove the fill(previous) from the subquery the whole statement works as expected.