JRobin – a quick and easy graphing tool

So, finally got around to playing with JRobin, and I’m pretty impressed. To those who don’t know, JRobin is a re-implementation of RRDTool, a data storing and graphing utility, in pure Java (The original is your standard configure, make, make install C jobby).

Anyone who has worked in Network Management has almost certainly encountered RRDTool – its a nice generic tool to store arbitrary numeric data without having to worry about files growing without bound, due to its trick of being able to aggregate data as time goes by. Because of its command line interface, it can be grafted into any little sysadmin script to produce graphs on pretty much any aspect of a system.

I’ve been a big user of it in the past, mainly with Perl. RRDTool comes with Perl bindings which makes it pretty convenient. Similar bindings have existed for Java, but the need to manually compile up RRDTool for your particular platform has detracted somewhat from the run-anywhere Java thing!

JRobin is a re-implementation of RRDTool in pure java. So, bundle the JAR up and it should just work, no matter where your application runs.

I’ve just hacked together a quick app that reads in a log file and produces a graph, and the process is pretty painless. Loading up my log file (of timestamp, value pairs) was done with the following:


while ((line = reader.readLine()) != null) {
StringTokenizer tokenizer = new StringTokenizer(line);
long time = Long.parseLong(tokenizer.nextToken());
double value = Double.parseDouble(tokenizer.nextToken());
Sample sample = db.createSample();
sample.setTime(time);
sample.setValue("temp", value);
sample.update();
}

And producing a JPanel containing a graph is even easier!


RrdGraphDef def = new RrdGraphDef();
def.setTimePeriod(Util.getTimestamp(2004,9,01), Util.getTimestamp(2004,10,4));
def.setVerticalLabel("Degrees");
def.setTitle("Computer Room temperature");
def.datasource("t", RRDFILENAME, "temp", "AVERAGE");
def.area("t", new Color(0xFF,0,0),"Temperature");
def.gprint("t", "AVERAGE","Avg temp: @3@r");
def.setLowerLimit(0L);
RrdGraph g = new RrdGraph(def);
JPanel p = g.getChartPanel();

Pretty straightforward, Huh?!

Now, if its graphs you’re after, bear in mind that JRobin is not designed to produce 101 different types of 3D, animated, translucent graphs – you get a basic line graph, and thats it (although its perfectly servicable, and not unattractive). If you want fancy graphs, you’re better of storing the data yourself and using JFreeChart.

One final little thing, in this already overly-long post. As someone who does a lot of Perl code (and is imbued with some of that culture), I’ve gotta say its refreshing to be able to produce my graph without a single Factory, or Delegate, or Proxy in sight. I mean, don’t get me wrong – I love my Design Patterns – but sometimes you just want to write code. You know what I mean? ;)

4 Responses to “JRobin – a quick and easy graphing tool”

  1. Mathias Bogaert says:

    You might wanna check out RRD4J: https://rrd4j.dev.java.net

  2. Ayman says:

    Have you come across a Javadoc for JRobin. For instance, what are the arguments to the method RrdDB.getArchive()?

    Thanks,
    ++Ayman

  3. dasman says:

    Sorry Ayman. The website http://oldwww.jrobin.org/api/ has some code snippets on performing typical tasks which are enough for getting up and running, but as you’ve probably already discovered, the Javadoc link gives a “Page Not Found”.

    It might be worth getting in touch with the authors?

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image