Search in sources :

Example 1 with Point

use of org.influxdb.dto.Point 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 2 with Point

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

the class CamelInfluxDbConverterTest method doesNotAddCamelHeaders.

@Test
public void doesNotAddCamelHeaders() {
    Map<String, Object> pointInMapFormat = new HashMap<>();
    pointInMapFormat.put(InfluxDbConstants.MEASUREMENT_NAME, "testCPU");
    double value = 99.999999d;
    pointInMapFormat.put("busy", value);
    Point p = CamelInfluxDbConverters.fromMapToPoint(pointInMapFormat);
    assertNotNull(p);
    String line = p.lineProtocol();
    assertNotNull(line);
    LOG.debug("doesNotAddCamelHeaders generated: \"{}\"", line);
    assertTrue(!line.contains(InfluxDbConstants.MEASUREMENT_NAME));
}
Also used : HashMap(java.util.HashMap) Point(org.influxdb.dto.Point) Test(org.junit.Test)

Example 3 with Point

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

the class CamelInfluxDbConverterTest method canAddDouble.

@Test
public void canAddDouble() {
    Map<String, Object> pointInMapFormat = new HashMap<>();
    pointInMapFormat.put(InfluxDbConstants.MEASUREMENT_NAME, "testCPU");
    double value = 99.999999d;
    pointInMapFormat.put("busy", value);
    Point p = CamelInfluxDbConverters.fromMapToPoint(pointInMapFormat);
    assertNotNull(p);
    String line = p.lineProtocol();
    assertNotNull(line);
    LOG.debug("Doublecommand generated: \"{}\"", line);
    assertTrue(line.contains("busy=99.999999"));
}
Also used : HashMap(java.util.HashMap) Point(org.influxdb.dto.Point) Test(org.junit.Test)

Example 4 with Point

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

the class InfluxDbWriterTests method pointsAreWrittenToInfluxDb.

@Test
public void pointsAreWrittenToInfluxDb() 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);
    // 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>
    Map<String, String> expectedTags = new TreeMap<String, String>();
    expectedTags.put(enumValueToAttribute(ResultAttribute.ATTRIBUTE_NAME), result.getAttributeName());
    expectedTags.put(enumValueToAttribute(ResultAttribute.CLASS_NAME), result.getClassName());
    expectedTags.put(enumValueToAttribute(ResultAttribute.OBJ_DOMAIN), result.getObjDomain());
    expectedTags.put(enumValueToAttribute(ResultAttribute.TYPE_NAME), result.getTypeName());
    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) Matchers.anyString(org.mockito.Matchers.anyString) Point(org.influxdb.dto.Point) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 5 with Point

use of org.influxdb.dto.Point 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)

Aggregations

Point (org.influxdb.dto.Point)11 Test (org.junit.Test)7 BatchPoints (org.influxdb.dto.BatchPoints)6 HashMap (java.util.HashMap)5 TreeMap (java.util.TreeMap)2 Matchers.anyString (org.mockito.Matchers.anyString)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)1 Result (com.googlecode.jmxtrans.model.Result)1 Map (java.util.Map)1 InvalidPayloadException (org.apache.camel.InvalidPayloadException)1 HSBType (org.openhab.core.library.types.HSBType)1 PercentType (org.openhab.core.library.types.PercentType)1 State (org.openhab.core.types.State)1 UnDefType (org.openhab.core.types.UnDefType)1