about RRD

date +’%s‘ ---- 1970-1-1


rrdtool create test.rrd --start {date +'%s'} DS:speed:COUNTER:600:U:U RRA:AVERAGE:0.5:1:24 AVERAGE:0.5:6:10

rrd database created named test (test.rrd), its current start time is my time. Storing a database called 'speed' of the data source (DS), which represents a counter. The counter is read once every 5 minutes (default). In the same database, stores two annular archive (RRA), a is the average of each reading data (e.g.: nothing averaging) and keeps 24 samples (2 times 5 minutes 24 hours) . Another RRA 6 values ​​(half hour) and contains 10 such averages (e.g., 5 hours).


插入数据rrdtool update
 往rrd文件中插入数据的命令是rrdtool update

* update - update an RRD

rrdtool update filename
[--template|-t ds-name:ds-name:...]
[--daemon <address>]
time|N:value[:value...]

at-time@value[:value...]

[ time:value[:value...] ..]

两个主要选项一个就是数据源的顺序,这个顺序对应上后面需要插入数值的顺序,另一个就是"时间:值",当前时间可以用N代替

[root@localhost22 ~]# rrdtool update test.rrd N:`echo $RANDOM`

上面的只是更新一次数据,写个循环,让其不断更新

[root@localhost22 ~]# cat test.sh
while(true)
do
  sleep 3         //每隔3s插入数据
  rrdtool update test.rrd N:`echo $RANDOM`
done

然后执行该脚本,一段时间后,查看rrd文件 ,-r 2为解析度(表示两个PDP聚合,如果指定其他解析度是创建时RRA没有的,取相近的)

rrdtool graph speed.png --start {date +'%s'-3600000} --end {date +'%2'} DEF:myspeed=test.rrd:speed:AVERAGE LINE2:myspeed#FF0000

This will create an image file named speed.png, which starts at 12:00 and ends at 13:00. There called myspeed variable definitions, which uses data from the database test.rrd speed RRA in. 2 is a line drawn pixels high, represents the variable myspeed. Color is red.

