Skip to content

Commit

Permalink
[rrd4j] Avoid RrdDb.getRrdDef calls (#17449)
Browse files Browse the repository at this point in the history
Signed-off-by: Jörg Sautter <[email protected]>
  • Loading branch information
joerg1985 authored Sep 20, 2024
1 parent b77458d commit 52ea5d6
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,7 @@ private synchronized void writePointToDatabase(String name, double value, long t
// only do it if there is not already a value
double lastValue = db.getLastDatasourceValue(DATASOURCE_STATE);
if (!Double.isNaN(lastValue) && lastValue != value) {
Sample sample = db.createSample();
sample.setTime(timestamp - 1);
Sample sample = db.createSample(timestamp - 1);
sample.setValue(DATASOURCE_STATE, lastValue);
sample.update();
logger.debug("Stored '{}' as value '{}' with timestamp {} in rrd4j database (again)", name,
Expand All @@ -387,12 +386,11 @@ private synchronized void writePointToDatabase(String name, double value, long t
}
}
try {
Sample sample = db.createSample();
sample.setTime(timestamp);
Sample sample = db.createSample(timestamp);
double storeValue = value;
if (db.getDatasource(DATASOURCE_STATE).getType() == DsType.COUNTER) {
// counter values must be adjusted by stepsize
storeValue = value * db.getRrdDef().getStep();
storeValue = value * db.getHeader().getStep();
}
sample.setValue(DATASOURCE_STATE, storeValue);
sample.update();
Expand Down Expand Up @@ -469,7 +467,7 @@ public Iterable<HistoricItem> query(FilterCriteria filter) {
if (filter.getOrdering() == Ordering.DESCENDING && filter.getPageSize() == 1
&& filter.getPageNumber() == 0) {
if (filterEndDate == null || Duration.between(filterEndDate, ZonedDateTime.now()).getSeconds() < db
.getRrdDef().getStep()) {
.getHeader().getStep()) {
// we are asked only for the most recent value!
double lastValue = db.getLastDatasourceValue(DATASOURCE_STATE);
if (!Double.isNaN(lastValue)) {
Expand Down Expand Up @@ -628,7 +626,7 @@ public Set<PersistenceItemInfo> getItemInfo() {

public ConsolFun getConsolidationFunction(RrdDb db) {
try {
return db.getRrdDef().getArcDefs()[0].getConsolFun();
return db.getArchive(0).getConsolFun();
} catch (IOException e) {
return ConsolFun.MAX;
}
Expand Down

0 comments on commit 52ea5d6

Please sign in to comment.