public class DataProcessor extends Object implements ConsolFuns
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 int |
DEFAULT_PIXEL_COUNT
Constant representing the default number of pixels on a JRobin graph (will be used if
no other value is specified with
setStep() method. |
static boolean |
DEFAULT_POOL_USAGE_POLICY
Constant that defines the default
RrdDbPool usage policy. |
CF_AVERAGE, CF_FIRST, CF_LAST, CF_MAX, CF_MIN, CF_TOTAL
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.
|
Modifier and Type | Method and Description |
---|---|
void |
addDatasource(String name,
FetchData fetchData)
Adds DEF datasource with datasource values already available in the FetchData object.
|
void |
addDatasource(String name,
Plottable plottable)
Adds a custom,
plottable datasource (PDEF). |
void |
addDatasource(String name,
String rpnExpression)
Adds complex source (CDEF).
|
void |
addDatasource(String name,
String sourceName,
double percentile)
Creates a new VDEF datasource that performs a percentile calculation on an
another named datasource to yield a single value.
|
void |
addDatasource(String name,
String sourceName,
double percentile,
boolean ignorenan)
Creates a new VDEF datasource that performs a percentile calculation on an
another named datasource to yield a single value.
|
void |
addDatasource(String name,
String defName,
String consolFun)
Adds static source (SDEF).
|
void |
addDatasource(String name,
String file,
String dsName,
String consolFunc)
Adds simple datasource (DEF).
|
void |
addDatasource(String name,
String file,
String dsName,
String consolFunc,
String backend)
Adds simple source (DEF).
|
String |
dump()
Dumps timestamps and values of all datasources in a tabelar form.
|
double |
get95Percentile(String sourceName)
This method is just an alias for
getPercentile(String) method. |
double |
getAggregate(String sourceName,
String consolFun)
Returns single aggregated value for a single datasource.
|
Aggregates |
getAggregates(String sourceName)
Returns all (MIN, MAX, LAST, FIRST, AVERAGE and TOTAL) aggregated values for a single datasource.
|
long |
getEndingTimestamp()
Returns ending timestamp.
|
long |
getFetchRequestResolution()
Returns desired RRD archive step (reslution) 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)
Used by ISPs which charge for bandwidth utilization on a "95th percentile" basis.
|
double |
getPercentile(String sourceName,
double percentile)
The same as
getPercentile(String) but with a possibility to define custom percentile boundary
(different from 95). |
int |
getPixelCount()
Returns the number of pixels (target graph width).
|
String[] |
getSourceNames()
Returns array of datasource names defined in this DataProcessor.
|
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.
|
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.
|
boolean |
isPoolUsed()
Returns boolean value representing
RrdDbPool usage policy. |
static void |
main(String[] args)
Cute little demo.
|
void |
processData()
Method that should be called once all datasources are defined.
|
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 |
setPoolUsed(boolean poolUsed)
Sets the
RrdDbPool usage policy. |
void |
setStep(long step)
Roughly corresponds to the --step option in RRDTool's graph/xport commands.
|
public static final int DEFAULT_PIXEL_COUNT
setStep()
method.public static final boolean DEFAULT_POOL_USAGE_POLICY
RrdDbPool
usage policy. Defaults to false
(i.e. the pool will not be used to fetch data from RRD files)public DataProcessor(long t1, long t2) throws RrdException
processData()
method.t1
- Starting timestamp in seconds without millisecondst2
- Ending timestamp in seconds without millisecondsRrdException
- Thrown if invalid timestamps are suppliedpublic DataProcessor(Date d1, Date d2) throws RrdException
processData()
method.d1
- Starting dated2
- Ending dateRrdException
- Thrown if invalid timestamps are suppliedpublic DataProcessor(Calendar gc1, Calendar gc2) throws RrdException
processData()
method.gc1
- Starting Calendar dategc2
- Ending Calendar dateRrdException
- Thrown if invalid timestamps are suppliedpublic boolean isPoolUsed()
RrdDbPool
usage policy.public void setPoolUsed(boolean poolUsed)
RrdDbPool
usage policy.poolUsed
- true, if the pool should be used to fetch data from RRD files, false otherwise.public void setPixelCount(int pixelCount)
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.
The default number of pixels is defined by constant DEFAULT_PIXEL_COUNT
and can be changed with a setPixelCount(int)
method.
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)
"By default rrdgraph calculates the width of one pixel in the time domain and tries to get data at that resolution from the RRD. With this switch you can override this behavior. If you want rrdgraph to get data at 1 hour resolution from the RRD, then you can set the step to 3600 seconds. Note, that a step smaller than 1 pixel will be silently ignored."
I think this option is not that useful, but it's here just for compatibility.
step
- Time step at which data should be fetched from RRD files. If this method is not used,
the step will be equal to the smallest RRD step of all processed RRD files. If no RRD file is processed,
the step will be roughly equal to the with of one graph pixel (in seconds).public long getStep()
processData()
is finished, the method will return the real value used for
all internal computations. Roughly corresponds to the --step option in RRDTool's graph/xport commands.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 resoltuion) in seconds.public long getEndingTimestamp()
processData()
method returns. The real
value will be calculated from the last update times of processed RRD files.public long[] getTimestamps() throws RrdException
processData()
method.RrdException
- thrown if timestamps are not calculated yetpublic double[] getValues(String sourceName) throws RrdException
getTimestamps()
method.sourceName
- Datasource nameRrdException
- Thrown if invalid datasource name is specified,
or if datasource values are not yet calculated (method processData()
was not called)public double getAggregate(String sourceName, String consolFun) throws RrdException
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 ConsolFuns
class)RrdException
- Thrown if invalid datasource name is specified,
or if datasource values are not yet calculated (method processData()
was not called)public Aggregates getAggregates(String sourceName) throws RrdException
sourceName
- Datasource nameRrdException
- Thrown if invalid datasource name is specified,
or if datasource values are not yet calculated (method processData()
was not called)public double get95Percentile(String sourceName) throws RrdException
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 nameRrdException
- Thrown if invalid source name is suppliedpublic double getPercentile(String sourceName) throws RrdException
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 nameRrdException
- Thrown if invalid source name is suppliedpublic double getPercentile(String sourceName, double percentile) throws RrdException
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.RrdException
- Thrown if invalid sourcename is supplied, or if the percentile value makes no sense.public String[] getSourceNames()
public double[][] getValues() throws RrdException
getTimestamps()
method.RrdException
- Thrown if invalid datasource name is specified,
or if datasource values are not yet calculated (method processData()
was not called)public void addDatasource(String name, Plottable plottable)
plottable
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 addDatasource(String name, String rpnExpression)
RPN
expression.
Complex source name
can be used:
JRobin supports the following RPN functions, operators and constants: +, -, *, /, %, SIN, COS, LOG, EXP, FLOOR, CEIL, ROUND, POW, ABS, SQRT, RANDOM, LT, LE, GT, GE, EQ, IF, MIN, MAX, LIMIT, DUP, EXC, POP, UN, UNKN, NOW, TIME, PI, E, AND, OR, XOR, PREV, PREV(sourceName), INF, NEGINF, STEP, YEAR, MONTH, DATE, HOUR, MINUTE, SECOND, WEEK, SIGN and RND.
JRobin 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 containig comma (or space) delimited simple and complex
source names, RPN constants, functions and operators.public void addDatasource(String name, String defName, String consolFun)
name
- source name.defName
- Name of the datasource to calculate the value from.consolFun
- Consolidation function to use for value calculationpublic void addDatasource(String name, String file, String dsName, String consolFunc)
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 RRD
file ("AVERAGE", "MIN", "MAX" or "LAST" - these string constants are conveniently defined
in the ConsolFuns
class).public void addDatasource(String name, String file, String dsName, String consolFunc, String backend)
Adds 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 ConsolFuns
class).backend
- Name of the RrdBackendFactory that should be used for this RrdDb.public void addDatasource(String name, FetchData fetchData)
name
- Source name.fetchData
- Fetched data containing values for the given source name.public void addDatasource(String name, String sourceName, double percentile)
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 datasourcepublic void addDatasource(String name, String sourceName, double percentile, boolean ignorenan)
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 datasourceignorenan
- - true if we include Double.NaNpublic void processData() throws IOException, RrdException
IOException
- Thrown in case of I/O error (while fetching data from RRD files)RrdException
- Thrown in case of JRobin specific errorpublic double[] getValuesPerPixel(String sourceName, int pixelCount) throws RrdException
getTimestampsPerPixel()
method.sourceName
- Datasource namepixelCount
- Graph widthRrdException
- Thrown if datasource values are not yet calculated (method processData()
was not called)public double[] getValuesPerPixel(String sourceName) throws RrdException
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 nameRrdException
- 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() throws RrdException
RrdException
- Thrown if nothing is calculated so far (the method processData()
was not called).public long getLastRrdArchiveUpdateTime()
public static void main(String[] args) throws IOException, RrdException
args
- Not usedIOException
- if an I/O error occurs.RrdException
- Thrown if internal jrobin error occurs.