准备测试数据
public static void main(String[] args) {
InfluxDB influxDB = InfluxDBFactory.connect("http://192.168.41.128:8086", "root", "root");
String dbName = "mydb";
influxDB.query(new Query("CREATE DATABASE " + dbName));
long time = 1600327592000L;
int count = 50000;
while (count > 0) {
System.out.println(count);
count--;
time = time + 5000;
BatchPoints batchPoints = BatchPoints
.database(dbName)
.tag("async", "true")
.consistency(InfluxDB.ConsistencyLevel.ALL)
.build();
for (int i = 0; i < 10000; i++) {
Point point1 = Point.measurement("node-" + i)
.time(time, TimeUnit.MILLISECONDS)
.addField("idle", new Random().nextInt(100))
.addField("user", new Random().nextInt(100))
.addField("system", new Random().nextInt(100))
.build();
batchPoints.point(point1);
}
influxDB.write(batchPoints);
}
influxDB.close();
}
使用正则表达式查询测试
目前influxdb
支持在以下场景中使用正则表达式:
field keys
and tag keys
in the SELECT
clause
measurements
in the FROM
clause
tag values
and string field values
in the WHERE
clause.
tag keys
in the GROUP BY
clause
SELECT /<regular_expression_field_key>/ FROM /<regular_expression_measurement>/ WHERE [<tag_key> <operator> /<regular_expression_tag_value>/ | <field_key> <operator> /<regular_expression_field_value>/] GROUP BY /<regular_expression_tag_key>/
SELECT /l/ FROM "h2o_feet" LIMIT 1
SELECT MEAN("degrees") FROM /temperature/
SELECT MEAN(water_level) FROM "h2o_feet" WHERE "location" =~ /[m]/ AND "water_level" > 3
SELECT * FROM "h2o_feet" WHERE "location" !~ /./
SELECT MEAN("water_level") FROM "h2o_feet" WHERE "location" =~ /./
SELECT MEAN("water_level") FROM "h2o_feet" WHERE "location" = 'santa_monica' AND "level description" =~ /between/
SELECT FIRST("index") FROM "h2o_quality" GROUP BY /l/
测试使用正则表达式进行切面查询
SELECT * FROM /node-/ WHERE time='2020-09-18T01:43:27Z'
SELECT * FROM /(node-100)[1-5]/ WHERE time='2020-09-18T01:43:27Z'
参考链接