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;
}
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"));
}
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));
}
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;
}
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);
}
Aggregations