rrd
Class Rrd

java.lang.Object
  |
  +--rrd.Rrd

public class Rrd
extends java.lang.Object

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:

Some 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.

Version:
1.0.1 (Feb 17, 2003)

Author:
Sasa Markovic
sasam@dnseurope.co.uk


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

getInstance

public static Rrd getInstance()
Returns single Rrd class instance for further usage. Rrd class follows the singleton pattern. Only one Rrd instance exists during the lifetime of application. This instance processes all RRD commands through synchronized methods.

Returns:
Rrd class instance to be used for RRD commands execution.

create

public void create(java.lang.String rrdCmd)
            throws RrdException
Executes RRDCREATE command. This method is synchronized because RRD commands must be handled one by one.

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);
 

Parameters:
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.
Throws:
RrdException - Exception thrown if create command fails.

update

public void update(java.lang.String rrdCmd)
            throws RrdException
Executes RRDUPDATE command. This method is synchronized because RRD commands must be handled one by one.

Example:

 String cmd = "update temperatures.rrd 1004243132:32:46";
 Rrd.getInstance().update(cmd);
 

Parameters:
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.
Throws:
RrdException - Exception thrown if update command fails.

graph

public java.lang.String[] graph(java.lang.String rrdCmd)
                         throws RrdException
Executes RRDGRAPH command. This method is synchronized because RRD commands must be handled one by one.

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);
 

Parameters:
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.
Returns:
String array containing lines of text normaly printed on stdout. RRDGRAPH is used not only to create graphs but to perform various calculations. Those calculations are usually printed on the graph itself (GPRINT directives, see example above), or to standard output (PRINT directives). graph() method intercepts information that should be printed to stdout and returns it as array of Strings (one string represents one PRINT directive).
Throws:
RrdException - Exception thrown if graph command fails.

last

public long last(java.lang.String rrdCmd)
          throws RrdException
Executes RRDLAST command. This method is synchronized because RRD commands must be handled one by one.

Example:

 String cmd = "last temperatures.rrd";
 long timestamp = Rrd.getInstance().last(cmd);
 

Parameters:
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.
Returns:
UNIX timestamp of the last successful update() call.
Throws:
RrdException - Exception thrown if command fails.

fetch

public Rrd.FetchData fetch(java.lang.String rrdCmd)
                    throws RrdException
Executes RRDFETCH command. This method is synchronized because RRD commands must be handled one by one.

Example:

 String cmd = "fetch temperatures.rrd AVERAGE --start 1000000000 --end 1000086400";
 rrd.Rrd.FetchData data = Rrd.getInstance().fetch(cmd);
 

Parameters:
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.
Returns:
Read only object of class Rrd.FetchData representing data fetched from the database.
Throws:
RrdException - Exception thrown if command fails.