JRobin :: RRDTool Choice for the Java World :: Quick reference(转自http://www.360doc.com/content/11/0)

9 篇文章 0 订阅
4 篇文章 0 订阅

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.rrdRrdDef rrdDef = new RrdDef("test.rrd");
--start 1000111222rrdDef.setStartTime(1000111222L);
--step 300rrdDef.setStep(300);
DS:input:COUNTER:600:0:UrrdDef.addDatasource("input", "COUNTER", 600, 0, Double.NaN);
RRA:AVERAGE:0.5:6:700rrdDef.addArchive("AVERAGE", 0.5, 6, 700)
[Enter]RrdDb rrdDb = new RrdDb(rrdDef);

UPDATE

rrdtool update test.rrdRrdDb rrdDb = new RrdDb("test.rrd");
Sample sample = rrdDb.createSample();
1000111222:23.45:Usample.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.rrdRrdDb rrdDb = new RrdDb("test.rrd");
[Enter]long lastUpdateTime = rrdDb.getLastUpdateTime();

FETCH

rrdtool fetch test.rrdRrdDb 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 200int 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_pathdef.setBackground("image_path");
--color BACK#FF0080def.setBackColor(new Color(0xFF, 0x00, 0x80));
--color CANVAS#FF0080def.setCanvasColor(new Color(0xFF, 0x00, 0x80));
--base 1024def.setBaseValue(1024);
--units-exponent 6def.setUnitsExponent(6);
--no-legenddef.setShowLegend(false);
DEF:in=traffic.rrd:input:AVERAGEdef.datasource("in", "traffic.rrd", "input", "AVERAGE");
CDEF:in1=in,8,*def.datasource("in1", "in,8,*");
CDEF:in2=rpn_expressiondef.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:AVERAGEdef.datasource("xval", "test.rrd", "x", "AVERAGE");
XPORT:xval:"X values"def.export("xval", "X values");
--maxrows 100RrdExport 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 should be your first choice. However, JRobin supports GIF and JPEG formats too.
(***) JRobin's RRDToolkit class is not fully compatible with rrdtool tune command but has some interesting features (to add/remove datasource/archive for example) that cannot be found in RRDTool. 


Copyright ? 2003, 2004 Sasa Markovic & Arne Vandamme. All Rights Reserved.

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值