Search in sources :

Example 11 with BatchPoints

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

the class InfluxDbWriterTests method writeConsistencyLevelsAreAppliedToBatchPointsBeingWritten.

@Test
public void writeConsistencyLevelsAreAppliedToBatchPointsBeingWritten() throws Exception {
    for (ConsistencyLevel consistencyLevel : ConsistencyLevel.values()) {
        BatchPoints batchPoints = writeAtLeastOnceToInfluxDb(getTestInfluxDbWriterWithWriteConsistency(consistencyLevel));
        assertThat(batchPoints.getConsistency()).isEqualTo(consistencyLevel);
    }
}
Also used : ConsistencyLevel(org.influxdb.InfluxDB.ConsistencyLevel) BatchPoints(org.influxdb.dto.BatchPoints) Test(org.junit.Test)

Example 12 with BatchPoints

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

the class InfluxDbWriterTests method pointsAreWrittenToInfluxDb.

@Test
public void pointsAreWrittenToInfluxDb() throws Exception {
    BatchPoints batchPoints = writeToInfluxDb(getTestInfluxDbWriterWithDefaultSettings());
    // The database name is present
    assertThat(batchPoints.getDatabase()).isEqualTo(DATABASE_NAME);
    // Point only exposes its state via a line protocol so we have to
    // make assertions against this.
    // Format is:
    // measurement,<comma separated key=val tags>" " <comma separated
    // key=val fields>" "time
    Map<String, String> expectedTags = new TreeMap<String, String>();
    expectedTags.put(ResultAttributes.ATTRIBUTE_NAME.getName(), result.getAttributeName());
    expectedTags.put(ResultAttributes.CLASS_NAME.getName(), result.getClassName());
    expectedTags.put(ResultAttributes.OBJ_DOMAIN.getName(), result.getObjDomain());
    expectedTags.put(TAG_HOSTNAME, HOST);
    String lineProtocol = buildLineProtocol(result.getKeyAlias(), expectedTags);
    List<Point> points = batchPoints.getPoints();
    assertThat(points).hasSize(1);
    Point point = points.get(0);
    assertThat(point.lineProtocol()).startsWith(lineProtocol);
}
Also used : BatchPoints(org.influxdb.dto.BatchPoints) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Point(org.influxdb.dto.Point) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 13 with BatchPoints

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

the class InfluxDbWriterTests method jmxPortIsReportedAsTag.

@Test
public void jmxPortIsReportedAsTag() throws Exception {
    BatchPoints batchPoints = writeToInfluxDb(getTestInfluxDbWriterWithReportJmxPortAsTag());
    verifyJMXPortOnlyInToken(batchPoints.getPoints().get(0).lineProtocol(), 0);
}
Also used : BatchPoints(org.influxdb.dto.BatchPoints) Test(org.junit.Test)

Example 14 with BatchPoints

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

the class InfluxDbWriterTests method valueString.

@Test
public void valueString() throws Exception {
    InfluxDbWriter writer = getTestInfluxDbWriterWithStringValue();
    writer.doWrite(dummyServer(), dummyQuery(), resultsStr);
    verify(influxDB).write(messageCaptor.capture());
    BatchPoints batchPoints = messageCaptor.getValue();
    assertThat(batchPoints.getDatabase()).isEqualTo(DATABASE_NAME);
    List<Point> points = batchPoints.getPoints();
    assertThat(points).hasSize(1);
    Point point = points.get(0);
    assertThat(point.lineProtocol()).contains("key=\"hello\"");
}
Also used : BatchPoints(org.influxdb.dto.BatchPoints) Point(org.influxdb.dto.Point) Test(org.junit.Test)

Example 15 with BatchPoints

use of org.influxdb.dto.BatchPoints in project weicoder by wdcode.

the class Influx method insertMany.

/**
 * 批量插入
 *
 * @param measurement    表
 * @param tagsfieldsList 标签字段列表
 */
public void insertMany(String measurement, List<Map<Map<String, String>, Map<String, Object>>> tagsfieldsList) {
    // 声明BatchPoints
    BatchPoints batchPoints = BatchPoints.database(database).consistency(ConsistencyLevel.ONE).precision(TimeUnit.MILLISECONDS).build();
    // 设置标签字段.
    tagsfieldsList.forEach(tf -> tf.forEach((k, v) -> batchPoints.point(Point.measurement(measurement).tag(k).fields(v).build())));
    // 写数据
    db.write(batchPoints);
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) ConsistencyLevel(org.influxdb.InfluxDB.ConsistencyLevel) List(java.util.List) BatchPoints(org.influxdb.dto.BatchPoints) Query(org.influxdb.dto.Query) Map(java.util.Map) InfluxDBFactory(org.influxdb.InfluxDBFactory) Point(org.influxdb.dto.Point) InfluxDB(org.influxdb.InfluxDB) QueryResult(org.influxdb.dto.QueryResult) BatchPoints(org.influxdb.dto.BatchPoints)

Aggregations

BatchPoints (org.influxdb.dto.BatchPoints)26 Test (org.junit.Test)12 Point (org.influxdb.dto.Point)11 Map (java.util.Map)6 HashMap (java.util.HashMap)5 TreeMap (java.util.TreeMap)5 InfluxDB (org.influxdb.InfluxDB)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 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 ConsistencyLevel (org.influxdb.InfluxDB.ConsistencyLevel)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