Hi guys,
I am evaluating Influx 2.0 and can’t find a good way to extract measurements. Maybe someone can point me in the right direction?
What I am trying to do?:
I want to get all measurements that contain a specific tag.
What did I try?
I tried the example here: Schema Queries in Flux (formerly IFQL) | InfluxData
In my understanding that would give me all measurements as a start. But the example doesn’t seem to work?
I use the java client library with the following code:
queryApi.query("from(bucket:\"opennms\")\n" +
" |> range(start:-24h)\n" +
" |> group(by:[\"_measurement\"])\n" +
" |> distinct(column:\"_measurement\")\n" +
" |> group(none:true)");
The error I get is:
type error 3:6-3:32: function does not take a parameter "by", required params ∅
Is the example broken?
What would be an efficient way to get all measurements (ideally including all their tags) that contain a specific tag?
Here is my nasty workaround:
Any ideas are appreciated!
Thanks
Patrick
bednar
June 22, 2020, 7:22am
2
Hi @Patrick_Schweizer ,
thanks for using java client.
Did you try something like:
import "influxdata/influxdb/v1"
v1.tagValues(
bucket: "opennms",
tag: "_measurement",
predicate: (r) => exists r["tag_key"],
start: duration(v: uint(v: 1970) - uint(v: now()))
)
?
Regards
Hello Bednar,
thank you for your reply!
I am not sure I understand your answer. I tried the example from the documentation:
from(db:"foo")
|> range(start:-24h)
|> group(by:["_measurement"])
|> distinct(column:"_measurement")
|> group(none:true)
This doesn’t seem to work.
I am trying to apply your example but I can’t get it to work either. How do I apply your example?
This is how I start:
InfluxDBClientOptions options = InfluxDBClientOptions.builder()
.bucket(configBucket)
.org(configOrg)
.url(url)
.authenticateToken(token.toCharArray())
.build();
influxDBClient = InfluxDBClientFactory.create(options);
influxDBClient.getQueryApi().query("here goes the query");
I am not sure what String to put for “here goes the query”.
If I put there your example
String query = "bucket: \"opennms\"\n" +
" |> tag: \"_measurement\"\n" +
" |> predicate: (r) => exists r[\"tag_key\"]\n" +
" |> start: duration(v: uint(v: 1970) - uint(v: now()))\n";
I get:
compilation failed: loc 1:7-1:8: invalid statement @1:7-1:8:
I assume I am understanding something wrong?
Thanks for your help!
Patrick
@bednar ,
to make it a bit clearer I extracted the functionality to have a stand alone test for the problem:
https://github.com/patrick-schweizer/influx-playground
You can clone the repo and run the test with maven test
Please take a look at this part:
https://github.com/patrick-schweizer/influx-playground/blob/master/src/test/java/org/opennms/influxdb/GetMeasurementsTest.java#L118
Here you see what I am trying to query. The question is what should be instead in the query
string?
Thanks!