First, tell us about this common syntax RRDtool options, you can read the rough, and then look at an example, in a careful study of grammar afterwards.
1. How to use rrdtool create various types, characteristics of ring RRD database.
rrdtool create filename [--start | -b start time] [--step | -s step] [DS: ds-name: DST: dst arguments]. net [RRA: CF: cf arguments ]
Description:
RRDtool to create a function to set a new RRD database files. This feature is created at the completion of all the documents are pre-populated UNKNOWN value.
filename
filename RRD need to create. RRD database file name should be .rrd extension. Although RRDtool can accept any file name.
--start | -b start time (default: now - 10s)
is set to join RRD database first time a data value - time since 1970-01-01 UTC time (in seconds). RRDtool will not accept any value at or earlier than the specified time.
--step | -s step (default: 300 seconds)
to specify the data to be filled in basic database RRD time interval (default is 300 seconds).
DS: ds-name: DST: dst arguments
single RRD database can accept input data from several sources. For example, into traffic on a given communication lines and the traffic. In the DS configuration options, you must specify some basic attributes stored in RRD data source for each.
ds-name you want to use a specific data source reference from one of the RRD. ds-name must be a length of 1-19 characters [a-zA-Z0-9] between.
DST data source definition type. Subsequent item parameter data source depends on the type of data source. For GAUGE, COUNTER, DERIVE, and the ABSOLUTE, the format which the data source is:
the DS: DS-name: GAUGE | the COUNTER | DERIVE | the ABSOLUTE: Heartbeat: min: max
For COMPUTE data source in the format:
the DS: DS-name : COMPUTE: rpn-expression
to determine what type of data source used, check the following definitions.
GAUGE
is like a thermometer, or number of people in a room, or shared values such thing in Redhat.
COUNTER
like routers ifInOctets counter it will continue incrementing counter. COUNTER data source is assumed that the computer never decreases unless an overflow. update feature may cause an overflow. The computer is stored according to the frequency of the second. When the counter overflows, the overflow checks whether RRDtool occur 32 or 64 bit boundary, and an appropriate value corresponding to the added result.
DERIVE
store the data source to the difference from the previous line. This is useful for gauges type, it can be used to measure the ratio of one out of the room. Inside derive, and COUNTER is almost the same, but there is no overflow checking. So, if you are not reset in the counter 32 or 64, you should use DERIVE value or with a mixture of 0 MIN.
About COUNTER vs DERIVE explanation
mistake if you do not allow the legitimate wrap reset a counter sporadic caused, but rather useunknowns‘ 来对表示所有计数器的合法回绕和复位,你就要使用min=0的DERIVE类型。否则,使用具有合理max的COUNTER类型,会为所有的合法计数器回绕返回正确的值。<br/>对于一个步长为5分钟的32位计数器,计数器回绕复位的错误概率大约为:每1Mbps的最大带宽发生概率为0.8%.注意这等价于100Mbps接口的80%,因此对于高带宽接口和32位计数器,最好使用带有min=0的DERIVE。如果你使用的是64位计数器,只有任何最大值的设定可以避免计数器回绕的错误发生的可能性。<br/>ABSOLUTE<br/>读取后马上复位的计数器。用于易于溢出的快速计数器。因此,不要常规地读取他们,你需要自每次读取后确认在下一次溢出前有一个最大的有效时间。该类型的另外一个用途是你需要累积上次更新以来的信息数目。<br/>COMPUTE<br/>用于存放对RRD中的其他数据源进行公式计算的结果。该数据源在更新时不需要提供数值,它是根据rpn-表达式定义的公式从数据源的PDPs中计算出来的PDP(Primary Data Point)。归并功能会被应用到COMPUTE数据源的PDPs上。在数据库软件中,此类数据集用Virtual 'or' calculation 'column represents.
heartbeat heartbeat defined between two update data source, the data source to determine the value for the maximum number of seconds allowed before UNKNOWN.
min and max defines the data sources, the expected range of values. Any more than min or max value range a value of a data source, will be considered as UNKNOWN. If you do not know or do not care mix and max, they will be set to unknown. Note that min and max values are always processed numerical data source. For a traffic counter type of DS, this rate can be expected in the data acquired from the device.
If the value of information is available min / max, the min and max must be set properties. This can help RRDtool data provided by the robust check on update.
rpn-expression defines calculated by computing RRD comes with a library of other data sources, PDPs a COMPUTE data sources formula. This is the same argument in graph CDEF command. See graph manual for a list and description of RPN operators. For COMPUTE data sources, the operator does not support the following RPN: COUNT, PREV, TIME, and LTIME. Further, when defining the RPN expression, the COMPUTE data source data source can only references listed in the create command. This is to limit the CDEF is the same, CDEF can only quote DEFs and CDEFs in the same graph commands previously defined.
RRA: CF: cf arguments
a RRD object is a ring in the data stored in the archive data. A large amount of statistical data archive or values of each data source has been defined, and it is defined in one row of RRA.
When data enters the RRD a database, the data is first filled into the slot with the steps defined in the -s option, the value becomes a pdp - first data point (Primary Data Point).
This data will be processed by the CF merge function archived. PDPs each merge function can be merged by such a polymerization several functions: AVERAGE, MIN, MAX, LAST like. The RRA merge function command line format is:
RRA: AVERAGE | MIN | MAX | LAST: xFF: Steps: rows
xFF
XFiles factor defines when a merge value is still unknown, UNKNOWN which data in a merge interval section can be used.
steps
define how many can be used to construct these data points merged in the PDP.
rows
define how many times the value of the data generated in a reserved RRA archive.
Examples Example. 1
RRDtool Create temperature.rrd the --step 300 \
the DS: TEMP: GAUGE: 600: -273: 5000 \
RRA: the AVERAGE: 0.5:. 1: 1200 \
RRA: MIN: 0.5: 12 is: 2400 \
RRA: MAX: 0.5: 12 is: 2400 \
RRA: the AVERAGE: 2400: 0.5: 12 is
example sets the called temperature.rrd on RRD, which receives a temperature value every 300 seconds. If no data is more than 600 seconds, the temperature value becomes UNKNOWN . -273 its minimum acceptable value, the maximum value of 5000.
In this example also defines several archive area. The temperature within the first 100 hours RRA archive storage area (1200300 seconds = 100 hours). The second storage hour RRA lowest temperature (12 300 seconds = 1 hour), a total of 100 days of data (2,400 hours) is stored. The third and fourth RRA were stored maximum temperature and average temperature.
2 cases
RRDtool Create proxy.rrd the --step 300 \
the DS: the Total: DERIVE: 1800: 0: the U-\
the DS: the Duration: DERIVE: 1800: 0: the U-\
RRA: the AVERAGE: 0.5:. 1: 2016
This example is a monitor Mean Web proxy request process (5 minutes) request every 300 seconds interval. In this embodiment, the agent has two counters, the number of requests after starting treatment, and the total cumulative number of processing requests. Clearly, these counters have a wrap-around point, but using DERIVE data source types also can handle reset in stop and restart the Web proxy when.
In the RRD database, storing the first type of data source is the number of requests per second during the interval. The second type of data source is divided by the total number of requests during the processing interval 300.
Update database 2.rrd ring:
RRDtool Update {|} updatev filename [--template | -t DS-name [: DS-name] ...] N | timestamp: value [: value ...] AT- @ value timestamp [: value ...] [timestamp: value [: value ...] ...]
filename: name of the RRD database to be updated.
--template | -t ds-name [: ds-name] ...: -t ds-name to update the name of the RRD database data source
N | timestamp: value [: value ...]: Time: To update the value of ...
Code:
$> timestamp = date -d "2003/08/15 12:00" +%s
3. How the drawing data in the database rrd ring collected
rrdtool graph filename [option ... ] [the Data Definition ...] [the Data Calculation ...] [variable Definition ...] [Graph Element ...] [Print Element ...]
filename you want to paint the picture name
time range time range
[-s | --start time] start time [-e | --end time] end time [-S | --step seconds] step
Labels
[-t | --title String] Image title [-v | --vertical -label string] Y-axis described
Size
[-w | width --width pixels] display region [-H | height --height pixels] display region [-j | --only-Graph]
Limits
[-u | - -upper-limit value] Y-axis height value [-l | --lower-limit value] Y -axis negative height [-R & lt | --rigid]
the Data Variables and
the DEF: vname = rrdfile: DS-name: CF2 [ : step = step] [: start = time] [: end = time]
CDEF: vname = RPN expression The
VDEF: vname = RPN expression The
main use is to explain that you want to remove the RRD file DSN to the graph of parameters to get a virtual CDEF by operation of variable ,, after its expression to be written in order EX: a = 1 + 3 written as a = 1,3 + LINE {1 | 2 | 3}: vname [#rrggbb [: legend]] LINE1: your_var # rgb color value: the legend, the "your_var" DEF required presence or CDEF in the declaration, AREA: vname [#rrggbb [: legend]] AREA draw sample values between 0 to the block diagram sTACK: vname [#rrggbb [: legend ]] sTACK superimposed on a pattern of values Note and requires extra care if you use AREA / STACK issue cover Figure Figure, be sure to draw large value, and then draw a small value, this will have an effect level, otherwise, the largest data if the last painting, will cover previous data COMMENT caption, such as COMMENT: "last Updated" to generate the text in the figure, can be \ n the like newline GPRINT GPRINT: vname: CF: format vname i.e. DEF in your_var, and CF see you want to output text is AVERAGE / MAX / MIN / LAST value, etc., format as the format printf, EX: GPRINT: telnet: AVERAGE : "% 10.0lf \ n" I.e., to be output this time (-s ~ -e, the mean value of telnet,% 10.0lf position is calculated to a good).

Guess you like

Origin blog.51cto.com/14142757/2427639