-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: yangzl <[email protected]>
- Loading branch information
Showing
9 changed files
with
143 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
时序数据库:Time Series Database (TSDB) | ||
https://github.com/influxdata/influxdb | ||
https://docs.influxdata.com/influxdb/v1.7/introduction/getting-started/ | ||
https://docs.influxdata.com/influxdb/v1.7/administration/config | ||
|
||
Java客户端 | ||
https://github.com/influxdata/influxdb-java | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
quickstart-influxdb/src/test/java/org/quickstart/influxdb/example/InfluxDBTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package org.quickstart.influxdb.example; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
import org.influxdb.BatchOptions; | ||
import org.influxdb.InfluxDB; | ||
import org.influxdb.InfluxDBFactory; | ||
import org.influxdb.dto.Point; | ||
import org.influxdb.dto.Query; | ||
import org.influxdb.dto.QueryResult; | ||
|
||
/** | ||
* @author [email protected] | ||
* @description TODO | ||
* @createTime 2020/6/11 22:48 | ||
*/ | ||
public class InfluxDBTest { | ||
|
||
public static void main(String[] args) throws InterruptedException { | ||
// Create an object to handle the communication with InfluxDB. | ||
// (best practice tip: reuse the 'influxDB' instance when possible) | ||
final String serverURL = "http://127.0.0.1:8086", username = "root", password = "root"; | ||
final InfluxDB influxDB = InfluxDBFactory.connect(serverURL, username, password); | ||
|
||
// Create a database... | ||
// https://docs.influxdata.com/influxdb/v1.7/query_language/database_management/ | ||
String databaseName = "NOAA_water_database"; | ||
influxDB.query(new Query("CREATE DATABASE " + databaseName)); | ||
influxDB.setDatabase(databaseName); | ||
|
||
// ... and a retention policy, if necessary. | ||
// https://docs.influxdata.com/influxdb/v1.7/query_language/database_management/ | ||
String retentionPolicyName = "one_day_only"; | ||
influxDB.query(new Query("CREATE RETENTION POLICY " + retentionPolicyName | ||
+ " ON " + databaseName + " DURATION 1d REPLICATION 1 DEFAULT")); | ||
influxDB.setRetentionPolicy(retentionPolicyName); | ||
|
||
// Enable batch writes to get better performance. | ||
influxDB.enableBatch(BatchOptions.DEFAULTS); | ||
|
||
// Write points to InfluxDB. | ||
influxDB.write(Point.measurement("h2o_feet") | ||
.time(System.currentTimeMillis(), TimeUnit.MILLISECONDS) | ||
.tag("location", "santa_monica") | ||
.addField("level description", "below 3 feet") | ||
.addField("water_level", 2.064d) | ||
.build()); | ||
|
||
influxDB.write(Point.measurement("h2o_feet") | ||
.time(System.currentTimeMillis(), TimeUnit.MILLISECONDS) | ||
.tag("location", "coyote_creek") | ||
.addField("level description", "between 6 and 9 feet") | ||
.addField("water_level", 8.12d) | ||
.build()); | ||
|
||
// Wait a few seconds in order to let the InfluxDB client | ||
// write your points asynchronously (note: you can adjust the | ||
// internal time interval if you need via 'enableBatch' call). | ||
Thread.sleep(5_000L); | ||
|
||
// Query your data using InfluxQL. | ||
// https://docs.influxdata.com/influxdb/v1.7/query_language/data_exploration/#the-basic-select-statement | ||
QueryResult queryResult = influxDB.query(new Query("SELECT * FROM h2o_feet")); | ||
|
||
System.out.println(queryResult); | ||
// It will print something like: | ||
// QueryResult [results=[Result [series=[Series [name=h2o_feet, tags=null, | ||
// columns=[time, level description, location, water_level], | ||
// values=[ | ||
// [2020-03-22T20:50:12.929Z, below 3 feet, santa_monica, 2.064], | ||
// [2020-03-22T20:50:12.929Z, between 6 and 9 feet, coyote_creek, 8.12] | ||
// ]]], error=null]], error=null] | ||
|
||
// Close it if your application is terminating or you are not using it anymore. | ||
influxDB.close(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.