/** * Returns archive consolidation function ("AVERAGE", "MIN", "MAX", "FIRST", "LAST" or "TOTAL"). * * @return Archive consolidation function. * @throws java.io.IOException Thrown in case of I/O error. */ public ConsolFun getConsolFun() throws IOException { return consolFun.get(); }
void set(E value) throws IOException { if (!isCachingAllowed()) { writeEnum(value); } // caching allowed else if (cache == null || cache != value) { // update cache writeEnum((cache = value)); } }
E get() throws IOException { if (!isCachingAllowed()) { return readEnum(clazz); } else { if (cache == null) { cache = readEnum(clazz); } return cache; } }
Datasource(RrdDb parentDb, DsDef dsDef) throws IOException { boolean shouldInitialize = dsDef != null; this.parentDb = parentDb; dsName = new RrdString<>(this); dsType = new RrdEnum<>(this, DsType.class); heartbeat = new RrdLong<>(this); minValue = new RrdDouble<>(this); maxValue = new RrdDouble<>(this); lastValue = new RrdDouble<>(this); accumValue = new RrdDouble<>(this); nanSeconds = new RrdLong<>(this); accumLastValue = Double.NaN; if (shouldInitialize) { dsName.set(dsDef.getDsName()); dsType.set(dsDef.getDsType()); heartbeat.set(dsDef.getHeartbeat()); minValue.set(dsDef.getMinValue()); maxValue.set(dsDef.getMaxValue()); lastValue.set(Double.NaN); accumValue.set(0.0); Header header = parentDb.getHeader(); nanSeconds.set(header.getLastUpdateTime() % header.getStep()); } }
String dump() throws IOException { StringBuilder sb = new StringBuilder("== ARCHIVE ==\n"); sb.append("RRA:") .append(consolFun.name()) .append(":") .append(xff.get()) .append(":") .append(steps.get()) .append(":") .append(rows.get()) .append("\n") .append("interval [") .append(getStartTime()) .append(", ") .append(getEndTime()) .append("]" + "\n"); for (int i = 0; i < robins.length; i++) { sb.append(states[i].dump()); sb.append(robins[i].dump()); } return sb.toString(); }
/** * <p>Setter for the field <code>dsType</code>.</p> * * @param newDsType a {@link org.rrd4j.DsType} object. * @throws java.io.IOException if any. */ public void setDsType(DsType newDsType) throws IOException { // set datasource type dsType.set(newDsType); // reset datasource status lastValue.set(Double.NaN); accumValue.set(0.0); // reset archive status int dsIndex = parentDb.getDsIndex(dsName.get()); Archive[] archives = parentDb.getArchives(); for (Archive archive : archives) { archive.getArcState(dsIndex).setAccumValue(Double.NaN); } }
Archive(RrdDb parentDb, ArcDef arcDef) throws IOException { this.parentDb = parentDb; consolFun = new RrdEnum<>(this, false, ConsolFun.class); // Don't cache, as the enum type should be used instead xff = new RrdDouble<>(this); steps = new RrdInt<>(this, true); // constant, may be cached boolean shouldInitialize = arcDef != null; if (shouldInitialize) { consolFun.set(arcDef.getConsolFun()); xff.set(arcDef.getXff()); steps.set(arcDef.getSteps());
String dump() throws IOException { return "== DATASOURCE ==\n" + "DS:" + dsName.get() + ":" + dsType.name() + ":" + heartbeat.get() + ":" + minValue.get() + ":" + maxValue.get() + "\nlastValue:" + lastValue.get() + " nanSeconds:" + nanSeconds.get() + " accumValue:" + accumValue.get() + "\n"; }
Datasource(RrdDb parentDb, DataImporter reader, int dsIndex) throws IOException { this(parentDb, null); dsName.set(reader.getDsName(dsIndex)); dsType.set(reader.getDsType(dsIndex)); heartbeat.set(reader.getHeartbeat(dsIndex)); minValue.set(reader.getMinValue(dsIndex)); maxValue.set(reader.getMaxValue(dsIndex)); lastValue.set(reader.getLastValue(dsIndex)); accumValue.set(reader.getAccumValue(dsIndex)); nanSeconds.set(reader.getNanSeconds(dsIndex)); }
/** * Returns datasource type (GAUGE, COUNTER, DERIVE, ABSOLUTE). * * @return Datasource type. * @throws java.io.IOException Thrown in case of I/O error */ public DsType getType() throws IOException { return dsType.get(); }
void appendXml(XmlWriter writer) throws IOException { writer.startTag("ds"); writer.writeTag("name", dsName.get()); writer.writeTag("type", dsType.name()); writer.writeTag("minimal_heartbeat", heartbeat.get()); writer.writeTag("min", minValue.get()); writer.writeTag("max", maxValue.get()); writer.writeComment("PDP Status"); writer.writeTag("last_ds", lastValue.get(), "UNKN"); writer.writeTag("value", accumValue.get()); writer.writeTag("unknown_sec", nanSeconds.get()); writer.closeTag(); // ds }
String name() throws IOException { return get().name(); }
void appendXml(XmlWriter writer) throws IOException { writer.startTag("rra"); writer.writeTag("cf", consolFun.name()); writer.writeComment(getArcStep() + " seconds"); writer.writeTag("pdp_per_row", steps.get()); writer.startTag("params"); writer.writeTag("xff", xff.get()); writer.closeTag(); // params writer.startTag("cdp_prep"); for (ArcState state : states) { state.appendXml(writer); } writer.closeTag(); // cdp_prep writer.startTag("database"); long startTime = getStartTime(); for (int i = 0; i < rows.get(); i++) { long time = startTime + i * getArcStep(); writer.writeComment(Util.getDate(time) + " / " + time); writer.startTag("row"); for (Robin robin : robins) { writer.writeTag("v", robin.getValue(i)); } writer.closeTag(); // row } writer.closeTag(); // database writer.closeTag(); // rra }
/** * {@inheritDoc} * * Copies object's internal state to another Datasource object. */ public void copyStateTo(Datasource datasource) throws IOException { if (!datasource.dsName.get().equals(dsName.get())) { throw new IllegalArgumentException("Incompatible datasource names"); } if (datasource.dsType.get() != dsType.get()) { throw new IllegalArgumentException("Incompatible datasource types"); } datasource.lastValue.set(lastValue.get()); datasource.nanSeconds.set(nanSeconds.get()); datasource.accumValue.set(accumValue.get()); }
double updateValue = Double.NaN; if (newTime - oldTime <= heartbeat.get()) { switch (dsType.get()) { case GAUGE: updateValue = newValue;
/** * {@inheritDoc} * * Copies object's internal state to another Archive object. */ public void copyStateTo(Archive arc) throws IOException { if (arc.consolFun.get() != consolFun.get()) { throw new IllegalArgumentException("Incompatible consolidation functions"); } if (arc.steps.get() != steps.get()) { throw new IllegalArgumentException("Incompatible number of steps"); } int count = parentDb.getHeader().getDsCount(); for (int i = 0; i < count; i++) { int j = Util.getMatchingDatasourceIndex(parentDb, i, arc.parentDb); if (j >= 0) { states[i].copyStateTo(arc.states[j]); robins[i].copyStateTo(arc.robins[j]); } } }
private void finalizeStep(ArcState state, Robin robin) throws IOException { // should store long arcSteps = steps.get(); double arcXff = xff.get(); long nanSteps = state.getNanSteps(); double accumValue = state.getAccumValue(); if (nanSteps <= arcXff * arcSteps && !Double.isNaN(accumValue)) { if (consolFun.get() == ConsolFun.AVERAGE) { accumValue /= (arcSteps - nanSteps); } robin.store(accumValue); } else { robin.store(Double.NaN); } state.setAccumValue(Double.NaN); state.setNanSteps(0); }
private void accumulate(ArcState state, double value) throws IOException { if (Double.isNaN(value)) { state.setNanSteps(state.getNanSteps() + 1); } else { switch (consolFun.get()) { case MIN: state.setAccumValue(Util.min(state.getAccumValue(), value)); break; case MAX: state.setAccumValue(Util.max(state.getAccumValue(), value)); break; case FIRST: if (Double.isNaN(state.getAccumValue())) { state.setAccumValue(value); } break; case LAST: state.setAccumValue(value); break; case AVERAGE: case TOTAL: state.setAccumValue(Util.sum(state.getAccumValue(), value)); break; } } }