I have a bunch of measurements, all starting with task_runtime.
i.e.
task_runtime.task_a
task_runtime.task_b
task_runtime.task_c
Is there a way to select all of them by a partial measurement name?
I'm using grafana on top of influxdb and I want to display all of these measurements in a single graph, but I don't have a closed list of these measurements.
I thought about something like
select * from (select table_name from all_tables where table_name like "task_runtime.*")
But not sure on the influxdb syntax for this
You can use a regular expression when specifying measurements in the FROM clause as described in the InfluxDB documentation.
For example, in your case:
SELECT * FROM /^task_runtime.*/
Grafana also supports this and will display all measurements separately.
Related
I have developed a project using influxdb and I am currently trying to understand why my influx container keeps crashing due to oom exits.
The way I designed my database is quite basic. I have several buildings, for each building, I need to have timebased values. So I created a database for each building, and a measurement for each type of value (for example energy consumption).
I do not use tags at all, because using the design I described above, all I have left to store is the float values and their timestamp index. I like this design because every building is completely separated from the others (as they should be), and if I want to get data from one of them, I just need to connect to the building's database (or bucket) and query it like so :
SELECT * FROM field1,field2 WHERE time>d1 and time<d2
According to this influx article, if I understand correctly (english isn't my first langage), I have a cardinality of:
3 buildings (bucket/database) * 1000 fields (measurement) * 1 (default tag ?) = 3000 cardinality
This doesn't seem to be much, thus I think I misunderstand something.
I have two measurements in my InfluxDB, say, mem_used and mem_ available.
I tried to query across those measurements and do a mathematics with
SELECT mean("mem_used_value") / mean("mem_available_value") FROM
(
SELECT mean("value") AS "mem_used_value",
mean("value") AS "mem_available_value"
FROM "dbname"."autogen"."mem_used",
"dbname"."autogen"."mem_available"
GROUP BY time(1m)
)
GROUP BY time(1m)
The result of the query is very weird, and I was wondering if it’s possible for InfluxDB to perform a mathematics across measurements.
I have did some research about this feature and found the issue 3552 Mathematics across measurements is still opening. However, it was requested three years ago.
Is there any approach to do this? any advice is welcome.
There's no JOINs in Influx QL.
Remember pls: that's NOT a relational DB, the query language may look familiar, but it is a totally different thing.
Here's what you can do.
1) The smartest & legit-iest way: shape your measurement properly.
Currently you didn't: there should not be two measurements, but one, like (in line protocol notation)
memusage,host=yourhost,othertag=something,yetanotertag=anything mem_used=123,mem_available=321 yourtimestamp
2) Use Kapacitor to join your measurements altogether.
There, you can do math right in Kapacitor, or simply write the result of the join back into a single measurement and later do your aggregations in plain InfluxQL.
I am trying to calculate the percentage of values within a threshold.
How would do something like this with InfluxDB?
SELECT
(
SELECT count(*) FROM "durations" WHERE "duration" < 500
)
/
(
SELECT count(*) FROM "durations"
)
That is not possible in plain InfluxQL.
You have to have every data point that belongs to particular dimension (and the range value belongs to IS a sort of a dimension, which is identified by tags) explicitly in your measurement.
See examples of something alike (without aggregation, though) there (pay attention how sample dataset looks like).
Although, what you're asking for could be done in Kapacitor (most likely, with Join and/or Union nodes, I guess).
Is there a way to add a tag to an existing entry in InfluxDB measurement? If not in the existing db measurement, is there a way to insert the records with a new tag into a new influx measurement?
Currently I have a set of measurements that should probably be entries in a single measurement where their current measurement names should be tag-keys in the superset of the merged measurements.
e.g.
show measurements
measurement1
measurement2
measurement3
measurement4
should instead be tags on the data included in each measurement and union to form a single measurement joinedmeasurement with indexed tags measurment1, measurement2,...
It would have to be done manually via queries.
For example, in python using the official client:
from influxdb import InfluxDBClient
client = InfluxDBClient('localhost', database='my_db')
measurement = 'measurement1'
db_data = client.query('select value from %s' % (measurement))
data_to_write = [{'measurement': 'joinedmeasurement',
'tags': ['measurement1'],
'time': d['time'],
'fields': {'value': d['value']},
}
for d in db_data.get_points()]
client.write_points(data_to_write)
And so on for the rest of the measurements. Can run the above in a loop to do all of them in one go.
Consider using named fields though in addition to tags. The above example only uses one field - can have as many as you want.
This improves performance further, though obviously fields are not indexed so do not use them for data that queries are to run on.
I have influxdb and grafana set up. Templating works fine.
What I'm now trying to achieve is to have a FROM clause built from multiple templated values.
I have the following measurements defined in influxdb:
Game1_Draw, Game1_Home, Game1_Away
Game2_Draw, Game2_Home, Game2_Away
.... ... ...
GameN_Draw, GameN_Home, GameN_Away
I want the user to select the game name (Game1, Game2...), and then have three graphs (not queries) with measurements (GameSelected)_Home, (GameSelected)_Away, (GameSelected)_Draw
Getting the game names from templating was easy.
What I need is to generate a query whose FROM clause will depend the game selected and a constant. Something like:
SELECT mean("myvalue") FROM /^$game_Home/ WHERE ....
SELECT mean("myvalue") FROM /^$game_Draw/ WHERE ....
SELECT mean("myvalue") FROM /^$game_Away/ WHERE ....
I cannot make this work. I cannot find anything in the documentation related to aggregate FROM clause.
Encoding information in measurement names is generally an anti-pattern in InfluxDB. The information in the separate measurement suffixes, e.g. _Home, _Draw, _Away, would be much more useful if it was recorded in a tag.
game,odds_type=home myvalue=0.5 1469923200000000000
game,odds_type=draw myvalue=0.6 1469923200000000000
game,odds_type=away myvalue=0.2 1469923200000000000
Then displaying these series on the same graph in Grafana would only require a group by on the odds_type tag.