Package io.openems.shared.influxdb
Class InfluxConnector
java.lang.Object
io.openems.shared.influxdb.InfluxConnector
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionInfluxConnector
(String componentId, QueryLanguageConfig queryLanguage, URI url, String org, String apiKey, String bucket, boolean isReadOnly, int poolSize, int maxQueueSize, Consumer<com.influxdb.exceptions.BadRequestException> onWriteError, boolean safeWrite, com.influxdb.client.write.WriteParameters... parameters) The Constructor.InfluxConnector
(String componentId, QueryLanguageConfig queryLanguage, URI url, String org, String apiKey, String bucket, boolean isReadOnly, int poolSize, int maxQueueSize, Consumer<com.influxdb.exceptions.BadRequestException> onWriteError, com.influxdb.client.write.WriteParameters... parameters) -
Method Summary
Modifier and TypeMethodDescriptionstatic com.influxdb.client.write.Point
buildUpdateAvailableSincePoint
(int influxEdgeId, String channel, long availableSinceTimestamp) Builds aPoint
which set theQueryProxy.AVAILABLE_SINCE_COLUMN_NAME
field to the new value.void
Close currentInfluxDBClient
.debugLog()
Returns a debug log of the current influx connection state.protected InfluxConnector.InfluxConnection
Get InfluxDB Connection.boolean
static Integer
parseNumberFromName
(String name) Parses the number of an Edge from its name string.Gets the edges which already have the available since field set.SortedMap<ChannelAddress,
com.google.gson.JsonElement> queryFirstValueBefore
(Optional<Integer> influxEdgeId, ZonedDateTime date, Set<ChannelAddress> channels, String measurement) Queries the first valid values before the given date.SortedMap<ZonedDateTime,
SortedMap<ChannelAddress, com.google.gson.JsonElement>> queryHistoricData
(Optional<Integer> influxEdgeId, ZonedDateTime fromDate, ZonedDateTime toDate, Set<ChannelAddress> channels, Resolution resolution, String measurement) Queries historic data.SortedMap<ChannelAddress,
com.google.gson.JsonElement> queryHistoricEnergy
(Optional<Integer> influxEdgeId, ZonedDateTime fromDate, ZonedDateTime toDate, Set<ChannelAddress> channels, String measurement) Queries historic energy.SortedMap<ZonedDateTime,
SortedMap<ChannelAddress, com.google.gson.JsonElement>> queryHistoricEnergyPerPeriod
(Optional<Integer> influxEdgeId, ZonedDateTime fromDate, ZonedDateTime toDate, Set<ChannelAddress> channels, Resolution resolution, String measurement) Queries historic energy per period.SortedMap<ChannelAddress,
com.google.gson.JsonElement> queryHistoricEnergySingleValueInDay
(Optional<Integer> influxEdgeId, ZonedDateTime fromDate, ZonedDateTime toDate, Set<ChannelAddress> channels, String measurement) Queries historic energy where only one value per day is saved.SortedMap<ChannelAddress,
com.google.gson.JsonElement> queryLastData
(Optional<Integer> influxEdgeId, ChannelAddress channelAddress, String measurement) Queries the last value for given channel address from now to 100 days in the past.SortedMap<ZonedDateTime,
SortedMap<ChannelAddress, com.google.gson.JsonElement>> queryRawHistoricEnergyPerPeriodSinglePerDay
(Optional<Integer> influxEdgeId, ZonedDateTime fromDate, ZonedDateTime toDate, Set<ChannelAddress> channels, Resolution resolution, String measurement) Queries the raw historic values without calculating the difference between two values.void
write
(com.influxdb.client.write.Point point) Actually write the Point to InfluxDB.void
write
(com.influxdb.client.write.Point point, com.influxdb.client.write.WriteParameters writeParameters) Actually write the Point to InfluxDB.
-
Field Details
-
executor
-
queryProxy
-
-
Constructor Details
-
Method Details
-
debugLog
Returns a debug log of the current influx connection state.- Returns:
- the debug log string
-
getInfluxConnection
Get InfluxDB Connection.- Returns:
- the
InfluxDB
connection
-
deactivate
public void deactivate()Close currentInfluxDBClient
. -
queryHistoricEnergy
public SortedMap<ChannelAddress,com.google.gson.JsonElement> queryHistoricEnergy(Optional<Integer> influxEdgeId, ZonedDateTime fromDate, ZonedDateTime toDate, Set<ChannelAddress> channels, String measurement) throws OpenemsError.OpenemsNamedException Queries historic energy.- Parameters:
influxEdgeId
- the unique, numeric Edge-ID; or Empty to query all EdgesfromDate
- the From-DatetoDate
- the To-Datechannels
- the Channels to querymeasurement
- the measurement- Returns:
- a map between ChannelAddress and value
- Throws:
OpenemsException
- on errorOpenemsError.OpenemsNamedException
-
queryHistoricEnergySingleValueInDay
public SortedMap<ChannelAddress,com.google.gson.JsonElement> queryHistoricEnergySingleValueInDay(Optional<Integer> influxEdgeId, ZonedDateTime fromDate, ZonedDateTime toDate, Set<ChannelAddress> channels, String measurement) throws OpenemsError.OpenemsNamedException Queries historic energy where only one value per day is saved.- Parameters:
influxEdgeId
- the unique, numeric Edge-ID; or Empty to query all EdgesfromDate
- the From-DatetoDate
- the To-Datechannels
- the Channels to querymeasurement
- the measurement- Returns:
- a map between ChannelAddress and value
- Throws:
OpenemsException
- on errorOpenemsError.OpenemsNamedException
-
queryHistoricEnergyPerPeriod
public SortedMap<ZonedDateTime,SortedMap<ChannelAddress, queryHistoricEnergyPerPeriodcom.google.gson.JsonElement>> (Optional<Integer> influxEdgeId, ZonedDateTime fromDate, ZonedDateTime toDate, Set<ChannelAddress> channels, Resolution resolution, String measurement) throws OpenemsError.OpenemsNamedException Queries historic energy per period.- Parameters:
influxEdgeId
- the unique, numeric Edge-ID; or Empty to query all EdgesfromDate
- the From-DatetoDate
- the To-Datechannels
- the Channels to queryresolution
- the resolution in secondsmeasurement
- the measurement- Returns:
- the historic data as Map
- Throws:
OpenemsException
- on errorOpenemsError.OpenemsNamedException
-
queryRawHistoricEnergyPerPeriodSinglePerDay
public SortedMap<ZonedDateTime,SortedMap<ChannelAddress, queryRawHistoricEnergyPerPeriodSinglePerDaycom.google.gson.JsonElement>> (Optional<Integer> influxEdgeId, ZonedDateTime fromDate, ZonedDateTime toDate, Set<ChannelAddress> channels, Resolution resolution, String measurement) throws OpenemsError.OpenemsNamedException Queries the raw historic values without calculating the difference between two values.- Parameters:
influxEdgeId
- the unique, numeric Edge-ID; or Empty to query all EdgesfromDate
- the From-DatetoDate
- the To-Datechannels
- the Channels to queryresolution
- the resolution in secondsmeasurement
- the measurement- Returns:
- the historic data as Map
- Throws:
OpenemsException
- on errorOpenemsError.OpenemsNamedException
-
queryHistoricData
public SortedMap<ZonedDateTime,SortedMap<ChannelAddress, queryHistoricDatacom.google.gson.JsonElement>> (Optional<Integer> influxEdgeId, ZonedDateTime fromDate, ZonedDateTime toDate, Set<ChannelAddress> channels, Resolution resolution, String measurement) throws OpenemsError.OpenemsNamedException Queries historic data.- Parameters:
influxEdgeId
- the unique, numeric Edge-ID; or Empty to query all EdgesfromDate
- the From-DatetoDate
- the To-Datechannels
- the Channels to queryresolution
- the resolution in secondsmeasurement
- the measurement- Returns:
- the historic data as Map
- Throws:
OpenemsException
- on errorOpenemsError.OpenemsNamedException
-
queryLastData
public SortedMap<ChannelAddress,com.google.gson.JsonElement> queryLastData(Optional<Integer> influxEdgeId, ChannelAddress channelAddress, String measurement) throws OpenemsError.OpenemsNamedException Queries the last value for given channel address from now to 100 days in the past.- Parameters:
influxEdgeId
- the unique, numeric Edge-ID; or Empty to query all EdgeschannelAddress
- the Channels to querymeasurement
- the measurement- Returns:
- the values mapped to their channel
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
queryFirstValueBefore
public SortedMap<ChannelAddress,com.google.gson.JsonElement> queryFirstValueBefore(Optional<Integer> influxEdgeId, ZonedDateTime date, Set<ChannelAddress> channels, String measurement) throws OpenemsError.OpenemsNamedException Queries the first valid values before the given date.- Parameters:
influxEdgeId
- the unique, numeric Edge-ID; or Empty to query all Edgesdate
- the datechannels
- the Channels to querymeasurement
- the measurement- Returns:
- the values mapped to their channel
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
write
public void write(com.influxdb.client.write.Point point) Actually write the Point to InfluxDB.- Parameters:
point
- the InfluxDB Point
-
write
public void write(com.influxdb.client.write.Point point, com.influxdb.client.write.WriteParameters writeParameters) Actually write the Point to InfluxDB.- Parameters:
point
- the InfluxDB PointwriteParameters
- theWriteParameters
of the written point. TheWriteParameters
had to be passed in the constructor
-
queryAvailableSince
public Map<Integer,Map<String, queryAvailableSince() throws OpenemsError.OpenemsNamedExceptionLong>> Gets the edges which already have the available since field set. Mapped from edgeId to timestamp of availableSince. The timestamp should be in epoch seconds.- Returns:
- the map, where the first key is the edge id the second key is the channel and the value is the available since timestamp in epoch seconds
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
buildUpdateAvailableSincePoint
public static com.influxdb.client.write.Point buildUpdateAvailableSincePoint(int influxEdgeId, String channel, long availableSinceTimestamp) Builds aPoint
which set theQueryProxy.AVAILABLE_SINCE_COLUMN_NAME
field to the new value.- Parameters:
influxEdgeId
- the id of the edgeavailableSinceTimestamp
- the new timestamp in epoch secondschannel
- the channels- Returns:
- the
Point
-
isSafeWrite
public boolean isSafeWrite() -
parseNumberFromName
Parses the number of an Edge from its name string.e.g. translates "edge0" to "0".
- Parameters:
name
- the edge name- Returns:
- the number
- Throws:
OpenemsException
- on error
-