Java Code Examples for org.influxdb.InfluxDB#close()

The following examples show how to use org.influxdb.InfluxDB#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OffsetsInfluxDBDaoImpl.java    From Kafka-Insight with Apache License 2.0 5 votes vote down vote up
@Override
    public void insert() {
        InfluxDB influxDB = null;
        try {
            influxDB = InfluxDBFactory.connect(influxDBUrl);
            if (!influxDB.databaseExists(dbName)) {
                influxDB.createDatabase(dbName);
            }
            for (OffsetInfo offsetInfo : offsetInfoList) {
                String group = offsetInfo.getGroup();
                String topic = offsetInfo.getTopic();
                Long logSize = offsetInfo.getLogSize();
                Long offsets = offsetInfo.getCommittedOffset();
                Long lag = offsetInfo.getLag();
                Long timestamp = offsetInfo.getTimestamp();

                BatchPoints batchPoints = BatchPoints
                        .database(dbName)
                        .tag("group", group)
                        .tag("topic", topic)
                        .build();
                Point point = Point.measurement("offsetsConsumer")
                        .time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
//                        .time(timestamp, TimeUnit.MILLISECONDS)
                        .addField("logSize", logSize)
                        .addField("offsets", offsets)
                        .addField("lag", lag)
                        .build();
                batchPoints.point(point);
                influxDB.write(batchPoints);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (influxDB != null) {
                influxDB.close();
            }
        }

    }
 
Example 2
Source File: InfluxDbTelemetryManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void stop(String name) {
    InfluxDB producer = producers.get(name);

    if (producer != null) {
        producer.close();
        producers.remove(name);
    }
}
 
Example 3
Source File: InfluxdbResource.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
void disposeInfluxDbConnection(@Disposes InfluxDB influxDbConnection) {
    influxDbConnection.query(new Query("DROP DATABASE " + DB_NAME, ""));
    influxDbConnection.close();
}
 
Example 4
Source File: MBeansInfluxDBDaoImpl.java    From Kafka-Insight with Apache License 2.0 4 votes vote down vote up
@Override
    public void insert() {

        InfluxDB influxDB = null;
        try {
            influxDB = InfluxDBFactory.connect(influxDBUrl);
            if (!influxDB.databaseExists(dbName)) {
                influxDB.createDatabase(dbName);
            }
            for (MBeanInfo mBeanInfo : mBeanInfoList) {
                String label = mBeanInfo.getLabel();
                String topic = mBeanInfo.getTopic();
                double oneMinute = mBeanInfo.getOneMinute();
                double fiveMinute = mBeanInfo.getFiveMinute();
                double fifteenMinute = mBeanInfo.getFifteenMinute();
                double meanRate = mBeanInfo.getMeanRate();


                BatchPoints batchPoints = BatchPoints
                        .database(dbName)
                        .tag("label", label)
                        .tag("topic", topic)
                        .build();
                Point point = Point.measurement("mBeanMetric")
                        .time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
//                        .time(timestamp, TimeUnit.MILLISECONDS)
                        .addField("oneMinuteRate", oneMinute)
                        .addField("fiveMinuteRate", fiveMinute)
                        .addField("fifteenMinuteRate", fifteenMinute)
                        .addField("meanRate", meanRate)
                        .build();
                batchPoints.point(point);
                influxDB.write(batchPoints);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (influxDB != null) {
                influxDB.close();
            }
        }

    }
 
Example 5
Source File: InfluxDBConnectionLiveTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void whenPointsWrittenPointsExists() throws Exception {

    InfluxDB connection = connectDatabase();

    String dbName = "baeldung";
    connection.createDatabase(dbName);

    // Need a retention policy before we can proceed
    connection.createRetentionPolicy("defaultPolicy", "baeldung", "30d", 1, true);

    // Since we are doing a batch thread, we need to set this as a default
    connection.setRetentionPolicy("defaultPolicy");

    // Enable batch mode
    connection.enableBatch(10, 10, TimeUnit.MILLISECONDS);

    for (int i = 0; i < 10; i++) {
        Point point = Point.measurement("memory")
                .time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
                .addField("name", "server1")
                .addField("free", 4743656L)
                .addField("used", 1015096L)
                .addField("buffer", 1010467L)
                .build();

        connection.write(dbName, "defaultPolicy", point);
        Thread.sleep(2);

    }

    // Unfortunately, the sleep inside the loop doesn't always add enough time to insure
    // that Influx's batch thread flushes all of the writes and this sometimes fails without
    // another brief pause.
    Thread.sleep(10);

    List<com.baeldung.influxdb.MemoryPoint> memoryPointList = getPoints(connection, "Select * from memory", "baeldung");

    assertEquals(10, memoryPointList.size());

    // Turn off batch and clean up
    connection.disableBatch();
    connection.deleteDatabase("baeldung");
    connection.close();

}
 
Example 6
Source File: InfluxDBConnectionLiveTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void whenBatchWrittenBatchExists() {

    InfluxDB connection = connectDatabase();

    String dbName = "baeldung";
    connection.createDatabase(dbName);

    // Need a retention policy before we can proceed
    // Since we are doing batches, we need not set it
    connection.createRetentionPolicy("defaultPolicy", "baeldung", "30d", 1, true);


    BatchPoints batchPoints = BatchPoints
            .database(dbName)
            .retentionPolicy("defaultPolicy")
            .build();
    Point point1 = Point.measurement("memory")
            .time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
            .addField("free", 4743656L)
            .addField("used", 1015096L)
            .addField("buffer", 1010467L)
            .build();
    Point point2 = Point.measurement("memory")
            .time(System.currentTimeMillis() - 100, TimeUnit.MILLISECONDS)
            .addField("free", 4743696L)
            .addField("used", 1016096L)
            .addField("buffer", 1008467L)
            .build();
    batchPoints.point(point1);
    batchPoints.point(point2);
    connection.write(batchPoints);

    List<MemoryPoint> memoryPointList = getPoints(connection, "Select * from memory", "baeldung");

    assertEquals(2, memoryPointList.size());
    assertTrue(4743696L == memoryPointList.get(0).getFree());


    memoryPointList = getPoints(connection, "Select * from memory order by time desc", "baeldung");

    assertEquals(2, memoryPointList.size());
    assertTrue(4743656L == memoryPointList.get(0).getFree());

    // Clean up database
    connection.deleteDatabase("baeldung");
    connection.close();
}