[rrd4j] Improve timestamp handling (#15107)

* [rrd4j] Improve timestamp handling

Signed-off-by: Jan N. Klug <github@klug.nrw>
pull/14911/head
J-N-K 2023-06-18 21:14:41 +02:00 committed by GitHub
parent 2603f5f355
commit 07e640387c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 4 deletions

View File

@ -205,6 +205,16 @@ public class RRD4jPersistenceService implements QueryablePersistenceService {
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 {
@ -231,8 +241,8 @@ public class RRD4jPersistenceService implements QueryablePersistenceService {
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);
@ -247,8 +257,7 @@ public class RRD4jPersistenceService implements QueryablePersistenceService {
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());
}