Skip to content

Commit

Permalink
[rrd4j] Improve timestamp handling (openhab#15107)
Browse files Browse the repository at this point in the history
* [rrd4j] Improve timestamp handling

Signed-off-by: Jan N. Klug <[email protected]>
  • Loading branch information
J-N-K authored Jun 18, 2023
1 parent 2603f5f commit 07e6403
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@ private synchronized void internalStore(String name, double value, long now, boo
return;
}

try {
if (now < db.getLastUpdateTime()) {
logger.warn("RRD4J does not support adding past value this={}, last update={}. Discarding {} - {}", now,
db.getLastUpdateTime(), name, value);
return;
}
} catch (IOException ignored) {
// we can ignore that here, we'll fail again later.
}

ConsolFun function = getConsolidationFunction(db);
if (function != ConsolFun.AVERAGE) {
try {
Expand All @@ -231,8 +241,8 @@ private synchronized void internalStore(String name, double value, long now, boo
Sample sample = db.createSample();
sample.setTime(now);
double storeValue = value;
if (db.getDatasource(DATASOURCE_STATE).getType() == DsType.COUNTER) { // counter values must be
// adjusted by stepsize
if (db.getDatasource(DATASOURCE_STATE).getType() == DsType.COUNTER) {
// counter values must be adjusted by stepsize
storeValue = value * db.getRrdDef().getStep();
}
sample.setValue(DATASOURCE_STATE, storeValue);
Expand All @@ -247,8 +257,7 @@ private synchronized void internalStore(String name, double value, long now, boo
job.cancel(true);
scheduledJobs.remove(name);
}
job = scheduler.schedule(() -> internalStore(name, value, now + 1, false), 1, TimeUnit.SECONDS);
scheduledJobs.put(name, job);
internalStore(name, value, now + 1, false);
} else {
logger.warn("Could not persist '{}' to rrd4j database: {}", name, e.getMessage());
}
Expand Down

0 comments on commit 07e6403

Please sign in to comment.