0
votes

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
Can you include what you've currently tried? Does something like SELECT count(name) FROM ratio WHERE name = 'current_assets' and time > now() - 24h work? - Michael Desa
yes I have tried it with an "where" condition and it works so far. But I don't like to create a seperate query for all 20 different conditions. - Michi
Unless you modify your schema, you'll need multiple queries. Essentially what you want to do is GROUP BY name which is only possible is name is a tag. - Michael Desa
@MichaelDesa thanks a lot! I've changed the "name" to an tag and its working great - Michi
Awesome! Glad to hear that it worked. - Michael Desa

1 Answers

1
votes

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