mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-26 15:21:41 +01:00
[rrd4j] Avoid RrdDb.getRrdDef calls (#17449)
Signed-off-by: Jörg Sautter <joerg.sautter@gmx.net> Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
parent
6dc2b6e478
commit
c555eb9d95
@ -374,8 +374,7 @@ public class RRD4jPersistenceService implements QueryablePersistenceService {
|
|||||||
// only do it if there is not already a value
|
// only do it if there is not already a value
|
||||||
double lastValue = db.getLastDatasourceValue(DATASOURCE_STATE);
|
double lastValue = db.getLastDatasourceValue(DATASOURCE_STATE);
|
||||||
if (!Double.isNaN(lastValue) && lastValue != value) {
|
if (!Double.isNaN(lastValue) && lastValue != value) {
|
||||||
Sample sample = db.createSample();
|
Sample sample = db.createSample(timestamp - 1);
|
||||||
sample.setTime(timestamp - 1);
|
|
||||||
sample.setValue(DATASOURCE_STATE, lastValue);
|
sample.setValue(DATASOURCE_STATE, lastValue);
|
||||||
sample.update();
|
sample.update();
|
||||||
logger.debug("Stored '{}' as value '{}' with timestamp {} in rrd4j database (again)", name,
|
logger.debug("Stored '{}' as value '{}' with timestamp {} in rrd4j database (again)", name,
|
||||||
@ -387,12 +386,11 @@ public class RRD4jPersistenceService implements QueryablePersistenceService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Sample sample = db.createSample();
|
Sample sample = db.createSample(timestamp);
|
||||||
sample.setTime(timestamp);
|
|
||||||
double storeValue = value;
|
double storeValue = value;
|
||||||
if (db.getDatasource(DATASOURCE_STATE).getType() == DsType.COUNTER) {
|
if (db.getDatasource(DATASOURCE_STATE).getType() == DsType.COUNTER) {
|
||||||
// counter values must be adjusted by stepsize
|
// counter values must be adjusted by stepsize
|
||||||
storeValue = value * db.getRrdDef().getStep();
|
storeValue = value * db.getHeader().getStep();
|
||||||
}
|
}
|
||||||
sample.setValue(DATASOURCE_STATE, storeValue);
|
sample.setValue(DATASOURCE_STATE, storeValue);
|
||||||
sample.update();
|
sample.update();
|
||||||
@ -469,7 +467,7 @@ public class RRD4jPersistenceService implements QueryablePersistenceService {
|
|||||||
if (filter.getOrdering() == Ordering.DESCENDING && filter.getPageSize() == 1
|
if (filter.getOrdering() == Ordering.DESCENDING && filter.getPageSize() == 1
|
||||||
&& filter.getPageNumber() == 0) {
|
&& filter.getPageNumber() == 0) {
|
||||||
if (filterEndDate == null || Duration.between(filterEndDate, ZonedDateTime.now()).getSeconds() < db
|
if (filterEndDate == null || Duration.between(filterEndDate, ZonedDateTime.now()).getSeconds() < db
|
||||||
.getRrdDef().getStep()) {
|
.getHeader().getStep()) {
|
||||||
// we are asked only for the most recent value!
|
// we are asked only for the most recent value!
|
||||||
double lastValue = db.getLastDatasourceValue(DATASOURCE_STATE);
|
double lastValue = db.getLastDatasourceValue(DATASOURCE_STATE);
|
||||||
if (!Double.isNaN(lastValue)) {
|
if (!Double.isNaN(lastValue)) {
|
||||||
@ -628,7 +626,7 @@ public class RRD4jPersistenceService implements QueryablePersistenceService {
|
|||||||
|
|
||||||
public ConsolFun getConsolidationFunction(RrdDb db) {
|
public ConsolFun getConsolidationFunction(RrdDb db) {
|
||||||
try {
|
try {
|
||||||
return db.getRrdDef().getArcDefs()[0].getConsolFun();
|
return db.getArchive(0).getConsolFun();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return ConsolFun.MAX;
|
return ConsolFun.MAX;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user