📄 datasource.java
字号:
updateValue = Double.NaN;
}
if (!Double.isNaN(maxVal) && updateValue > maxVal) {
updateValue = Double.NaN;
}
}
}
lastValue.set(newValue);
return updateValue;
}
private void accumulate(long oldTime, long newTime, double updateValue) throws IOException {
if (Double.isNaN(updateValue)) {
nanSeconds.set(nanSeconds.get() + (newTime - oldTime));
}
else {
accumValue.set(accumValue.get() + updateValue * (newTime - oldTime));
}
}
private double calculateTotal(long startTime, long boundaryTime) throws IOException {
double totalValue = Double.NaN;
long validSeconds = boundaryTime - startTime - nanSeconds.get();
if (nanSeconds.get() <= heartbeat.get() && validSeconds > 0) {
totalValue = accumValue.get() / validSeconds;
}
// IMPORTANT:
// if datasource name ends with "!", we'll send zeros instead of NaNs
// this might be handy from time to time
if (Double.isNaN(totalValue) && dsName.get().endsWith(DsDef.FORCE_ZEROS_FOR_NANS_SUFFIX)) {
totalValue = 0D;
}
return totalValue;
}
void appendXml(XmlWriter writer) throws IOException {
writer.startTag("ds");
writer.writeTag("name", dsName.get());
writer.writeTag("type", dsType.get());
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
}
/**
* Copies object's internal state to another Datasource object.
*
* @param other New Datasource object to copy state to
* @throws IOException Thrown in case of I/O error
* @throws RrdException Thrown if supplied argument is not a Datasource object
*/
public void copyStateTo(RrdUpdater other) throws IOException, RrdException {
if (!(other instanceof Datasource)) {
throw new RrdException(
"Cannot copy Datasource object to " + other.getClass().getName());
}
Datasource datasource = (Datasource) other;
if (!datasource.dsName.get().equals(dsName.get())) {
throw new RrdException("Incomaptible datasource names");
}
if (!datasource.dsType.get().equals(dsType.get())) {
throw new RrdException("Incomaptible datasource types");
}
datasource.lastValue.set(lastValue.get());
datasource.nanSeconds.set(nanSeconds.get());
datasource.accumValue.set(accumValue.get());
}
/**
* Returns index of this Datasource object in the RRD.
*
* @return Datasource index in the RRD.
* @throws IOException Thrown in case of I/O error
*/
public int getDsIndex() throws IOException {
try {
return parentDb.getDsIndex(dsName.get());
}
catch (RrdException e) {
return -1;
}
}
/**
* Sets datasource heartbeat to a new value.
*
* @param heartbeat New heartbeat value
* @throws IOException Thrown in case of I/O error
* @throws RrdException Thrown if invalid (non-positive) heartbeat value is specified.
*/
public void setHeartbeat(long heartbeat) throws RrdException, IOException {
if (heartbeat < 1L) {
throw new RrdException("Invalid heartbeat specified: " + heartbeat);
}
this.heartbeat.set(heartbeat);
}
/**
* Sets datasource name to a new value
*
* @param newDsName New datasource name
* @throws RrdException Thrown if invalid data source name is specified (name too long, or
* name already defined in the RRD
* @throws IOException Thrown in case of I/O error
*/
public void setDsName(String newDsName) throws RrdException, IOException {
if (newDsName.length() > RrdString.STRING_LENGTH) {
throw new RrdException("Invalid datasource name specified: " + newDsName);
}
if (parentDb.containsDs(newDsName)) {
throw new RrdException("Datasource already defined in this RRD: " + newDsName);
}
this.dsName.set(newDsName);
}
public void setDsType(String newDsType) throws RrdException, IOException {
if (!DsDef.isValidDsType(newDsType)) {
throw new RrdException("Invalid datasource type: " + newDsType);
}
// set datasource type
this.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);
}
}
/**
* Sets minimum allowed value for this datasource. If <code>filterArchivedValues</code>
* argment is set to true, all archived values less then <code>minValue</code> will
* be fixed to NaN.
*
* @param minValue New minimal value. Specify <code>Double.NaN</code> if no minimal
* value should be set
* @param filterArchivedValues true, if archived datasource values should be fixed;
* false, otherwise.
* @throws IOException Thrown in case of I/O error
* @throws RrdException Thrown if invalid minValue was supplied (not less then maxValue)
*/
public void setMinValue(double minValue, boolean filterArchivedValues)
throws IOException, RrdException {
double maxValue = this.maxValue.get();
if (!Double.isNaN(minValue) && !Double.isNaN(maxValue) && minValue >= maxValue) {
throw new RrdException("Invalid min/max values: " + minValue + "/" + maxValue);
}
this.minValue.set(minValue);
if (!Double.isNaN(minValue) && filterArchivedValues) {
int dsIndex = getDsIndex();
Archive[] archives = parentDb.getArchives();
for (Archive archive : archives) {
archive.getRobin(dsIndex).filterValues(minValue, Double.NaN);
}
}
}
/**
* Sets maximum allowed value for this datasource. If <code>filterArchivedValues</code>
* argment is set to true, all archived values greater then <code>maxValue</code> will
* be fixed to NaN.
*
* @param maxValue New maximal value. Specify <code>Double.NaN</code> if no max
* value should be set.
* @param filterArchivedValues true, if archived datasource values should be fixed;
* false, otherwise.
* @throws IOException Thrown in case of I/O error
* @throws RrdException Thrown if invalid maxValue was supplied (not greater then minValue)
*/
public void setMaxValue(double maxValue, boolean filterArchivedValues)
throws IOException, RrdException {
double minValue = this.minValue.get();
if (!Double.isNaN(minValue) && !Double.isNaN(maxValue) && minValue >= maxValue) {
throw new RrdException("Invalid min/max values: " + minValue + "/" + maxValue);
}
this.maxValue.set(maxValue);
if (!Double.isNaN(maxValue) && filterArchivedValues) {
int dsIndex = getDsIndex();
Archive[] archives = parentDb.getArchives();
for (Archive archive : archives) {
archive.getRobin(dsIndex).filterValues(Double.NaN, maxValue);
}
}
}
/**
* Sets min/max values allowed for this datasource. If <code>filterArchivedValues</code>
* argment is set to true, all archived values less then <code>minValue</code> or
* greater then <code>maxValue</code> will be fixed to NaN.
*
* @param minValue New minimal value. Specify <code>Double.NaN</code> if no min
* value should be set.
* @param maxValue New maximal value. Specify <code>Double.NaN</code> if no max
* value should be set.
* @param filterArchivedValues true, if archived datasource values should be fixed;
* false, otherwise.
* @throws IOException Thrown in case of I/O error
* @throws RrdException Thrown if invalid min/max values were supplied
*/
public void setMinMaxValue(double minValue, double maxValue, boolean filterArchivedValues)
throws IOException, RrdException {
if (!Double.isNaN(minValue) && !Double.isNaN(maxValue) && minValue >= maxValue) {
throw new RrdException("Invalid min/max values: " + minValue + "/" + maxValue);
}
this.minValue.set(minValue);
this.maxValue.set(maxValue);
if (!(Double.isNaN(minValue) && Double.isNaN(maxValue)) && filterArchivedValues) {
int dsIndex = getDsIndex();
Archive[] archives = parentDb.getArchives();
for (Archive archive : archives) {
archive.getRobin(dsIndex).filterValues(minValue, maxValue);
}
}
}
/**
* Returns the underlying storage (backend) object which actually performs all
* I/O operations.
*
* @return I/O backend object
*/
public RrdBackend getRrdBackend() {
return parentDb.getRrdBackend();
}
/**
* Required to implement RrdUpdater interface. You should never call this method directly.
*
* @return Allocator object
*/
public RrdAllocator getRrdAllocator() {
return parentDb.getRrdAllocator();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -