- Notifications
You must be signed in to change notification settings - Fork476
influxdata/influxdb-java
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This is the official (and community-maintained) Java client library forInfluxDB (1.x), the open source time series database that is part of the TICK (Telegraf, InfluxDB, Chronograf, Kapacitor) stack.
For InfluxDB 3.0 users, this library is succeeded by the lightweightv3 client library.
Note: This library is for use with InfluxDB 1.x and2.x compatibility API. For full supports of InfluxDB 2.x features, please use theinfluxdb-client-java client.
The library artifact is published in Maven central, available athttps://search.maven.org/artifact/org.influxdb/influxdb-java.
Maven dependency:
<dependency> <groupId>org.influxdb</groupId> <artifactId>influxdb-java</artifactId> <version>${influxdbClient.version}</version></dependency>
Gradle dependency:
compile group:'org.influxdb', name:'influxdb-java', version:"${influxdbClientVersion}"
- Querying data using:
- Influx Query Language (InfluxQL), with support forbind parameters (similar toJDBC PreparedStatement parameters);
- it's ownQueryBuilder, as you would do with e.g. EclipseLink or Hibernate;
- Message Pack (requires InfluxDB1.4+);
- Writing data using:
- Data Point (an object provided by this library that represents a ... data point);
- Your own POJO (you need to add a few Java Annotations);
- InfluxDB line protocol (for the braves only);
- UDP, assupported by InfluxDB;
- Support synchronous and asynchronous writes;
- Batch support configurable with
jitterinterval,buffersize andflushinterval.
// Create an object to handle the communication with InfluxDB.// (best practice tip: reuse the 'influxDB' instance when possible)finalStringserverURL ="http://127.0.0.1:8086",username ="root",password ="root";finalInfluxDBinfluxDB =InfluxDBFactory.connect(serverURL,username,password);// Create a database...// https://docs.influxdata.com/influxdb/v1.7/query_language/database_management/StringdatabaseName ="NOAA_water_database";influxDB.query(newQuery("CREATE DATABASE " +databaseName));influxDB.setDatabase(databaseName);// ... and a retention policy, if necessary.// https://docs.influxdata.com/influxdb/v1.7/query_language/database_management/StringretentionPolicyName ="one_day_only";influxDB.query(newQuery("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 .threadFactory(runnable -> {Threadthread =newThread(runnable);thread.setDaemon(true);returnthread; }));// Close it if your application is terminating or you are not using it anymore.Runtime.getRuntime().addShutdownHook(newThread(influxDB::close));// 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-statementQueryResultqueryResult =influxDB.query(newQuery("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]
For version change history have a look atChangeLog.
- Java 1.8+
- Maven 3.5+
- Docker (for Unit testing)
Then you can build influxdb-java with all tests with:
$>export INFLUXDB_IP=127.0.0.1$> mvn clean install
There is a shell script running InfluxDB and Maven from inside a Docker container and you can execute it by running:
$> ./compile-and-test.sh- Manual (main documentation);
- InfluxDB Object Mapper;
- Query Builder;
- FAQ;
- Changelog.
The MIT License (MIT)Copyright (c) 2014 Stefan MajerPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.About
Java client for InfluxDB
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.