InfluxDB count same string values for a timerange

2.1k views Asked by At

I've set up the following InfluxDB measurement called ratio with one fieldKey called "name"

--------------------------------------------------
| time                | name                     |
--------------------------------------------------
| 1481274571179850400 | current_assets           |
--------------------------------------------------
| 1481274571179850401 | othervalue               |
--------------------------------------------------
| 1481274571179850402 | othervalue               |
--------------------------------------------------
| 1481274571179850403 | current_assets           |
--------------------------------------------------
| 1481274571179850404 | othervalue               |
--------------------------------------------------

There are about 20 different names. Depending on what is called on the backend I write one line with the given name (e.g. current_assets, othervalue, ...) for statistic.

This works well and I get the table above.

Now I'd like to create one query (in grafana)

  • hits per timerange for a single name

e.g.

251 "current_assets" entries the last 24 hours

21 "other value" entries the last 6 hours

I have tried different things here but I can not make it.

Does somebody have any idea how such a query can look?

Thanks a lot

1

There are 1 answers

0
Michael Desa On BEST ANSWER

I'd recommend changing name to a tag and having a field value that either stores an integer or a bool. That way you can issue queries like

SELECT count(value) FROM ratio WHERE time > now() - 24h GROUP BY name