Skip to content

Commit

Permalink
[rrd4j] use a more fine granular default configuration for persistence (
Browse files Browse the repository at this point in the history
#7234)

* use a more fine granular default configuration for persistence
* use AVERAGE for quantifiable number items and LAST for others

Signed-off-by: Kai Kreuzer <[email protected]>
  • Loading branch information
kaikreuzer authored Apr 4, 2020
1 parent 7e9c64e commit 20ac8df
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@
QueryablePersistenceService.class }, configurationPid = "org.openhab.rrd4j")
public class RRD4jPersistenceService implements QueryablePersistenceService {

private static final String DEFAULT_OTHER = "default_other";
private static final String DEFAULT_NUMERIC = "default_numeric";
private static final String DEFAULT_QUANTIFIABLE = "default_quantifiable";

private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(3,
new NamedThreadFactory("RRD4j"));

Expand Down Expand Up @@ -285,15 +289,20 @@ public Set<PersistenceItemInfo> getItemInfo() {
try {
Item item = itemRegistry.getItem(itemName);
if (item instanceof NumberItem) {
useRdc = rrdDefs.get("default_numeric");
NumberItem numberItem = (NumberItem) item;
if (numberItem.getDimension() != null) {
useRdc = rrdDefs.get(DEFAULT_QUANTIFIABLE);
} else {
useRdc = rrdDefs.get(DEFAULT_NUMERIC);
}
} else {
useRdc = rrdDefs.get("default_other");
useRdc = rrdDefs.get(DEFAULT_OTHER);
}
} catch (ItemNotFoundException e) {
logger.debug("Could not find item '{}' in registry", itemName);
}
} else {
useRdc = rrdDefs.get("default_other");
useRdc = rrdDefs.get(DEFAULT_OTHER);
}
}
return useRdc;
Expand Down Expand Up @@ -350,17 +359,42 @@ private static String getUserPersistenceDataFolder() {
*/
public void activate(final Map<String, Object> config) {
// add default configurations
RrdDefConfig defaultNumeric = new RrdDefConfig("default_numeric");
defaultNumeric.setDef("GAUGE,60,U,U,60");
defaultNumeric.addArchives(
"AVERAGE,0.5,1,480:AVERAGE,0.5,4,360:AVERAGE,0.5,14,644:AVERAGE,0.5,60,720:AVERAGE,0.5,720,730:AVERAGE,0.5,10080,520");
rrdDefs.put("default_numeric", defaultNumeric);

RrdDefConfig defaultOther = new RrdDefConfig("default_other");
defaultOther.setDef("GAUGE,3600,U,U,1");
defaultOther.addArchives(
"MAX,.999,1,3600:MAX,.999,10,1440:MAX,.999,60,1440:MAX,.999,900,2880:MAX,.999,21600,1460:MAX,.999,86400,3650");
rrdDefs.put("default_other", defaultOther);

RrdDefConfig defaultNumeric = new RrdDefConfig(DEFAULT_NUMERIC);
// use 10 seconds as a step size for numeric values and allow a 10 minute silence between updates
defaultNumeric.setDef("GAUGE,600,U,U,10");
// define 5 different boxes:
// 1. granularity of 10s for the last hour
// 2. granularity of 1m for the last week
// 3. granularity of 15m for the last year
// 4. granularity of 1h for the last 5 years
// 5. granularity of 1d for the last 10 years
defaultNumeric.addArchives("LAST,0.5,1,360:LAST,0.5,6,10080:LAST,0.5,90,36500:LAST,0.5,8640,3650");
rrdDefs.put(DEFAULT_NUMERIC, defaultNumeric);

RrdDefConfig defaultQuantifiable = new RrdDefConfig(DEFAULT_QUANTIFIABLE);
// use 10 seconds as a step size for numeric values and allow a 10 minute silence between updates
defaultQuantifiable.setDef("GAUGE,600,U,U,10");
// define 5 different boxes:
// 1. granularity of 10s for the last hour
// 2. granularity of 1m for the last week
// 3. granularity of 15m for the last year
// 4. granularity of 1h for the last 5 years
// 5. granularity of 1d for the last 10 years
defaultQuantifiable
.addArchives("AVERAGE,0.5,1,360:AVERAGE,0.5,6,10080:LAST,0.5,90,36500:AVERAGE,0.5,8640,3650");
rrdDefs.put(DEFAULT_QUANTIFIABLE, defaultQuantifiable);

RrdDefConfig defaultOther = new RrdDefConfig(DEFAULT_OTHER);
// use 5 seconds as a step size for discrete values and allow a 1h silence between updates
defaultOther.setDef("GAUGE,3600,U,U,5");
// define 4 different boxes:
// 1. granularity of 5s for the last hour
// 2. granularity of 1m for the last week
// 3. granularity of 15m for the last year
// 4. granularity of 4h for the last 10 years
defaultOther.addArchives("LAST,0.5,1,1440:LAST,0.5,12,10080:LAST,0.5,180,35040:LAST,0.5,240,21900");
rrdDefs.put(DEFAULT_OTHER, defaultOther);

if (config.isEmpty()) {
logger.debug("using default configuration only");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# configure specific rrd properties for given items in this file.
# please refer to the documentation available at
# Configure specific rrd properties for given items in this file.
# Please refer to the documentation available at
# https://www.openhab.org/addons/persistence/rrd4j/
#
# default_numeric and default_other are internally defined defnames and are used as
Expand Down

0 comments on commit 20ac8df

Please sign in to comment.