public class DataProcessor extends Object implements DataHolder
Class which should be used for all calculations based on the data fetched from RRD files. This class
supports ordinary DEF datasources (defined in RRD files), CDEF datasources (RPN expressions evaluation),
SDEF (static datasources - extension of Rrd4j) and PDEF (plottables, see
Plottable
for more information.
Typical class usage:
final long t1 = ... final long t2 = ... DataProcessor dp = new DataProcessor(t1, t2); // DEF datasource dp.addDatasource("x", "demo.rrd", "some_source", "AVERAGE"); // DEF datasource dp.addDatasource("y", "demo.rrd", "some_other_source", "AVERAGE"); // CDEF datasource, z = (x + y) / 2 dp.addDatasource("z", "x,y,+,2,/"); // ACTION! dp.processData(); // Dump calculated values System.out.println(dp.dump());
Modifier and Type | Field and Description |
---|---|
static double |
DEFAULT_PERCENTILE
Constant
DEFAULT_PERCENTILE=95.0 |
static int |
DEFAULT_PIXEL_COUNT
Deprecated.
|
DEFAULT_POOL_USAGE_POLICY
Constructor and Description |
---|
DataProcessor(Calendar gc1,
Calendar gc2)
Creates new DataProcessor object for the given time span.
|
DataProcessor(Date d1,
Date d2)
Creates new DataProcessor object for the given time span.
|
DataProcessor(long t1,
long t2)
Creates new DataProcessor object for the given time span.
|
DataProcessor(java.time.temporal.TemporalAmount d)
Creates new DataProcessor object for the given time duration.
|
Modifier and Type | Method and Description |
---|---|
void |
addDatasource(String name,
FetchData fetchData)
Deprecated.
Uses
datasource(String, FetchData) instead. |
void |
addDatasource(String name,
Plottable plottable)
Deprecated.
Uses
datasource(String, IPlottable) instead |
void |
addDatasource(String name,
String rpnExpression)
Deprecated.
Uses
datasource(String, String) instead |
void |
addDatasource(String name,
String defName,
ConsolFun consolFun)
Deprecated.
Use
Variable based method instead. |
void |
addDatasource(String name,
String sourceName,
double percentile)
Deprecated.
Use
Variable based method instead. |
void |
addDatasource(String name,
String dsName,
FetchData fetchData)
Deprecated.
Uses
datasource(String, String, FetchData) instead. |
void |
addDatasource(String name,
String file,
String dsName,
ConsolFun consolFunc)
Deprecated.
Uses
datasource(String, String, String, ConsolFun) instead. |
void |
addDatasource(String name,
String file,
String dsName,
ConsolFun consolFunc,
RrdBackendFactory backend)
Deprecated.
|
void |
addDatasource(String name,
String file,
String dsName,
ConsolFun consolFunc,
String backend)
Deprecated.
|
void |
addDatasource(String name,
String defName,
Variable var)
Deprecated.
Uses
datasource(String, String, Variable) instead. |
void |
datasource(String name,
FetchData fetchData)
Adds DEF datasource with datasource values already available in the FetchData object.
|
void |
datasource(String name,
IPlottable plottable)
Adds a custom,
plottable datasource (PDEF). |
void |
datasource(String name,
String rpnExpression)
Adds complex source (CDEF).
|
void |
datasource(String name,
String dsName,
FetchData fetchData)
Adds DEF datasource with datasource values already available in the FetchData object.
|
void |
datasource(String name,
String file,
String dsName,
ConsolFun consolFunc)
Adds simple datasource (DEF).
|
void |
datasource(String name,
String file,
String dsName,
ConsolFun consolFunc,
RrdBackendFactory backend)
Adds simple source (DEF).
|
void |
datasource(String name,
String defName,
Variable var)
Creates a datasource that performs a variable calculation on an
another named datasource to yield a single combined timestamp/value.
|
void |
datasource(String name,
URI rrdUri,
String dsName,
ConsolFun consolFunc)
Adds simple datasource (DEF).
|
void |
datasource(String name,
URI uri,
String dsName,
ConsolFun consolFunc,
RrdBackendFactory backend)
Adds simple source (DEF).
|
String |
dump()
Dumps timestamps and values of all datasources in a tabular form.
|
double |
get95Percentile(String sourceName)
Deprecated.
Use
Variable based method instead. |
double |
getAggregate(String sourceName,
ConsolFun consolFun)
Deprecated.
Use
Variable based method instead. |
Aggregates |
getAggregates(String sourceName)
Deprecated.
Use
Variable based method instead. |
long |
getEndingTimestamp()
Deprecated.
Uses
getEndTime() instead. |
long |
getEndTime()
Returns ending timestamp.
|
long |
getFetchRequestResolution()
Returns desired RRD archive step (resolution) in seconds to be used while fetching data
from RRD files.
|
long |
getLastRrdArchiveUpdateTime()
Returns time when last RRD archive was updated (all RRD files are considered).
|
double |
getPercentile(String sourceName)
Deprecated.
Use
Variable based method instead. |
double |
getPercentile(String sourceName,
double percentile)
Deprecated.
Use
Variable based method instead. |
int |
getPixelCount()
Returns the number of pixels (target graph width).
|
RrdDbPool |
getPool() |
(package private) Source |
getSource(String sourceName) |
String[] |
getSourceNames()
Returns array of datasource names defined in this DataProcessor.
|
long |
getStartTime()
Returns starting timestamp.
|
long |
getStep()
Returns the time step used for data processing.
|
long[] |
getTimestamps()
Returns consolidated timestamps created with the
processData() method. |
long[] |
getTimestampsPerPixel()
Calculates timestamps which correspond to individual pixels on the graph
based on the graph width set with a
setPixelCount(int) method call. |
long[] |
getTimestampsPerPixel(int pixelCount)
Calculates timestamps which correspond to individual pixels on the graph.
|
TimeZone |
getTimeZone() |
double[][] |
getValues()
Returns an array of all datasource values for all datasources.
|
double[] |
getValues(String sourceName)
Returns calculated values for a single datasource.
|
double[] |
getValuesPerPixel(String sourceName)
Method used to calculate datasource values which should be presented on the graph
based on the graph width set with a
setPixelCount(int) method call. |
double[] |
getValuesPerPixel(String sourceName,
int pixelCount)
Method used to calculate datasource values which should be presented on the graph
based on the desired graph width.
|
Variable.Value |
getVariable(String sourceName)
Extract the variable value from an already define Variable datasource (a VDEF)
|
Variable.Value |
getVariable(String sourceName,
Variable var)
Returns single aggregated value for a single datasource.
|
boolean |
isPoolUsed()
Returns boolean value representing
RrdDbPool usage policy. |
void |
processData()
Method that should be called once all datasources are defined.
|
void |
setEndTime(long time)
Sets the time when the graph should end.
|
void |
setFetchRequestResolution(long fetchRequestResolution)
Sets desired RRD archive step in seconds to be used internally while fetching data
from RRD files.
|
void |
setPixelCount(int pixelCount)
Sets the number of pixels (target graph width).
|
void |
setPool(RrdDbPool pool)
Defines the
RrdDbPool to use. |
void |
setPoolUsed(boolean poolUsed)
Sets the
RrdDbPool usage policy. |
void |
setStartTime(long time)
Sets the time when the graph should start.
|
void |
setStep(long step)
Once data are fetched, the step value will be used to generate values.
|
void |
setTimeSpan(long startTime,
long endTime)
Sets starting and ending time for the for the graph.
|
void |
setTimeZone(TimeZone tz)
Set the time zone used for the legend.
|
@Deprecated public static final int DEFAULT_PIXEL_COUNT
public static final double DEFAULT_PERCENTILE
DEFAULT_PERCENTILE=95.0
public DataProcessor(long t1, long t2)
processData()
method.t1
- Starting timestamp in seconds without millisecondst2
- Ending timestamp in seconds without millisecondspublic DataProcessor(Date d1, Date d2)
processData()
method.d1
- Starting dated2
- Ending datepublic DataProcessor(Calendar gc1, Calendar gc2)
processData()
method.
It use the time zone for starting calendar date.
gc1
- Starting Calendar dategc2
- Ending Calendar datepublic DataProcessor(java.time.temporal.TemporalAmount d)
d
- duration to substract.public boolean isPoolUsed()
RrdDbPool
usage policy.isPoolUsed
in interface DataHolder
public void setPoolUsed(boolean poolUsed)
RrdDbPool
usage policy.setPoolUsed
in interface DataHolder
poolUsed
- true, if the pool should be used to fetch data from RRD files, false otherwise.public RrdDbPool getPool()
getPool
in interface DataHolder
public void setPool(RrdDbPool pool)
RrdDbPool
to use. If not defined, but {setPoolUsed(boolean)
set to true, the default RrdDbPool.getInstance()
will be used.setPool
in interface DataHolder
pool
- an optional pool to use.public void setPixelCount(int pixelCount)
Sets the number of pixels (target graph width). This number is used only to calculate pixel coordinates
for Rrd4j graphs (methods getValuesPerPixel(String)
and getTimestampsPerPixel()
),
but has influence neither on datasource values calculated with the
processData()
method nor on aggregated values returned from getAggregates(String)
and similar methods. In other words, aggregated values will not change once you decide to change
the dimension of your graph.
pixelCount
- The number of pixels. If you process RRD data in order to display it on the graph,
this should be the width of your graph.public int getPixelCount()
setPixelCount(int)
for more information.public void setStep(long step)
setStep
in interface DataHolder
step
- Default to 0.public long getStep()
processData()
is finished, the method will return the time stamp interval.getStep
in interface DataHolder
public long getFetchRequestResolution()
RrdDb.createFetchRequest()
method
when this method is called internally by this DataProcessor.public void setFetchRequestResolution(long fetchRequestResolution)
RrdDb.createFetchRequest()
method
when this method is called internally by this DataProcessor. If this method is never called, fetch
request resolution defaults to 1 (smallest possible archive step will be chosen automatically).fetchRequestResolution
- Desired archive step (fetch resolution) in seconds.public TimeZone getTimeZone()
getTimeZone
in interface DataHolder
public void setTimeZone(TimeZone tz)
DataHolder
setTimeZone
in interface DataHolder
tz
- the time zone to set@Deprecated public long getEndingTimestamp()
getEndTime()
instead.processData()
method returns. The real
value will be calculated from the last update times of processed RRD files.public long[] getTimestamps()
processData()
method.public double[] getValues(String sourceName)
getTimestamps()
method.sourceName
- Datasource nameIllegalArgumentException
- Thrown if invalid datasource name is specified,
or if datasource values are not yet calculated (method processData()
was not called)@Deprecated public double getAggregate(String sourceName, ConsolFun consolFun)
Variable
based method instead.sourceName
- Datasource nameconsolFun
- Consolidation function to be applied to fetched datasource values.
Valid consolidation functions are MIN, MAX, LAST, FIRST, AVERAGE and TOTAL
(these string constants are conveniently defined in the ConsolFun
class)IllegalArgumentException
- Thrown if invalid datasource name is specified,
or if datasource values are not yet calculated (method processData()
was not called)@Deprecated public Aggregates getAggregates(String sourceName)
Variable
based method instead.sourceName
- Datasource nameIllegalArgumentException
- Thrown if invalid datasource name is specified,
or if datasource values are not yet calculated (method processData()
was not called)public Variable.Value getVariable(String sourceName)
sourceName
- Datasource namepublic Variable.Value getVariable(String sourceName, Variable var)
sourceName
- Datasource namevar
- variable that will generate value@Deprecated public double get95Percentile(String sourceName)
Variable
based method instead.getPercentile(String)
method.
Used by ISPs which charge for bandwidth utilization on a "95th percentile" basis.
The 95th percentile is the highest source value left when the top 5% of a numerically sorted set of source data is discarded. It is used as a measure of the peak value used when one discounts a fair amount for transitory spikes. This makes it markedly different from the average.
sourceName
- Datasource name@Deprecated public double getPercentile(String sourceName)
Variable
based method instead.The 95th percentile is the highest source value left when the top 5% of a numerically sorted set of source data is discarded. It is used as a measure of the peak value used when one discounts a fair amount for transitory spikes. This makes it markedly different from the average.
sourceName
- Datasource name@Deprecated public double getPercentile(String sourceName, double percentile)
Variable
based method instead.getPercentile(String)
but with a possibility to define custom percentile boundary
(different from 95).sourceName
- Datasource name.percentile
- Boundary percentile. Value of 95 (%) is suitable in most cases, but you are free
to provide your own percentile boundary between zero and 100.public String[] getSourceNames()
public double[][] getValues()
getTimestamps()
method.IllegalArgumentException
- Thrown if invalid datasource name is specified,
or if datasource values are not yet calculated (method processData()
was not called)@Deprecated public void addDatasource(String name, Plottable plottable)
datasource(String, IPlottable)
insteadplottable
datasource (PDEF).
The datapoints should be made available by a class extending
Plottable
class.name
- source name.plottable
- class that extends Plottable class and is suited for graphing.public void datasource(String name, IPlottable plottable)
plottable
datasource (PDEF).
The datapoints should be made available by a class extending
Plottable
class.datasource
in interface DataHolder
name
- source name.plottable
- class that extends Plottable class and is suited for graphing.@Deprecated public void addDatasource(String name, String rpnExpression)
datasource(String, String)
insteadAdds complex source (CDEF).
Complex sources are evaluated using the supplied RPN
expression.
name
can be used:
Rrd4j does not force you to specify at least one simple source name as RRDTool.
For more details on RPN see RRDTool's rrdgraph man page.
name
- source name.rpnExpression
- RPN expression containing comma delimited simple and complex
source names, RPN constants, functions and operators.public void datasource(String name, String rpnExpression)
Adds complex source (CDEF).
Complex sources are evaluated using the supplied RPN
expression.
name
can be used:
Rrd4j does not force you to specify at least one simple source name as RRDTool.
For more details on RPN see RRDTool's rrdgraph man page.
datasource
in interface DataHolder
name
- source name.rpnExpression
- RPN expression containing comma delimited simple and complex
source names, RPN constants, functions and operators.@Deprecated public void addDatasource(String name, String defName, ConsolFun consolFun)
Variable
based method instead.name
- source name.defName
- Name of the datasource to calculate the value from.consolFun
- Consolidation function to use for value calculation@Deprecated public void addDatasource(String name, String sourceName, double percentile)
Variable
based method instead.Requires that the other datasource has already been defined; otherwise, it'll end up with no data
name
- - the new virtual datasource namesourceName
- - the datasource from which to extract the percentile. Must be a previously
defined virtual datasourcepercentile
- - the percentile to extract from the source datasource@Deprecated public void addDatasource(String name, String defName, Variable var)
datasource(String, String, Variable)
instead.Requires that the other datasource has already been defined; otherwise, it'll end up with no data
name
- - the new virtual datasource namedefName
- - the datasource from which to extract the percentile. Must be a previously
defined virtual datasourcevar
- - a new instance of a Variable used to do the calculationpublic void datasource(String name, String defName, Variable var)
Requires that the other datasource has already been defined; otherwise, it'll end up with no data
datasource
in interface DataHolder
name
- - the new virtual datasource namedefName
- - the datasource from which to extract the percentile. Must be a previously
defined virtual datasourcevar
- - a new instance of a Variable used to do the calculation@Deprecated public void addDatasource(String name, String file, String dsName, ConsolFun consolFunc)
datasource(String, String, String, ConsolFun)
instead.Adds simple datasource (DEF). Simple source name
can be used:
name
- source name.file
- Path to RRD file.dsName
- Datasource name defined in the RRD file.consolFunc
- Consolidation function that will be used to extract data from the RRDpublic void datasource(String name, String file, String dsName, ConsolFun consolFunc)
Adds simple datasource (DEF). Simple source name
can be used:
datasource
in interface DataHolder
name
- source name.file
- Path to RRD file.dsName
- Datasource name defined in the RRD file.consolFunc
- Consolidation function that will be used to extract data from the RRDpublic void datasource(String name, URI rrdUri, String dsName, ConsolFun consolFunc)
Adds simple datasource (DEF). Simple source name
can be used:
datasource
in interface DataHolder
name
- source name.rrdUri
- URI to RRD file.dsName
- Datasource name defined in the RRD file.consolFunc
- Consolidation function that will be used to extract data from the RRD@Deprecated public void addDatasource(String name, String file, String dsName, ConsolFun consolFunc, String backend)
datasource(String, String, String, ConsolFun, RrdBackendFactory)
insteadAdds simple source (DEF). Source name
can be used:
name
- Source name.file
- Path to RRD file.dsName
- Data source name defined in the RRD file.consolFunc
- Consolidation function that will be used to extract data from the RRD
file ("AVERAGE", "MIN", "MAX" or "LAST" - these string constants are conveniently defined
in the ConsolFun
class).backend
- Name of the RrdBackendFactory that should be used for this RrdDb.@Deprecated public void addDatasource(String name, String file, String dsName, ConsolFun consolFunc, RrdBackendFactory backend)
datasource(String, String, String, ConsolFun, RrdBackendFactory)
insteadAdds simple source (DEF). Source name
can be used:
name
- Source name.file
- Path to RRD file.dsName
- Data source name defined in the RRD file.consolFunc
- Consolidation function that will be used to extract data from the RRD
file ("AVERAGE", "MIN", "MAX" or "LAST" - these string constants are conveniently defined
in the ConsolFun
class).backend
- Name of the RrdBackendFactory that should be used for this RrdDb.public void datasource(String name, String file, String dsName, ConsolFun consolFunc, RrdBackendFactory backend)
Adds simple source (DEF). Source name
can be used:
datasource
in interface DataHolder
name
- Source name.file
- Path to RRD file.dsName
- Data source name defined in the RRD file.consolFunc
- Consolidation function that will be used to extract data from the RRD
file ("AVERAGE", "MIN", "MAX" or "LAST" - these string constants are conveniently defined
in the ConsolFun
class).backend
- Name of the RrdBackendFactory that should be used for this RrdDb.public void datasource(String name, URI uri, String dsName, ConsolFun consolFunc, RrdBackendFactory backend)
Adds simple source (DEF). Source name
can be used:
datasource
in interface DataHolder
name
- Source name.uri
- URI to RRD file.dsName
- Data source name defined in the RRD file.consolFunc
- Consolidation function that will be used to extract data from the RRD
file ("AVERAGE", "MIN", "MAX" or "LAST" - these string constants are conveniently defined
in the ConsolFun
class).backend
- Name of the RrdBackendFactory that should be used for this RrdDb.@Deprecated public void addDatasource(String name, FetchData fetchData)
datasource(String, FetchData)
instead.name
- Source name.fetchData
- Fetched data containing values for the given source name.public void datasource(String name, FetchData fetchData)
datasource
in interface DataHolder
name
- Source name.fetchData
- Fetched data containing values for the given source name.@Deprecated public void addDatasource(String name, String dsName, FetchData fetchData)
datasource(String, String, FetchData)
instead.name
- Source name.dsName
- Source name in the fetch data.fetchData
- Fetched data containing values for the given source name.public void datasource(String name, String dsName, FetchData fetchData)
datasource
in interface DataHolder
name
- Source name.dsName
- Source name in the fetch data.fetchData
- Fetched data containing values for the given source name.public void processData() throws IOException
IOException
- Thrown in case of I/O error (while fetching data from RRD files)public double[] getValuesPerPixel(String sourceName, int pixelCount)
getTimestampsPerPixel()
method.sourceName
- Datasource namepixelCount
- Graph widthIllegalArgumentException
- Thrown if datasource values are not yet calculated (method processData()
was not called)public double[] getValuesPerPixel(String sourceName)
setPixelCount(int)
method call.
Each value returned represents a single pixel on the graph. Corresponding timestamp can be
found in the array returned from getTimestampsPerPixel()
method.sourceName
- Datasource nameIllegalArgumentException
- Thrown if datasource values are not yet calculated (method processData()
was not called)public long[] getTimestampsPerPixel(int pixelCount)
pixelCount
- Graph widthpublic long[] getTimestampsPerPixel()
setPixelCount(int)
method call.public String dump()
public long getLastRrdArchiveUpdateTime()
public void setEndTime(long time)
DataHolder
setEndTime
in interface DataHolder
time
- Ending time for the graph in seconds since epochpublic long getEndTime()
DataHolder
getEndTime
in interface DataHolder
public void setStartTime(long time)
DataHolder
setStartTime
in interface DataHolder
time
- Starting time for the graph in seconds since epochpublic long getStartTime()
DataHolder
getStartTime
in interface DataHolder
public void setTimeSpan(long startTime, long endTime)
DataHolder
setTimeSpan
in interface DataHolder
startTime
- Starting time in seconds since epochendTime
- Ending time in seconds since epoch