|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--rrd.Rrd
Java wrapper for Tobi Oetiker's RRDTOOL. RRDTOOL is an excelent implementation of the so-called round robin database (RRD) concept. Here is a short comment on RRDTOOL from the author:
It is pretty easy to gather status information from all sorts of things, ranging from the temperature in your office to the number of octets which have passed through the FDDI interface of your router. But it is not so trivial to store this data in a efficient and systematic manner. This is where rrdtool kicks in. It lets you log and analyze the data you gather from all kinds of data-sources. The data analysis part of rrdtool is based on the ability to quickly generate graphical representations of the data values collected over a definable time period.
This class is part of RRDJTool package freely available from http://marvin.datagate.co.yu:8081/rrdjtool.
RRDTOOL is written in C and comes with language bindings for Tcl, Perl, PHP... but not for Java. If you want to use Oetiker's code from Java, you are forced to use his command line utilities through inefficient System.exec() calls.
Rrd class uses Java Native Interface (JNI) approach to provide very fast, simple and efficient RRD operation from your Java code. At the moment, RRD JNI is tested on Linux platform only. Bad news: Before you start using Rrd.class you have to recompile Rrd.c for your platform. The file can be found in the /native directory of this source code distribution. Makefile for Linux is provided.
Rrd class has several methods to support the most important functionality of RRDTOOL:
create
RRD databaseupdate
databasegraph
generationfetch
data from the databaselast
database update timeSome less important RRDTOOL operations are not supported, and probably never will be (dump>, restore, tune...). These operations are used so rarely that it would be a waste of time to provide java support for them.
All public methods are synchronized: RRD commands get processed one by one.
IMPORTANT: If you want to use Rrd.class, two shared libraries must be present in your sistem:
Be sure to set your LD_LIBRARY_PATH environment variable so that both librrd.so and libjrrd.so can be found by JVM. Alternatively, you could place both shared libraries in your standard library directory.
Before you use Rrd class, try RrdDemo
.
If it runs without exceptions, you are ready to use the full power of RRDTool
from the comfortable environment of Java.
Nested Class Summary | |
class |
Rrd.FetchData
Inner class to hold information returned by Rrd.fetch() . |
Method Summary | |
void |
create(java.lang.String rrdCmd)
Executes RRDCREATE command. |
Rrd.FetchData |
fetch(java.lang.String rrdCmd)
Executes RRDFETCH command. |
static Rrd |
getInstance()
Returns single Rrd class instance for further usage. |
java.lang.String[] |
graph(java.lang.String rrdCmd)
Executes RRDGRAPH command. |
long |
last(java.lang.String rrdCmd)
Executes RRDLAST command. |
void |
update(java.lang.String rrdCmd)
Executes RRDUPDATE command. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static Rrd getInstance()
public void create(java.lang.String rrdCmd) throws RrdException
Example:
String cmd = "create temperatures.rrd --start 999999999 --step 300 " + "DS:temp1:GAUGE:1800:U:U " + "DS:temp2:GAUGE:1800:U:U " + "RRA:AVERAGE:0.5:1:600 RRA:AVERAGE:0.5:6:700 " + "RRA:AVERAGE:0.5:24:700 RRA:AVERAGE:0.5:288:700 "; Rrd.getInstance().create(cmd);
rrdCmd
- RRD command to execute. This command should follow exactly the same
formatting rules as Oetiker's rrdcreate command line utility
(see man rrdcreate). The command must start with create.
RrdException
- Exception thrown if create command fails.public void update(java.lang.String rrdCmd) throws RrdException
Example:
String cmd = "update temperatures.rrd 1004243132:32:46"; Rrd.getInstance().update(cmd);
rrdCmd
- RRD command to execute. This command should follow exactly the same
formatting rules as Oetiker's rrdupdate command line utility
(see man rrdupdate). The command must start with update.
RrdException
- Exception thrown if update command fails.public java.lang.String[] graph(java.lang.String rrdCmd) throws RrdException
Example:
String cmd = "graph temperatures.png -s 1000000000 -e 1000086400 -a PNG " + "-w 450 -h 250 -t \"Moon temperatures\" " + "-v \"Measured temperature\" " + "DEF:temp1=temperatures.rrd:temp1:AVERAGE " + "DEF:temp2=temperatures.rrd:temp2:AVERAGE " + "AREA:temp1#FF0000:shade " + "GPRINT:temp1:AVERAGE:\"average %.2lf\\l\" " + "LINE1:temp2#0000FF:sunshine " + "GPRINT:temp2:AVERAGE:\"average %.2lf\\l\" " + "PRINT:temp1:AVERAGE:%.2lf " + "PRINT:temp2:AVERAGE:%.2lf "; String[] printInfo = Rrd.getInstance().graph(cmd);
rrdCmd
- RRD command to execute. This command should follow exactly the same
formatting rules as Oetiker's rrdgraph command line utility
(see man rrdgraph). The command must start with graph.
RrdException
- Exception thrown if graph command fails.public long last(java.lang.String rrdCmd) throws RrdException
Example:
String cmd = "last temperatures.rrd"; long timestamp = Rrd.getInstance().last(cmd);
rrdCmd
- RRD command to execute. This command should follow exactly the same
formatting rules as Oetiker's rrdlast command line utility
(see man rrdlast). The command must start with last.
update()
call.
RrdException
- Exception thrown if command fails.public Rrd.FetchData fetch(java.lang.String rrdCmd) throws RrdException
Example:
String cmd = "fetch temperatures.rrd AVERAGE --start 1000000000 --end 1000086400"; rrd.Rrd.FetchData data = Rrd.getInstance().fetch(cmd);
rrdCmd
- RRD command to execute. This command should follow exactly the same
formatting rules as Oetiker's rrdfetch command line utility
(see man rrdfetch). The command must start with fetch.
Rrd.FetchData
representing data fetched
from the database.
RrdException
- Exception thrown if command fails.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |