java.lang.Object
org.rrd4j.core.Datasource
- All Implemented Interfaces:
RrdUpdater<Datasource>
Class to represent single datasource within RRD. Each datasource object holds the following information: datasource definition (once set, never changed) and datasource state variables (changed whenever RRD gets updated).
Normally, you don't need to manipulate Datasource objects directly, it's up to Rrd4j framework to do it for you.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate doubleInterpolated value at the last update.private final RrdDouble<Datasource> Value accumulated since the last step.private final RrdString<Datasource> The name of the data source.private final RrdEnum<Datasource, DsType> The type of the data source.private final RrdLong<Datasource> The heartbeat, in seconds.private static final StringError text for an out of range min or max.private final RrdDouble<Datasource> The value at the last update.private static final doubleLargest value representable in 32 bits.private static final doubleLargest value representable in 64 bits.private final RrdDouble<Datasource> The minimum and maximum accepted values.private final RrdDouble<Datasource> The minimum and maximum accepted values.private final RrdLong<Datasource> Seconds of unknown data accumulated.private final RrdDbThe database holding this data source.Constructor Summary
ConstructorsConstructorDescriptionDatasource(RrdDb parentDb, DataImporter reader, int dsIndex) Loads an existing datasource from another RRD, copying the definition and the state variables (last value, accumulated value and NaN seconds) from the indexed datasource of the importer.Datasource(RrdDb parentDb, DsDef dsDef) Binds this datasource's storage slots in the RRD and, when a definition is supplied, fills them with it.Method Summary
Modifier and TypeMethodDescriptionprivate voidaccumulate(long oldTime, long newTime, double updateValue) Adds an update to the accumulated value.(package private) voidWrites the datasource as a<ds>element of the XML dump, including the definition fields and the PDP status fields holding the last, accumulated and unknown-second counts.private doublecalculateLastTotal(long startTime, long boundaryTime) Integrates up to the last known value.private doublecalculateTotal(long startTime, long boundaryTime) Integrates the consolidated values over a range.private doublecalculateUpdateValue(long oldTime, double oldValue, long newTime, double newValue) Interpolates the value to store for an update.voidcopyStateTo(Datasource datasource) Copies object's internal state to another Datasource object.(package private) Stringdump()Returns a string representation of datasource information.doubleReturns value this datasource accumulated so far.intReturns index of this Datasource object in the RRD.longReturns datasource heartbeatdoubleReturns last known value of the datasource.doubleReturns maximal allowed value for this datasource.doubleReturns minimal allowed value for this datasource.getName()Returns datasource name.longReturns the number of accumulated NaN seconds.Required to implement RrdUpdater interface.Returns the underlying storage (backend) object which actually performs all I/O operations.getType()Returns datasource type (GAUGE, COUNTER, DERIVE, ABSOLUTE).(package private) final voidprocess(long newTime, double newValue) Feeds one sample into the current primary data point, accumulating the rate over the interval since the last sample.voidSets datasource name to a new valuevoidSetter for the fielddsType.voidsetHeartbeat(long heartbeat) Sets datasource heartbeat to a new value.voidsetMaxValue(double maxValue, boolean filterArchivedValues) Sets maximum allowed value for this datasource.voidsetMinMaxValue(double minValue, double maxValue, boolean filterArchivedValues) Sets min/max values allowed for this datasource.voidsetMinValue(double minValue, boolean filterArchivedValues) Sets minimum allowed value for this datasource.
Field Details
MAX_32_BIT
private static final double MAX_32_BITLargest value representable in 32 bits.MAX_64_BIT
private static final double MAX_64_BITLargest value representable in 64 bits.INVALID_MIN_MAX_VALUES
Error text for an out of range min or max.- See Also:
accumLastValue
private double accumLastValueInterpolated value at the last update.parentDb
The database holding this data source.dsName
The name of the data source.dsType
The type of the data source.heartbeat
The heartbeat, in seconds.minValue
The minimum and maximum accepted values.maxValue
The minimum and maximum accepted values.lastValue
The value at the last update.nanSeconds
Seconds of unknown data accumulated.accumValue
Value accumulated since the last step.
Constructor Details
Datasource
Datasource(RrdDb parentDb, DsDef dsDef) throws IOException Binds this datasource's storage slots in the RRD and, when a definition is supplied, fills them with it. Passing a null definition leaves every slot holding the zero value, which is how a datasource is opened for reading from an existing file; the other constructor then copies the stored values in.- Parameters:
parentDb- the RRD this datasource belongs to, whose backend allocates the storagedsDef- definition to initialize the slots from, or null to leave them unset- Throws:
IOException- if the storage cannot be allocated or written
Datasource
Datasource(RrdDb parentDb, DataImporter reader, int dsIndex) throws IOException Loads an existing datasource from another RRD, copying the definition and the state variables (last value, accumulated value and NaN seconds) from the indexed datasource of the importer.- Parameters:
parentDb- the RRD this datasource belongs to, whose backend allocates the storagereader- the RRD to copy the datasource fromdsIndex- position of the datasource to copy within the reader's datasource list- Throws:
IOException- if the source datasource cannot be read or the storage written
Method Details
dump
Returns a string representation of datasource information.- Returns:
- a string containing datasource information
- Throws:
IOException- if an I/O error occurs
getName
Returns datasource name.- Returns:
- Datasource name
- Throws:
IOException- Thrown in case of I/O error
getType
Returns datasource type (GAUGE, COUNTER, DERIVE, ABSOLUTE).- Returns:
- Datasource type, one of GAUGE, COUNTER, DERIVE or ABSOLUTE.
- Throws:
IOException- Thrown in case of I/O error
getHeartbeat
Returns datasource heartbeat- Returns:
- Datasource heartbeat, in seconds
- Throws:
IOException- Thrown in case of I/O error
getMinValue
Returns minimal allowed value for this datasource.- Returns:
- Minimal value allowed.
- Throws:
IOException- Thrown in case of I/O error
getMaxValue
Returns maximal allowed value for this datasource.- Returns:
- Maximal value allowed.
- Throws:
IOException- Thrown in case of I/O error
getLastValue
Returns last known value of the datasource.- Returns:
- Last datasource value.
- Throws:
IOException- Thrown in case of I/O error
getAccumValue
Returns value this datasource accumulated so far.- Returns:
- Accumulated datasource value.
- Throws:
IOException- Thrown in case of I/O error
getNanSeconds
Returns the number of accumulated NaN seconds.- Returns:
- Accumulated NaN seconds.
- Throws:
IOException- Thrown in case of I/O error
process
Feeds one sample into the current primary data point, accumulating the rate over the interval since the last sample. Once the sample crosses a step boundary the interval is closed out and written to this datasource's archive, after which accumulation restarts at the boundary.- Parameters:
newTime- sample time in seconds since the epochnewValue- sample value; samples further apart than the heartbeat are ignored, as are rates that fall outside the configured min/max- Throws:
IOException- if the datasource state cannot be read, updated or archived
calculateUpdateValue
private double calculateUpdateValue(long oldTime, double oldValue, long newTime, double newValue) throws IOException Interpolates the value to store for an update.- Parameters:
oldTime- the time of the previous updateoldValue- the value at the previous updatenewTime- the time of the new updatenewValue- the value given for the new update- Returns:
- the interpolated value
- Throws:
IOException- if the archive data cannot be read
accumulate
Adds an update to the accumulated value.- Parameters:
oldTime- the start of the accumulationnewTime- the time of the updateupdateValue- the value to accumulate- Throws:
IOException- if the archive data cannot be read
calculateTotal
Integrates the consolidated values over a range.- Parameters:
startTime- the start of the rangeboundaryTime- the end of the range- Returns:
- the total over the range
- Throws:
IOException- if the archive data cannot be read
calculateLastTotal
Integrates up to the last known value.- Parameters:
startTime- the start of the rangeboundaryTime- the end of the range- Returns:
- the total over the range
- Throws:
IOException- if the archive data cannot be read
appendXml
Writes the datasource as a<ds>element of the XML dump, including the definition fields and the PDP status fields holding the last, accumulated and unknown-second counts. An unknown last value is written asUNKN.- Parameters:
writer- the XML writer positioned at the point thedselement starts- Throws:
IOException- if a datasource value cannot be read from storage
copyStateTo
Copies object's internal state to another Datasource object.
- Specified by:
copyStateToin interfaceRrdUpdater<Datasource>- Parameters:
datasource- aRrdUpdaterobject.- Throws:
IOException- if the state cannot be read from the backend
getDsIndex
Returns index of this Datasource object in the RRD.- Returns:
- Datasource index in the RRD.
- Throws:
IOException- Thrown in case of I/O error
setHeartbeat
Sets datasource heartbeat to a new value.- Parameters:
heartbeat- New heartbeat value- Throws:
IOException- Thrown in case of I/O errorIllegalArgumentException- Thrown if invalid (non-positive) heartbeat value is specified.
setDsName
Sets datasource name to a new value- Parameters:
newDsName- New datasource name- Throws:
IOException- Thrown in case of I/O error
setDsType
Setter for the fielddsType.- Parameters:
newDsType- aDsTypeobject.- Throws:
IOException- if the RRD file cannot be written.
setMinValue
Sets minimum allowed value for this datasource. IffilterArchivedValuesargument is set to true, all archived values less thenminValuewill be fixed to NaN.- Parameters:
minValue- New minimal value. SpecifyDouble.NaNif no minimal value should be setfilterArchivedValues- true, if archived datasource values should be fixed; false, otherwise.- Throws:
IOException- Thrown in case of I/O errorIllegalArgumentException- Thrown if invalid minValue was supplied (not less then maxValue)
setMaxValue
Sets maximum allowed value for this datasource. IffilterArchivedValuesargument is set to true, all archived values greater thenmaxValuewill be fixed to NaN.- Parameters:
maxValue- New maximal value. SpecifyDouble.NaNif no max value should be set.filterArchivedValues- true, if archived datasource values should be fixed; false, otherwise.- Throws:
IOException- Thrown in case of I/O errorIllegalArgumentException- Thrown if invalid maxValue was supplied (not greater then minValue)
setMinMaxValue
public void setMinMaxValue(double minValue, double maxValue, boolean filterArchivedValues) throws IOException Sets min/max values allowed for this datasource. IffilterArchivedValuesargument is set to true, all archived values less thenminValueor greater thenmaxValuewill be fixed to NaN.- Parameters:
minValue- New minimal value. SpecifyDouble.NaNif no min value should be set.maxValue- New maximal value. SpecifyDouble.NaNif no max value should be set.filterArchivedValues- true, if archived datasource values should be fixed; false, otherwise.- Throws:
IOException- Thrown in case of I/O errorIllegalArgumentException- Thrown if invalid min/max values were supplied
getRrdBackend
Returns the underlying storage (backend) object which actually performs all I/O operations.- Specified by:
getRrdBackendin interfaceRrdUpdater<Datasource>- Returns:
- I/O backend object
getRrdAllocator
Required to implement RrdUpdater interface. You should never call this method directly.- Specified by:
getRrdAllocatorin interfaceRrdUpdater<Datasource>- Returns:
- Allocator object