Search in sources :

Example 1 with InfluxDB

use of org.influxdb.InfluxDB in project camel by apache.

the class MockedInfluxDbConfiguration method influxDbBean.

@Bean
public InfluxDB influxDbBean() throws UnknownHostException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Creating new instance of a mocked influx db connection");
    }
    InfluxDB mockedDbConnection = mock(InfluxDB.class);
    //InfluxDB mockedDbConnection = InfluxDBFactory.connect("http://127.0.0.1:8086", "root", "root");
    assertNotNull(mockedDbConnection);
    return mockedDbConnection;
}
Also used : InfluxDB(org.influxdb.InfluxDB) Bean(org.springframework.context.annotation.Bean)

Example 2 with InfluxDB

use of org.influxdb.InfluxDB in project tutorials by eugenp.

the class InfluxDBConnectionLiveTest method whenDatabaseCreatedDatabaseChecksOk.

@Test
public void whenDatabaseCreatedDatabaseChecksOk() {
    InfluxDB connection = connectDatabase();
    // Create "baeldung" and check for it
    connection.createDatabase("baeldung");
    assertTrue(connection.databaseExists("baeldung"));
    // Verify that nonsense databases are not there
    assertFalse(connection.databaseExists("foobar"));
    // Drop "baeldung" and check again
    connection.deleteDatabase("baeldung");
    assertFalse(connection.databaseExists("baeldung"));
}
Also used : InfluxDB(org.influxdb.InfluxDB) Test(org.junit.Test)

Example 3 with InfluxDB

use of org.influxdb.InfluxDB in project tutorials by eugenp.

the class InfluxDBConnectionLiveTest method whenCorrectInfoDatabaseConnects.

@Test
public void whenCorrectInfoDatabaseConnects() {
    InfluxDB connection = connectDatabase();
    assertTrue(pingServer(connection));
}
Also used : InfluxDB(org.influxdb.InfluxDB) Test(org.junit.Test)

Example 4 with InfluxDB

use of org.influxdb.InfluxDB in project openems by OpenEMS.

the class InfluxdbQueryWrapper method query.

// private final static Logger log = LoggerFactory.getLogger(InfluxdbQueryWrapper.class);
public static JsonObject query(Optional<InfluxDB> _influxdb, Optional<Integer> fems, ZonedDateTime fromDate, ZonedDateTime toDate, JsonObject channels, int resolution, String dbName) throws OpenemsException {
    // Prepare return object
    JsonObject jQueryreply = new JsonObject();
    jQueryreply.addProperty("mode", "history");
    JsonArray jData = new JsonArray();
    JsonObject jkWh = new JsonObject();
    // Prepare date
    toDate = toDate.plusDays(1).truncatedTo(ChronoUnit.DAYS);
    ZonedDateTime nowDate = ZonedDateTime.now();
    if (nowDate.isBefore(toDate)) {
        toDate = nowDate;
    }
    if (fromDate.isAfter(toDate)) {
        fromDate = toDate;
    }
    if (_influxdb.isPresent()) {
        InfluxDB influxdb = _influxdb.get();
        jData = InfluxdbQueryWrapper.queryData(influxdb, fems, fromDate, toDate, channels, resolution, dbName);
    } else {
        jData = new JsonArray();
        jkWh = new JsonObject();
    }
    jQueryreply.add("data", jData);
    jQueryreply.add("kWh", jkWh);
    return jQueryreply;
}
Also used : JsonArray(com.google.gson.JsonArray) ZonedDateTime(java.time.ZonedDateTime) InfluxDB(org.influxdb.InfluxDB) JsonObject(com.google.gson.JsonObject)

Example 5 with InfluxDB

use of org.influxdb.InfluxDB in project openems by OpenEMS.

the class Influx method writeData.

private void writeData(int influxId, TreeBasedTable<Long, String, Object> data) throws OpenemsException {
    InfluxDB influxDB = this.getInfluxDbConnection();
    BatchPoints batchPoints = // 
    BatchPoints.database(database).tag("fems", // 
    String.valueOf(influxId)).build();
    for (Entry<Long, Map<String, Object>> entry : data.rowMap().entrySet()) {
        Long timestamp = entry.getKey();
        Builder builder = // this builds an InfluxDB record ("point") for a
        Point.measurement(this.measurement).time(timestamp, TimeUnit.MILLISECONDS).fields(entry.getValue());
        batchPoints.point(builder.build());
    }
    // write to DB
    influxDB.write(batchPoints);
}
Also used : BatchPoints(org.influxdb.dto.BatchPoints) InfluxDB(org.influxdb.InfluxDB) Builder(org.influxdb.dto.Point.Builder) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Aggregations

InfluxDB (org.influxdb.InfluxDB)26 Test (org.junit.Test)7 Query (org.influxdb.dto.Query)5 BatchPoints (org.influxdb.dto.BatchPoints)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Builder (org.influxdb.dto.Point.Builder)3 Test (org.junit.jupiter.api.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 JsonObject (com.google.gson.JsonObject)2 List (java.util.List)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 PipelineResult (org.apache.beam.sdk.PipelineResult)2 QueryResult (org.influxdb.dto.QueryResult)2 Series (org.influxdb.dto.QueryResult.Series)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Health (org.springframework.boot.actuate.health.Health)2 Bean (org.springframework.context.annotation.Bean)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1