Jrobin: rrdtool choice for the Java World: Quick Reference (from http://www.360doc.com/content/11/0)

Source: Internet
Author: User

Quick Reference

Here is the list of some most commonly used rrdtool commands and command line switches with a proper translation to Java (jrobin API). It's quite straightforward:

Rrdtool command...

... In jrobin API

Create

rrdtool create test.rrd RrdDef rrdDef = new RrdDef("test.rrd");
--start 1000111222 rrdDef.setStartTime(1000111222L);
--step 300 rrdDef.setStep(300);
DS:input:COUNTER:600:0:U rrdDef.addDatasource("input", "COUNTER", 600, 0, Double.NaN);
RRA:AVERAGE:0.5:6:700 rrdDef.addArchive("AVERAGE", 0.5, 6, 700)
[Enter] RrdDb rrdDb = new RrdDb(rrdDef);

Update

rrdtool update test.rrd RrdDb rrdDb = new RrdDb("test.rrd");
Sample sample = rrdDb.createSample();
1000111222:23.45:U sample.setTime(1000111222L);
sample.setValue(0, 23.45);
sample.setValue(1, Double.NaN);
-t input:output 
1000111222:12.345:U
sample.setTime(1000111222L);
sample.setValue("input", 12.345);
sample.setValue("output", Double.NaN);
[Enter] sample.update();

Last

rrdtool last test.rrd RrdDb rrdDb = new RrdDb("test.rrd");
[Enter] long lastUpdateTime = rrdDb.getLastUpdateTime();

Fetch

rrdtool fetch test.rrd RrdDb rrdDb = new RrdDb("test.rrd");
AVERAGE
--start 1000111222 
--end 1000222333
FetchRequest req = rrdDb.createFetchRequest("AVERAGE",
1000111222L, 1000222333L);
AVERAGE
--start 1000111222 
--end 1000222333 
--resolution 600
FetchRequest req = rrdDb.createFetchRequest("AVERAGE",
1000111222L, 1000222333L, 600);
[Enter] FetchData fetchData = req.fetchData();

Dump

rrdtool dump 
test.rrd > test.xml
RrdDb rrdDb = new RrdRb("test.rrd");
[Enter] rrdDb.dumpXml("test.xml");

Restore

rrdtool restore 
new.rrd old.xml
[Enter]

RrdDb rrdDb = new RrdDb("new.rrd" "old.xml");

Graph

rrdtool graph 
traffic.png
RrdGraphDef def = new RrdGraphDef();
String pngFile = "traffic.png";
--start 1000111222 
--end 1000222333
def.setTimePeriod(1000111222L, 1000222333L);
--start "10/25/2003" 
--end "10/28/2003"

def.setTimePeriod(Util.getTimestamp(2003, 9, 25), 
Util.getTimestamp(2003, 9, 28));*

-w 400 -h 200 int pngWidth = 400, pngHeight = 200;
-v "this is y-axis" def.setVerticalLabel("this is y-axis");
-t "this is graph title" def.setTitle("this is graph title");

--lower-limit 1000.0
--upper-limit 2000.0
--rigid

def.setGridRange(1000.0, 2000.0, true);
--background image_path def.setBackground("image_path");
--color BACK#FF0080 def.setBackColor(new Color(0xFF, 0x00, 0x80));
--color CANVAS#FF0080 def.setCanvasColor(new Color(0xFF, 0x00, 0x80));
--base 1024 def.setBaseValue(1024);
--units-exponent 6 def.setUnitsExponent(6);
--no-legend def.setShowLegend(false);
DEF:in=traffic.rrd:input:AVERAGE def.datasource("in", "traffic.rrd", "input", "AVERAGE");
CDEF:in1=in,8,* def.datasource("in1", "in,8,*");
CDEF:in2=rpn_expression def.datasource("in2", "rpn_expression");
LINE1:in#0000FF:"input" def.line("in", new Color(0, 0, 0xFF), "input");
AREA:in1#00FF00:"input 1" def.area("in1", new Color(0, 0xFF, 0), "input 1");
STACK:in2#FFFF00:"input 2\r" def.stack("in2", new Color(0xFF, 0xFF, 0), "input 2@r");
COMMENT:"This is a comment" def.comment("This is a comment");
GPRINT:in:AVERAGE:
"avg=%.2lf %sbits/sec"
def.gprint("in", "AVERAGE", "avg=@2 @sbits/sec");
GPRINT:in1:MAX:
"avg1=%5.2lf %Sbits/sec\r"
def.gprint("in1", "MAX", "avg1=@5.2 @Sbits/sec@r);
[Enter] RrdGraph g = new RrdGraph(def);
g.saveAsPNG(pngFile, pngWidth, pngHeight);**

Xport

rrdtool xport
--start 1000111222
--end 1000222333
RrdExportDef def = 
new RrdExportDef(1000111222L, 1000222333L);
DEF:xval=test.rrd:x:AVERAGE def.datasource("xval", "test.rrd", "x", "AVERAGE");
XPORT:xval:"X values" def.export("xval", "X values");
--maxrows 100 RrdExport export = new RrdExport(def);
ExportData data = export.fetch(100);
[Enter] System.out.println(data.exportXml());

Tune ***

rrdtool tune file.rrd
--heartbeat input:600 
RrdToolkit toolkit = RrdToolkit.getInstance();
toolkit.setDsHeartbeat("file.rrd", "input", 600);
rrdtool tune file.rrd
--maximum input:10000
RrdToolkit toolkit = RrdToolkit.getInstance();
toolkit.setDsMaxValue("file.rrd", "input", 10000, false);

Simple, isn' t it?

(*)Java months are zero based.
(**)PNG format shocould be your first choice. However, jrobin supports GIF and JPEG formats too.
(***)Jrobin's rrdtoolkit class is not fully compatibleRrdtool tuneCommand but has some interesting features (to Add/Remove datasource/archive
For example) that cannot be found in rrdtool.

Copyright? 2003,200 4 Sasa Markovic & Arne VANDAMME. All rights reserved.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.