Search in sources :

Example 1 with BatchPoints

use of org.influxdb.dto.BatchPoints in project jmxtrans by jmxtrans.

the class InfluxDbWriterTests method emptyCustomTagsDoesntBotherWrite.

@Test
public void emptyCustomTagsDoesntBotherWrite() throws Exception {
    InfluxDbWriter writer = getTestInfluxDbWriterWithDefaultSettings();
    writer.doWrite(dummyServer(), dummyQuery(), results);
    verify(influxDB).write(messageCaptor.capture());
    BatchPoints batchPoints = messageCaptor.getValue();
    assertThat(batchPoints.getDatabase()).isEqualTo(DATABASE_NAME);
    List<Point> points = batchPoints.getPoints();
    assertThat(points).hasSize(1);
}
Also used : BatchPoints(org.influxdb.dto.BatchPoints) Point(org.influxdb.dto.Point) Test(org.junit.Test)

Example 2 with BatchPoints

use of org.influxdb.dto.BatchPoints in project camel by apache.

the class InfluxDbProducerBatchTest method writeBatchPoints.

@Test
public void writeBatchPoints() throws InterruptedException {
    errorEndpoint.expectedMessageCount(0);
    successEndpoint.expectedMessageCount(1);
    BatchPoints batchPoints = createBatchPoints();
    sendBody("direct:test", batchPoints);
    errorEndpoint.assertIsSatisfied();
    successEndpoint.assertIsSatisfied();
}
Also used : BatchPoints(org.influxdb.dto.BatchPoints) Test(org.junit.Test)

Example 3 with BatchPoints

use of org.influxdb.dto.BatchPoints in project camel by apache.

the class InfluxDbProducerBatchTest method createBatchPoints.

private BatchPoints createBatchPoints() {
    BatchPoints batchPoints = BatchPoints.database("myTestTimeSeries").build();
    Point point1 = Point.measurement("cpu").time(System.currentTimeMillis(), TimeUnit.MILLISECONDS).addField("idle", 90L).addField("user", 9L).addField("system", 1L).build();
    Point point2 = Point.measurement("disk").time(System.currentTimeMillis(), TimeUnit.MILLISECONDS).addField("used", 8L).addField("free", 1L).build();
    batchPoints.point(point1);
    batchPoints.point(point2);
    return batchPoints;
}
Also used : BatchPoints(org.influxdb.dto.BatchPoints) Point(org.influxdb.dto.Point)

Example 4 with BatchPoints

use of org.influxdb.dto.BatchPoints in project oap by oaplatform.

the class InfluxDBReporter method report.

@Override
public synchronized void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) {
    try {
        final long time = DateTimeUtils.currentTimeMillis();
        BatchPoints.Builder pointsBuilder = BatchPoints.database(database);
        BatchPoints points = pointsBuilder.build();
        final SortedMap<String, Point.Builder> builders = new TreeMap<>();
        reportCounters(counters, builders);
        reportMeters(meters, builders);
        reportTimers(timers, builders);
        reportGauges(gauges, builders);
        reportHistograms(histograms, builders);
        builders.values().forEach(b -> points.point(b.time(time, MILLISECONDS).build()));
        logger.trace("reporting {} counters, {} meters, {} timers, {} gauges, {} histograms", counters.size(), meters.size(), timers.size(), gauges.size(), histograms);
        influxDB.write(points);
    } catch (Exception e) {
        Throwable rootCause = Throwables.getRootCause(e);
        if (rootCause instanceof SocketException || rootCause instanceof InterruptedIOException) {
            logger.error(e.getMessage());
        } else {
            logger.error(e.getMessage(), e);
        }
    }
}
Also used : SocketException(java.net.SocketException) InterruptedIOException(java.io.InterruptedIOException) BatchPoints(org.influxdb.dto.BatchPoints) TreeMap(java.util.TreeMap) InterruptedIOException(java.io.InterruptedIOException) SocketException(java.net.SocketException)

Example 5 with BatchPoints

use of org.influxdb.dto.BatchPoints in project xDrip by NightscoutFoundation.

the class InfluxDBUploader method upload.

public boolean upload(List<BgReading> glucoseDataSets, List<Calibration> meterRecords, List<Calibration> calRecords) {
    try {
        BatchPoints batchPoints = BatchPoints.database(dbName).retentionPolicy("autogen").consistency(InfluxDB.ConsistencyLevel.ALL).build();
        for (BgReading record : glucoseDataSets) {
            if (record == null) {
                Log.e(TAG, "InfluxDB glucose record is null");
                continue;
            }
            batchPoints.point(createGlucosePoint(record));
        }
        for (Calibration record : meterRecords) {
            if (record == null) {
                Log.e(TAG, "InfluxDB meter record is null");
                continue;
            }
            batchPoints.point(createMeterPoint(record));
        }
        for (Calibration record : calRecords) {
            if (record == null) {
                Log.e(TAG, "InfluxDB calibration record is null");
                continue;
            }
            if (record.slope == 0d)
                continue;
            batchPoints.point(createCalibrationPoint(record));
        }
        try {
            Log.d(TAG, "Influx url: " + dbUri);
            InfluxDBFactory.connect(dbUri, dbUser, dbPassword, client).enableGzip().write(batchPoints);
            last_error = null;
            return true;
        } catch (java.lang.ExceptionInInitializerError e) {
            Log.e(TAG, "InfluxDB failed: " + e.getCause());
            return false;
        } catch (java.lang.NoClassDefFoundError e) {
            Log.e(TAG, "InfluxDB failed more: " + e);
            return false;
        } catch (IllegalArgumentException e) {
            Log.wtf(TAG, "InfluxDB problem: " + e);
            return false;
        } catch (Exception e) {
            Log.e(TAG, "Write to InfluxDB failed: " + e);
            last_error = e.getMessage();
            return false;
        }
    } catch (Exception e) {
        Log.wtf(TAG, "Exception during initialization: ", e);
        return false;
    }
}
Also used : BatchPoints(org.influxdb.dto.BatchPoints) BgReading(com.eveningoutpost.dexdrip.Models.BgReading) Calibration(com.eveningoutpost.dexdrip.Models.Calibration) IOException(java.io.IOException)

Aggregations

BatchPoints (org.influxdb.dto.BatchPoints)24 Test (org.junit.Test)12 Point (org.influxdb.dto.Point)9 TreeMap (java.util.TreeMap)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 InfluxDB (org.influxdb.InfluxDB)4 Builder (org.influxdb.dto.Point.Builder)3 BgReading (com.eveningoutpost.dexdrip.Models.BgReading)2 Calibration (com.eveningoutpost.dexdrip.Models.Calibration)2 IOException (java.io.IOException)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)1 JsonObject (com.google.gson.JsonObject)1 Result (com.googlecode.jmxtrans.model.Result)1 ResultAttribute (com.googlecode.jmxtrans.model.ResultAttribute)1 InterruptedIOException (java.io.InterruptedIOException)1 SocketException (java.net.SocketException)1 Instant (java.time.Instant)1