Search in sources :

Example 11 with Point

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

the class InfluxDbWriterTests method customTagsAreWrittenToDb.

@Test
public void customTagsAreWrittenToDb() throws Exception {
    ImmutableMap<String, String> tags = ImmutableMap.of("customTag", "customValue");
    InfluxDbWriter writer = getTestInfluxDbWriterWithCustomTags(tags);
    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);
    Point point = points.get(0);
    assertThat(point.lineProtocol()).contains("customTag=customValue");
}
Also used : BatchPoints(org.influxdb.dto.BatchPoints) Matchers.anyString(org.mockito.Matchers.anyString) Point(org.influxdb.dto.Point) Test(org.junit.Test)

Example 12 with Point

use of org.influxdb.dto.Point in project openhab1-addons by openhab.

the class InfluxDBPersistenceService method store.

/**
     * {@inheritDoc}
     */
@Override
public void store(Item item, String alias) {
    if (item.getState() instanceof UnDefType) {
        return;
    }
    if (!isProperlyConfigured) {
        logger.warn("Configuration for influxdb not yet loaded or broken.");
        return;
    }
    if (!isConnected()) {
        logger.warn("InfluxDB is not yet connected");
        return;
    }
    String realName = item.getName();
    String name = (alias != null) ? alias : realName;
    State state = null;
    if (item.getAcceptedCommandTypes().contains(HSBType.class)) {
        state = item.getStateAs(HSBType.class);
        logger.trace("Tried to get item as {}, state is {}", HSBType.class, state.toString());
    } else if (item.getAcceptedDataTypes().contains(PercentType.class)) {
        state = item.getStateAs(PercentType.class);
        logger.trace("Tried to get item as {}, state is {}", PercentType.class, state.toString());
    } else {
        // All other items should return the best format by default
        state = item.getState();
        logger.trace("Tried to get item from item class {}, state is {}", item.getClass(), state.toString());
    }
    Object value = stateToObject(state);
    logger.trace("storing {} in influxdb value {}, {}", name, value, item);
    Point point = Point.measurement(name).field(VALUE_COLUMN_NAME, value).time(System.currentTimeMillis(), timeUnit).build();
    try {
        influxDB.write(dbName, retentionPolicy, point);
    } catch (RuntimeException e) {
        logger.error("storing failed with exception for item: {}", name);
        handleDatabaseException(e);
    }
}
Also used : UnDefType(org.openhab.core.types.UnDefType) State(org.openhab.core.types.State) PercentType(org.openhab.core.library.types.PercentType) Point(org.influxdb.dto.Point) HSBType(org.openhab.core.library.types.HSBType)

Example 13 with Point

use of org.influxdb.dto.Point in project cas by apereo.

the class InfluxDbCasEventRepository method save.

@Override
public void save(final CasEvent event) {
    final Point.Builder builder = Point.measurement(MEASUREMENT);
    ReflectionUtils.doWithFields(CasEvent.class, field -> {
        field.setAccessible(true);
        if (field.getType().equals(Map.class)) {
            builder.fields((Map) field.get(event));
        } else {
            builder.field(field.getName(), field.get(event));
        }
    });
    final Point point = builder.time(System.currentTimeMillis(), TimeUnit.MILLISECONDS).build();
    influxDbConnectionFactory.write(point);
}
Also used : Point(org.influxdb.dto.Point)

Example 14 with Point

use of org.influxdb.dto.Point in project cas by apereo.

the class InfluxDbConnectionFactoryTests method verifyWritePoint.

@Test
public void verifyWritePoint() {
    final Point p = Point.measurement("events").time(System.currentTimeMillis(), TimeUnit.MILLISECONDS).addField("hostname", "cas.example.org").build();
    factory.write(p, CAS_EVENTS_DATABASE);
    final QueryResult result = factory.query("*", "events", CAS_EVENTS_DATABASE);
    final InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
    final List<InfluxEvent> resultEvents = resultMapper.toPOJO(result, InfluxEvent.class);
    assertNotNull(resultEvents);
    assertEquals(1, resultEvents.size());
    assertEquals("cas.example.org", resultEvents.iterator().next().hostname);
}
Also used : QueryResult(org.influxdb.dto.QueryResult) InfluxDBResultMapper(org.influxdb.impl.InfluxDBResultMapper) Point(org.influxdb.dto.Point) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Point (org.influxdb.dto.Point)14 Test (org.junit.Test)8 BatchPoints (org.influxdb.dto.BatchPoints)6 HashMap (java.util.HashMap)5 TreeMap (java.util.TreeMap)2 Matchers.anyString (org.mockito.Matchers.anyString)2 JsonTypeInfo (com.fasterxml.jackson.annotation.JsonTypeInfo)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)1 Result (com.googlecode.jmxtrans.model.Result)1 Serializable (java.io.Serializable)1 Date (java.util.Date)1 Map (java.util.Map)1 TimeUnit (java.util.concurrent.TimeUnit)1 Getter (lombok.Getter)1 ToString (lombok.ToString)1 Slf4j (lombok.extern.slf4j.Slf4j)1 InvalidPayloadException (org.apache.camel.InvalidPayloadException)1 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)1 MetricsProperties (org.apereo.cas.configuration.model.core.metrics.MetricsProperties)1