简体   繁体   English

RRD错误值

[英]RRD wrong values

I'm playing with RRDTool, but it shows wrong values. 我在玩RRDTool,但显示错误的值。 I have little python script: 我有一点python脚本:

import sys
import rrdtool
import time

i = 0

rrdtool.create(
    'tempo.rrd',
    '--step', '10',
    'DS:temp:GAUGE:20:-40:100',
    'RRA:LAST:0.5:1:1500'
)

while 1:
    ret = rrdtool.update('tempo.rrd','N:' + `i`);
    print "i %i" % i

    rrdtool.graph(
    'test.png',
    '--imgformat', 'PNG',
    '--width', '540',
    '--height', '200',
    '--start', "-%i" % 60,
    '--end', "-1",
    '--vertical-label', 'Temperatura',
    '--title', 'Temperatura lauke',
    '--lower-limit', '-1',
    'DEF:actualtemp=tempo.rrd:temp:LAST',
    'LINE1:actualtemp#ff0000:Actual',
    'GPRINT:actualtemp:LAST:Actual %0.1lf C'
    )   

    i += 1

    time.sleep(10)

After inserting [0, 1, 2], I get graph with wrong values - http://i.imgur.com/rfWWDMm.png (sorry, I can't post images). 插入[0,1,2]后,出现图形值错误-http: //i.imgur.com/rfWWDMm.png (对不起,我无法发布图像)。 As you see, after inserting 0, graph shows 0, after inserting 1, graph shows 0.8 and after inserting 2, graph shows 1.8. 如您所见,在插入0之后,图形显示0,在插入1之后,图形显示0.8,在插入2之后,图形显示1.8。 Sometimes after inserting 1, graph shows 0.6 and so on. 有时在插入1后,图形显示0.6,依此类推。 Am I doing something wrong? 难道我做错了什么?

This is how RRDtool works. 这就是RRDtool的工作方式。 RRDtool works with rates, exclusively. RRDtool仅适用于费率。 You can input gauge data (discrete values in time) but RRDtool will always treat them internally as rates. 您可以输入仪表数据(时间上的离散值),但RRDtool始终将其内部视为比率。

When you created your RRD file (tempo.rrd), internally RRDtool created buckets with a starting timestamp at creation time and each subsequent bucket +10s from that timestamp. 当您创建RRD文件(tempo.rrd)时,内部RRDtool创建的存储桶在创建时带有开始时间戳,而每个后续存储桶都从该时间戳开始+ 10s。 For example 例如

bucket 1    - 1379713706
bucket 2    - 1379713716
bucket 3    - 1379713726
...
bucket 100  - 1379714706
bucket 101  - 1379714716
bucket 102  - 1379714726

If you were to insert your integer values at exactly the timestamps matching the buckets, you'd be ok but you're not. 如果要在恰好与存储桶匹配的时间戳上插入整数值,则可以,但不行。 Your script is inserting values using the current timestamp which is almost certainly not going to be equal to a bucket value. 您的脚本正在使用当前时间戳插入值,该时间戳几乎肯定不会等于存储桶值。 Hypothetically, lets say current timestamp is 1379714708 and you want to insert a value of 2. When you insert your value, RRDtool needs to choose which bucket to put it in. In this case 1379714706 is the nearest so it will choose that one (there's a bit more logic here but that's the gist). 假设,假设当前时间戳为1379714708,而您想插入一个值2。当您插入值时,RRDtool需要选择放入哪个存储桶。在这种情况下,1379714706是最接近的存储桶,因此它将选择一个(存在这里有更多逻辑,但这是要点)。 You might think it would insert '2' into the bucket, but to RRDtool, that would be a lie. 您可能会认为它将在存储桶中插入“ 2”,但是对于RRDtool来说,这是一个谎言。 It might be 2 now, but it probably wasn't 2 a few seconds ago. 现在可能是2,但几秒钟前可能不是2。 Bearing in mind that it sees all these values as rates, it tries to figure out how much it should subtract from that value to make it right by looking at the rate of change of previous values That's why you see values such as 1.8 and 2.8 and not the integer values you expect. 请记住,它将所有这些值都视为比率,它会尝试通过查看先前值的变化率来找出应该从该值中减去多少才能正确处理。这就是为什么您看到诸如1.8和2.8以及不是您期望的整数值。 Things get more complicate if you insert multiple values between buckets or skip buckets. 如果在存储桶或跳过存储桶之间插入多个值,事情会变得更加复杂。

There's an excellent tutorial at http://oss.oetiker.ch/rrdtool/tut/rrdtutorial.en.html that goes into more detail. http://oss.oetiker.ch/rrdtool/tut/rrdtutorial.en.html上有一个很棒的教程,其中有更详细的介绍。

I don't know to what extent this will match your needs, but this is how I trick my graphs to display a discrete number of users connected to my system: I use the CEIL arithmetic operator . 我不知道这在多大程度上可以满足您的需求,但这是我如何欺骗我的图表以显示连接到系统的离散用户数量的方法:我使用CEIL算术运算符 It is not meant to be accurate, only to be more satisfying to the eye than 0.324 online user. 这并不意味着准确,仅是比0.324在线用户更为满意。

Based on what the tool I use to manipulate the rrds spits out as a command line, I expect your code to look like 根据我用来操纵rrds的工具作为命令行吐出的内容,我希望您的代码看起来像

rrdtool.graph(
'test.png',
'--imgformat', 'PNG',
'--width', '540',
'--height', '200',
'--start', "-%i" % 60,
'--end', "-1",
'--vertical-label', 'Temperatura',
'--title', 'Temperatura lauke',
'--lower-limit', '-1',
'DEF:actualtemp=tempo.rrd:temp:LAST',
'CDEF:ACTUALTEMP=actualtemp,CEIL',
'LINE1:ACTUALTEMP#ff0000:Actual',
'GPRINT:ACTUALTEMP:LAST:Actual %0.1lf C'
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM