RRD插入值的计算方式

RRD插入值的计算方式

 

正常情况:

设:正常每5秒更新一次,HB10,分别在第15秒时更新值1,第25秒时更新值2……

这样每次PDP都有值:

887457305: 1.0000000000e+00

 887457310: 2.0000000000e+00

 887457315: 3.0000000000e+00

 887457320: 4.0000000000e+00

 887457325: 5.0000000000e+00

 887457330: 6.0000000000e+00

 887457335: 7.0000000000e+00

 887457340: 8.0000000000e+00

设:第23次更新没有到来,4来时,距上一次更新已经过去15秒>HB,直接将第234次的PDP置为无效:

(这时就算在34之间再有值被插入结果也是一样,这是因为插入的值都将使HB超时,3值都将无效,同时此值也会被抛弃,不会影响4值的计算)

887457305: 1.0000000000e+00

 887457310: nan

 887457315: nan

 887457320: nan

 887457325: 5.0000000000e+00

 887457330: 6.0000000000e+00

 887457335: 7.0000000000e+00

 887457340: 8.0000000000e+00

设:4值晚一秒到来,即21秒,另,45之间有多个值:24秒的225秒的5(如小图):

它是按照权重计算的:4*1/5 + 2*3/5 + 5*1/5 = 3

887457305: 1.0000000000e+00

 887457310: nan

 887457315: nan

 887457320: nan

 887457325: 3.0000000000e+00

 887457330: 6.0000000000e+00

 887457335: 7.0000000000e+00

 887457340: 8.0000000000e+00

程序如下:

#!/bin/bash

rm -f ./1.rrd

ep="Jan 1, 1970 UTC"

start=`date -d "$ep+887457300 seconds" +%s`

echo $start

# create

rrdtool create ./1.rrd "

--start `expr $start` --step 5 "

DS:t1:GAUGE:10:U:U "

RRA:AVERAGE:0.5:1:43200

# add data

rrdtool update ./1.rrd `expr $start + 5`:1

#rrdtool update ./1.rrd `expr $start + 10`:2

rrdtool update ./1.rrd `expr $start + 18`:3

rrdtool update ./1.rrd `expr $start + 21`:4

rrdtool update ./1.rrd `expr $start + 2`:2

rrdtool update ./1.rrd `expr $start + 25`:5

rrdtool update ./1.rrd `expr $start + 30`:6

rrdtool update ./1.rrd `expr $start + 35`:7

rrdtool update ./1.rrd `expr $start + 40`:8

echo "***begin fetch***"

s2=0

rrdtool fetch ./1.rrd AVERAGE "

-r 5 --start `expr $start + $s2` --end `expr $start + $s2 + 60`





有兴趣可以访问下我的生活博客: qqmovie.qzone.com

你可能感兴趣的:(RRD插入值的计算方式)