rrdtool简单教程

rrdtool教程

介绍:

RRDtool是代表 “Round Robin Database tool” 。

所谓的“Round Robin” 其实是一种存储数据的方式,使用固定大小的空间来存储数据,并有一个指针指向最新的数据的位置。我们可以把用于存储数据的数据库的空间看成一个圆,上面有很多刻度。这些刻度所在的位置就代表用于存储数据的地方。所谓指针,可以认为是从圆心指向这些刻度的一条直线。指针会随着数据的读写操作自动移动。要注意的是,这个圆没有起点和终点,所以指针可以一直移动,而不用担心到达终点后就无法前进的问题。在一段时间后,当所有的空间都存满了数据,就又从头开始存放。这样整个存储空间的大小就是一个固定的数值。所以RRDtool就是使用类似的方式来存放数据的工具,RRDtool所使用的数据库文件的后缀名是 ‘.rrd’。

要加深理解rrdtool的使用,可以先了解round robin database的原理及存储结构。

rrd文件结构:

char cookie[4]

‘RRD\0′

RRD文件标志

char version[5]

’0003\0′

RRD文件版本

double float_cookie

8.642135E130

Magic number

unsigned long ds_cnt

定义的DS个数

unsigned long rra_cnt

定义的RRA个数

unsigned long pdp_step

pdp时间间隔

unival par[10]

保留,未使用

char ds_nam[DS_NAM_SIZE]

DS的名称,DS_NAM_SIZE=20

%19[a-zA-Z0-9_-]

char dst[DST_SIZE]

DS的类型,DST_SIZE=20。%19[A-Z]

目前有5种:

GAUGE COUNTER

DERIVE ABSOLUTE

COMPUTE

unival par[10]

DS的参数队列,

前4种的参数有:heartbeat:min:max

后1种的参数有:rpn-expression

. . . . . .

ds_cnt

char cf_nam[CF_NAM_SIZE]

CF的名称,CF_NAM_SIZE=20,%19[A-Z]

目前有9种:

AVERAGE, MIN, MAX, LAST

HWPREDICT , SEASONAL

DEVPREDICT , DEVSEASONA

FAILURES

unsigned long row_cnt

存储记录的行数,超过后会循环覆盖

unsigned long pdp_cnt

cf函数执行时,需要的pdp个数

unival par[MAX_RRA_PAR_EN]

RRA的参数队列,MAX_RRA_PAR_EN=10

. . . . . .

rra_cnt

time_t last_up

最后一次更新的秒数部分

long last_up_usec

最后一次跟新的微秒数部分

char last_ds[LAST_DS_LEN]

最后一次更新后ds的值

LAST_DS_LEN=30

unival scratch[10]

最后一次更新后pdp的相关数值,包括:

PDP_unkn_sec_cnt,此次step以来未知的秒数

PDP_val,此次step的pdp值,根据dst的不同,

算法也不相同

. . . . . .

ds_cnt

Unival scratch[MAX_CDP_PAR_EN]

最后一次更新后cdp的相关数值

. . . . . .

ds_cnt

*

rra_cnt

unsigned long cur_row

指向RRA当前的记录

. . . . . .

rra_cnt

*RRA 0

(0,0) . . . . . . . . . . . . . . . . . . . . . . . . . ( ds_cnt -1 , 0)

.

.

.

(0, row_cnt -1) . . . . . . . . . . . (ds_cnt -1, row_cnt -1)

*RRA 1

*RRA 2

*RRA rra_cnt -1

RRD术语:

ds:   Data Source (ds) providing input to the database.

dst: Data Source Type (dst).

pdp: Primary Data Point (pdp).

cf:   Consolidation Function (cf).

cdp: Consolidated Data Point (cdp) is the long term storage format for data in the rrd database.

rra: Round Robin Archive (rra). This is the place where the consolidated data points (cdp) get stored.

Create语法:

rrdtool create filename [--start|-b start time] [--step|-s step] \

[DS:ds-name:DST:dst arguments] \

[RRA:CF:cf arguments]

step:Specifies the base interval in seconds with which data will be fed into the RRD。

dst argumet: 有heartbeat:min:max组成。其中最小,最大值表示pdp的范围,可以为UNKNOW。heartbeat:表示2次采样之间最大有效的时间间隔。

CHANGELOG:

Rrdtool-1.2.28后,对pdp的取UNKNOW值有点不同。查看了changelog,原来是作为bug修复了。

参考:

http://www.rrdtool.org

http://bbs.chinaunix.net/viewthread.php?tid=864861&highlight=rrdtool

 

Tags:

Leave a Reply

Powered by WP Hashcash