Package org.influxdb

Interface InfluxDB

All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
InfluxDBImpl

public interface InfluxDB
extends AutoCloseable
Interface with all available methods to access a InfluxDB database. A full list of currently available interfaces is implemented in: https://github.com/ influxdb/influxdb/blob/master/src/api/http/api.go
Author:
stefan.majer [at] gmail.com
  • Field Details

  • Method Details

    • setLogLevel

      InfluxDB setLogLevel​(InfluxDB.LogLevel logLevel)
      Set the loglevel which is used for REST related actions.
      Parameters:
      logLevel - the loglevel to set.
      Returns:
      the InfluxDB instance to be able to use it in a fluent manner.
    • enableGzip

      InfluxDB enableGzip()
      Enable Gzip compress for http request body.
      Returns:
      the InfluxDB instance to be able to use it in a fluent manner.
    • disableGzip

      InfluxDB disableGzip()
      Disable Gzip compress for http request body.
      Returns:
      the InfluxDB instance to be able to use it in a fluent manner.
    • isGzipEnabled

      boolean isGzipEnabled()
      Returns whether Gzip compress for http request body is enabled.
      Returns:
      true if gzip is enabled.
    • enableBatch

      InfluxDB enableBatch()
      Enable batching of single Point writes to speed up writes significantly. This is the same as calling InfluxDB.enableBatch(BatchOptions.DEFAULTS)
      Returns:
      the InfluxDB instance to be able to use it in a fluent manner.
    • enableBatch

      InfluxDB enableBatch​(BatchOptions batchOptions)
      Enable batching of single Point writes to speed up writes significantly. If either number of points written or flushDuration time limit is reached, a batch write is issued. Note that batch processing needs to be explicitly stopped before the application is shutdown. To do so call disableBatch().
      Parameters:
      batchOptions - the options to set for batching the writes.
      Returns:
      the InfluxDB instance to be able to use it in a fluent manner.
    • enableBatch

      InfluxDB enableBatch​(int actions, int flushDuration, TimeUnit flushDurationTimeUnit)
      Enable batching of single Point writes as enableBatch(int, int, TimeUnit, ThreadFactory)} using default thread factory.
      Parameters:
      actions - the number of actions to collect
      flushDuration - the time to wait at most.
      flushDurationTimeUnit - the TimeUnit for the given flushDuration.
      Returns:
      the InfluxDB instance to be able to use it in a fluent manner.
      See Also:
      enableBatch(int, int, TimeUnit, ThreadFactory)
    • enableBatch

      InfluxDB enableBatch​(int actions, int flushDuration, TimeUnit flushDurationTimeUnit, ThreadFactory threadFactory)
      Enable batching of single Point writes as enableBatch(int, int, TimeUnit, ThreadFactory, BiConsumer) using with a exceptionHandler that does nothing.
      Parameters:
      actions - the number of actions to collect
      flushDuration - the time to wait at most.
      flushDurationTimeUnit - the TimeUnit for the given flushDuration.
      threadFactory - a ThreadFactory instance to be used.
      Returns:
      the InfluxDB instance to be able to use it in a fluent manner.
      See Also:
      enableBatch(int, int, TimeUnit, ThreadFactory, BiConsumer)
    • enableBatch

      InfluxDB enableBatch​(int actions, int flushDuration, TimeUnit flushDurationTimeUnit, ThreadFactory threadFactory, BiConsumer<Iterable<Point>,​Throwable> exceptionHandler, InfluxDB.ConsistencyLevel consistency)
      Enable batching of single Point writes with consistency set for an entire batch flushDurations is reached first, a batch write is issued. Note that batch processing needs to be explicitly stopped before the application is shutdown. To do so call disableBatch(). Default consistency is ONE.
      Parameters:
      actions - the number of actions to collect
      flushDuration - the time to wait at most.
      flushDurationTimeUnit - the TimeUnit for the given flushDuration.
      threadFactory - a ThreadFactory instance to be used.
      exceptionHandler - a consumer function to handle asynchronous errors
      consistency - a consistency setting for batch writes.
      Returns:
      the InfluxDB instance to be able to use it in a fluent manner.
    • enableBatch

      InfluxDB enableBatch​(int actions, int flushDuration, TimeUnit flushDurationTimeUnit, ThreadFactory threadFactory, BiConsumer<Iterable<Point>,​Throwable> exceptionHandler)
      Enable batching of single Point writes to speed up writes significant. If either actions or flushDurations is reached first, a batch write is issued. Note that batch processing needs to be explicitly stopped before the application is shutdown. To do so call disableBatch().
      Parameters:
      actions - the number of actions to collect
      flushDuration - the time to wait at most.
      flushDurationTimeUnit - the TimeUnit for the given flushDuration.
      threadFactory - a ThreadFactory instance to be used.
      exceptionHandler - a consumer function to handle asynchronous errors
      Returns:
      the InfluxDB instance to be able to use it in a fluent manner.
    • disableBatch

      void disableBatch()
      Disable Batching.
    • isBatchEnabled

      boolean isBatchEnabled()
      Returns whether Batching is enabled.
      Returns:
      true if batch is enabled.
    • ping

      Pong ping()
      Ping this influxDB.
      Returns:
      the response of the ping execution.
    • version

      String version()
      Return the version of the connected influxDB Server.
      Returns:
      the version String, otherwise unknown.
    • write

      void write​(Point point)
      Write a single Point to the default database.
      Parameters:
      point - The point to write
    • write

      void write​(String records)
      Write a set of Points to the default database with the string records.
      Parameters:
      records - the points in the correct lineprotocol.
    • write

      void write​(List<String> records)
      Write a set of Points to the default database with the list of string records.
      Parameters:
      records - the List of points in the correct lineprotocol.
    • write

      void write​(String database, String retentionPolicy, Point point)
      Write a single Point to the database.
      Parameters:
      database - the database to write to.
      retentionPolicy - the retentionPolicy to use.
      point - The point to write
    • write

      void write​(int udpPort, Point point)
      Write a single Point to the database through UDP.
      Parameters:
      udpPort - the udpPort to write to.
      point - The point to write.
    • write

      void write​(BatchPoints batchPoints)
      Write a set of Points to the influxdb database with the new (>= 0.9.0rc32) lineprotocol.
      Parameters:
      batchPoints - the points to write in BatchPoints.
      See Also:
      2696
    • writeWithRetry

      void writeWithRetry​(BatchPoints batchPoints)
      Write a set of Points to the influxdb database with the new (>= 0.9.0rc32) lineprotocol. If batching is enabled with appropriate BatchOptions settings (BatchOptions.bufferLimit greater than BatchOptions.actions) This method will try to retry in case of some recoverable errors. Otherwise it just works as write(BatchPoints)
      Parameters:
      batchPoints - the points to write in BatchPoints.
      See Also:
      2696, Retry worth errors
    • write

      void write​(String database, String retentionPolicy, InfluxDB.ConsistencyLevel consistency, String records)
      Write a set of Points to the influxdb database with the string records.
      Parameters:
      database - the name of the database to write
      retentionPolicy - the retentionPolicy to use
      consistency - the ConsistencyLevel to use
      records - the points in the correct lineprotocol.
      See Also:
      2696
    • write

      void write​(String database, String retentionPolicy, InfluxDB.ConsistencyLevel consistency, TimeUnit precision, String records)
      Write a set of Points to the influxdb database with the string records.
      Parameters:
      database - the name of the database to write
      retentionPolicy - the retentionPolicy to use
      consistency - the ConsistencyLevel to use
      precision - the time precision to use
      records - the points in the correct lineprotocol.
      See Also:
      2696
    • write

      void write​(String database, String retentionPolicy, InfluxDB.ConsistencyLevel consistency, List<String> records)
      Write a set of Points to the influxdb database with the list of string records.
      Parameters:
      database - the name of the database to write
      retentionPolicy - the retentionPolicy to use
      consistency - the ConsistencyLevel to use
      records - the List of points in the correct lineprotocol.
      See Also:
      2696
    • write

      void write​(String database, String retentionPolicy, InfluxDB.ConsistencyLevel consistency, TimeUnit precision, List<String> records)
      Write a set of Points to the influxdb database with the list of string records.
      Parameters:
      database - the name of the database to write
      retentionPolicy - the retentionPolicy to use
      consistency - the ConsistencyLevel to use
      precision - the time precision to use
      records - the List of points in the correct lineprotocol.
      See Also:
      2696
    • write

      void write​(int udpPort, String records)
      Write a set of Points to the influxdb database with the string records through UDP.
      Parameters:
      udpPort - the udpPort where influxdb is listening
      records - the content will be encoded by UTF-8 before sent.
    • write

      void write​(int udpPort, List<String> records)
      Write a set of Points to the influxdb database with the list of string records through UDP.
      Parameters:
      udpPort - the udpPort where influxdb is listening
      records - list of record, the content will be encoded by UTF-8 before sent.
    • query

      QueryResult query​(Query query)
      Execute a query against a database.
      Parameters:
      query - the query to execute.
      Returns:
      a List of Series which matched the query.
    • query

      void query​(Query query, Consumer<QueryResult> onSuccess, Consumer<Throwable> onFailure)
      Execute a query against a database. One of the consumers will be executed.
      Parameters:
      query - the query to execute.
      onSuccess - the consumer to invoke when result is received
      onFailure - the consumer to invoke when error is thrown
    • query

      void query​(Query query, int chunkSize, Consumer<QueryResult> onNext)
      Execute a streaming query against a database.
      Parameters:
      query - the query to execute.
      chunkSize - the number of QueryResults to process in one chunk.
      onNext - the consumer to invoke for each received QueryResult
    • query

      void query​(Query query, int chunkSize, BiConsumer<InfluxDB.Cancellable,​QueryResult> onNext)
      Execute a streaming query against a database.
      Parameters:
      query - the query to execute.
      chunkSize - the number of QueryResults to process in one chunk.
      onNext - the consumer to invoke for each received QueryResult; with capability to discontinue a streaming query
    • query

      void query​(Query query, int chunkSize, Consumer<QueryResult> onNext, Runnable onComplete)
      Execute a streaming query against a database.
      Parameters:
      query - the query to execute.
      chunkSize - the number of QueryResults to process in one chunk.
      onNext - the consumer to invoke for each received QueryResult
      onComplete - the onComplete to invoke for successfully end of stream
    • query

      void query​(Query query, int chunkSize, BiConsumer<InfluxDB.Cancellable,​QueryResult> onNext, Runnable onComplete)
      Execute a streaming query against a database.
      Parameters:
      query - the query to execute.
      chunkSize - the number of QueryResults to process in one chunk.
      onNext - the consumer to invoke for each received QueryResult; with capability to discontinue a streaming query
      onComplete - the onComplete to invoke for successfully end of stream
    • query

      void query​(Query query, int chunkSize, BiConsumer<InfluxDB.Cancellable,​QueryResult> onNext, Runnable onComplete, Consumer<Throwable> onFailure)
      Execute a streaming query against a database.
      Parameters:
      query - the query to execute.
      chunkSize - the number of QueryResults to process in one chunk.
      onNext - the consumer to invoke for each received QueryResult; with capability to discontinue a streaming query
      onComplete - the onComplete to invoke for successfully end of stream
      onFailure - the consumer for error handling
    • query

      QueryResult query​(Query query, TimeUnit timeUnit)
      Execute a query against a database.
      Parameters:
      query - the query to execute.
      timeUnit - the time unit of the results.
      Returns:
      a List of Series which matched the query.
    • createDatabase

      @Deprecated void createDatabase​(String name)
      Deprecated.
      (since 2.9, removed in 3.0) Use org.influxdb.InfluxDB.query(Query) to execute a parameterized CREATE DATABASE query.
      Create a new Database.
      Parameters:
      name - the name of the new database.
    • deleteDatabase

      @Deprecated void deleteDatabase​(String name)
      Deprecated.
      (since 2.9, removed in 3.0) Use org.influxdb.InfluxDB.query(Query) to execute a DROP DATABASE query.
      Delete a database.
      Parameters:
      name - the name of the database to delete.
    • describeDatabases

      @Deprecated List<String> describeDatabases()
      Deprecated.
      (since 2.9, removed in 3.0) Use org.influxdb.InfluxDB.query(Query) to execute a SHOW DATABASES query.
      Describe all available databases.
      Returns:
      a List of all Database names.
    • databaseExists

      @Deprecated boolean databaseExists​(String name)
      Deprecated.
      (since 2.9, removed in 3.0) Use org.influxdb.InfluxDB.query(Query) to execute a SHOW DATABASES query and inspect the result.
      Check if a database exists.
      Parameters:
      name - the name of the database to search.
      Returns:
      true if the database exists or false if it doesn't exist
    • flush

      void flush()
      Send any buffered points to InfluxDB. This method is synchronous and will block while all pending points are written.
      Throws:
      IllegalStateException - if batching is not enabled.
    • close

      void close()
      close thread for asynchronous batch write and UDP socket to release resources if need.
      Specified by:
      close in interface AutoCloseable
    • setConsistency

      InfluxDB setConsistency​(InfluxDB.ConsistencyLevel consistency)
      Set the consistency level which is used for writing points.
      Parameters:
      consistency - the consistency level to set.
      Returns:
      the InfluxDB instance to be able to use it in a fluent manner.
    • setDatabase

      InfluxDB setDatabase​(String database)
      Set the database which is used for writing points.
      Parameters:
      database - the database to set.
      Returns:
      the InfluxDB instance to be able to use it in a fluent manner.
    • setRetentionPolicy

      InfluxDB setRetentionPolicy​(String retentionPolicy)
      Set the retention policy which is used for writing points.
      Parameters:
      retentionPolicy - the retention policy to set.
      Returns:
      the InfluxDB instance to be able to use it in a fluent manner.
    • createRetentionPolicy

      @Deprecated void createRetentionPolicy​(String rpName, String database, String duration, String shardDuration, int replicationFactor, boolean isDefault)
      Deprecated.
      (since 2.9, removed in 3.0) Use org.influxdb.InfluxDB.query(Query) to execute a parameterized CREATE RETENTION POLICY query.
      Creates a retentionPolicy.
      Parameters:
      rpName - the name of the retentionPolicy(rp)
      database - the name of the database
      duration - the duration of the rp
      shardDuration - the shardDuration
      replicationFactor - the replicationFactor of the rp
      isDefault - if the rp is the default rp for the database or not
    • createRetentionPolicy

      @Deprecated void createRetentionPolicy​(String rpName, String database, String duration, int replicationFactor, boolean isDefault)
      Deprecated.
      (since 2.9, removed in 3.0) Use org.influxdb.InfluxDB.query(Query) to execute a parameterized CREATE RETENTION POLICY query.
      Creates a retentionPolicy. (optional shardDuration)
      Parameters:
      rpName - the name of the retentionPolicy(rp)
      database - the name of the database
      duration - the duration of the rp
      replicationFactor - the replicationFactor of the rp
      isDefault - if the rp is the default rp for the database or not
    • createRetentionPolicy

      @Deprecated void createRetentionPolicy​(String rpName, String database, String duration, String shardDuration, int replicationFactor)
      Deprecated.
      (since 2.9, removed in 3.0) Use org.influxdb.InfluxDB.query(Query) to execute a parameterized CREATE RETENTION POLICY query.
      Creates a retentionPolicy. (optional shardDuration and isDefault)
      Parameters:
      rpName - the name of the retentionPolicy(rp)
      database - the name of the database
      duration - the duration of the rp
      shardDuration - the shardDuration
      replicationFactor - the replicationFactor of the rp
    • dropRetentionPolicy

      @Deprecated void dropRetentionPolicy​(String rpName, String database)
      Deprecated.
      (since 2.9, removed in 3.0) Use org.influxdb.InfluxDB.query(Query) to execute a DROP RETENTION POLICY query.
      Drops a retentionPolicy in a database.
      Parameters:
      rpName - the name of the retentionPolicy
      database - the name of the database