Java Code Examples for org.influxdb.InfluxDB#enableBatch()
The following examples show how to use
org.influxdb.InfluxDB#enableBatch() .
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: InfluxLogger.java From Okra with Apache License 2.0 | 6 votes |
public static void main(String[] args) { String dbName = "centos_test_db"; InfluxDB influxDB = InfluxDBFactory.connect("http://192.168.0.71:18086", "influxdbUser", "influxdbPsw"); // Flush every 2000 Points, at least every 100ms influxDB.enableBatch(2000, 100, TimeUnit.MILLISECONDS); for (int i = 0; i < 50; i++) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } Point point2 = Point.measurement("disk") .time(System.currentTimeMillis(), TimeUnit.MILLISECONDS) .addField("used", Math.random() * 80L) .addField("free", Math.random() * 30L) .build(); influxDB.write(dbName, "autogen", point2); } System.out.println(); }
Example 2
Source File: InfluxDbSourceTest.java From hazelcast-jet-contrib with Apache License 2.0 | 5 votes |
private void fillData(InfluxDB influxDB) { influxDB.enableBatch(500, 100, TimeUnit.MICROSECONDS); for (int value = 0; value < VALUE_COUNT; value++) { influxDB.write(DATABASE_NAME, "autogen", Point.measurement("test") .time(value, TimeUnit.MILLISECONDS) .addField("value", value) .build() ); } }
Example 3
Source File: InfluxDataMigrator.java From RuuviCollector with MIT License | 5 votes |
private InfluxDB createInfluxDB() { InfluxDB influxDB = InfluxDBFactory.connect(Config.getInfluxUrl(), Config.getInfluxUser(), Config.getInfluxPassword()); influxDB.setDatabase(Config.getInfluxDatabase()); influxDB.enableGzip(); influxDB.enableBatch(BATCH_SIZE, 100, TimeUnit.MILLISECONDS); return influxDB; }
Example 4
Source File: StatsCollector.java From cloudstack with Apache License 2.0 | 5 votes |
/** * Writes batches of InfluxDB database points into a given database. */ protected void writeBatches(InfluxDB influxDbConnection, String dbName, List<Point> points) { BatchPoints batchPoints = BatchPoints.database(dbName).build(); influxDbConnection.enableBatch(BatchOptions.DEFAULTS); for (Point point : points) { batchPoints.point(point); } influxDbConnection.write(batchPoints); }
Example 5
Source File: InfluxDBConnectionLiveTest.java From tutorials with MIT License | 4 votes |
@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(); }