rrdtool 获取 returns None 对象
rrdtool fetch returns None object
我在 python 中使用 rrdtool 库。同样的 python 脚本一天前返回了数据,但现在它突然在生成的元组中返回 None 对象。 rrd 文件没有被修改。返回的类型是元组,如果得到 printed.Please 甚至是 rrdinfo,请花点时间研究它。
import sys
import pprint
sys.path.append('/opt/plexus-srv/rrdtool-1.4.9/lib64/python2.6/site-
packages')
import rrdtool
rrd_file = sys.argv[1]
rrd_info = rrdtool.info(rrd_file)
data = rrdtool.fetch(rrd_file,"AVERAGE")
print(type(data))
pp = pprint.PrettyPrinter(indent =4)
pp.pprint(data)
pp.pprint(rrd_info)
输出为:
<type 'tuple'>
('sum',)
1510142400
[(None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,)]
{ 'ds[sum].index': 0L,
'ds[sum].last_ds': '99.3',
'ds[sum].max': None,
'ds[sum].min': None,
'ds[sum].minimal_heartbeat': 120L,
'ds[sum].type': 'GAUGE',
'ds[sum].unknown_sec': 0L,
'ds[sum].value': 1290.8999999999999,
'filename': '/home/u43555766/aad/plexus/rrdsample/testing/cpu/cpu_idle.rrd',
'header_size': 1416L,
'last_update': 1510030543L,
'rra[0].cdp_prep[0].unknown_datapoints': 0L,
'rra[0].cdp_prep[0].value': None,
'rra[0].cf': 'AVERAGE',
'rra[0].cur_row': 49L,
'rra[0].pdp_per_row': 1L,
'rra[0].rows': 490L,
'rra[0].xff': 0.5,
'rra[1].cdp_prep[0].unknown_datapoints': 0L,
'rra[1].cdp_prep[0].value': 198.78666666666669,
'rra[1].cf': 'AVERAGE',
'rra[1].cur_row': 2264L,
'rra[1].pdp_per_row': 4L,
'rra[1].rows': 2890L,
'rra[1].xff': 0.5,
'rra[2].cdp_prep[0].unknown_datapoints': 0L,
'rra[2].cdp_prep[0].value': 198.78666666666669,
'rra[2].cf': 'AVERAGE',
'rra[2].cur_row': 873L,
'rra[2].pdp_per_row': 20L,
'rra[2].rows': 2026L,
'rra[2].xff': 0.5,
'rra[3].cdp_prep[0].unknown_datapoints': 0L,
'rra[3].cdp_prep[0].value': 22058.293333333328,
'rra[3].cf': 'AVERAGE',
'rra[3].cur_row': 387L,
'rra[3].pdp_per_row': 240L,
'rra[3].rows': 754L,
'rra[3].xff': 0.5,
'rra[4].cdp_prep[0].unknown_datapoints': 0L,
'rra[4].cdp_prep[0].value': 117354.74000000028,
'rra[4].cf': 'AVERAGE',
'rra[4].cur_row': 214L,
'rra[4].pdp_per_row': 5760L,
'rra[4].rows': 375L,
'rra[4].xff': 0.5,
'rrd_version': '0003',
'step': 15L}
问题最明显的答案是return没有数据。
您没有说明是否以及如何将数据添加到 RRD 文件中。由于您的 'fetch' 调用没有任何参数来指定分辨率、开始或结束,因此它可能会默认为一天,现在结束,5 分钟分辨率。您确实有匹配的 RRA,但我们不知道那里是否有任何数据。
查看您提供的数据,您似乎 运行 在时间 1510142400 获取数据,但 RRD 最后更新时间为 1510030543,大约早了 31 小时。可能没有最后一天的数据?
从命令行尝试 运行 'rrdtool fetch' 和 'rrdtool dump',并验证是否存储了数据,并且它们适合您认为的时间。也许将附加参数传递给 'fetch' 以指定步骤、开始和结束。
我是 rrdtool 的新手,所以没有意识到我已经错过了收集数据的开始时间。这些文件几天前来自服务器。获取命令缺少“-s”时间,因此打印了 None 对象。添加“-s”和“-96h”打印数据。感谢@steve-shipway
我在 python 中使用 rrdtool 库。同样的 python 脚本一天前返回了数据,但现在它突然在生成的元组中返回 None 对象。 rrd 文件没有被修改。返回的类型是元组,如果得到 printed.Please 甚至是 rrdinfo,请花点时间研究它。
import sys
import pprint
sys.path.append('/opt/plexus-srv/rrdtool-1.4.9/lib64/python2.6/site-
packages')
import rrdtool
rrd_file = sys.argv[1]
rrd_info = rrdtool.info(rrd_file)
data = rrdtool.fetch(rrd_file,"AVERAGE")
print(type(data))
pp = pprint.PrettyPrinter(indent =4)
pp.pprint(data)
pp.pprint(rrd_info)
输出为:
<type 'tuple'>
('sum',)
1510142400
[(None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,), (None,)]
{ 'ds[sum].index': 0L,
'ds[sum].last_ds': '99.3',
'ds[sum].max': None,
'ds[sum].min': None,
'ds[sum].minimal_heartbeat': 120L,
'ds[sum].type': 'GAUGE',
'ds[sum].unknown_sec': 0L,
'ds[sum].value': 1290.8999999999999,
'filename': '/home/u43555766/aad/plexus/rrdsample/testing/cpu/cpu_idle.rrd',
'header_size': 1416L,
'last_update': 1510030543L,
'rra[0].cdp_prep[0].unknown_datapoints': 0L,
'rra[0].cdp_prep[0].value': None,
'rra[0].cf': 'AVERAGE',
'rra[0].cur_row': 49L,
'rra[0].pdp_per_row': 1L,
'rra[0].rows': 490L,
'rra[0].xff': 0.5,
'rra[1].cdp_prep[0].unknown_datapoints': 0L,
'rra[1].cdp_prep[0].value': 198.78666666666669,
'rra[1].cf': 'AVERAGE',
'rra[1].cur_row': 2264L,
'rra[1].pdp_per_row': 4L,
'rra[1].rows': 2890L,
'rra[1].xff': 0.5,
'rra[2].cdp_prep[0].unknown_datapoints': 0L,
'rra[2].cdp_prep[0].value': 198.78666666666669,
'rra[2].cf': 'AVERAGE',
'rra[2].cur_row': 873L,
'rra[2].pdp_per_row': 20L,
'rra[2].rows': 2026L,
'rra[2].xff': 0.5,
'rra[3].cdp_prep[0].unknown_datapoints': 0L,
'rra[3].cdp_prep[0].value': 22058.293333333328,
'rra[3].cf': 'AVERAGE',
'rra[3].cur_row': 387L,
'rra[3].pdp_per_row': 240L,
'rra[3].rows': 754L,
'rra[3].xff': 0.5,
'rra[4].cdp_prep[0].unknown_datapoints': 0L,
'rra[4].cdp_prep[0].value': 117354.74000000028,
'rra[4].cf': 'AVERAGE',
'rra[4].cur_row': 214L,
'rra[4].pdp_per_row': 5760L,
'rra[4].rows': 375L,
'rra[4].xff': 0.5,
'rrd_version': '0003',
'step': 15L}
问题最明显的答案是return没有数据。
您没有说明是否以及如何将数据添加到 RRD 文件中。由于您的 'fetch' 调用没有任何参数来指定分辨率、开始或结束,因此它可能会默认为一天,现在结束,5 分钟分辨率。您确实有匹配的 RRA,但我们不知道那里是否有任何数据。
查看您提供的数据,您似乎 运行 在时间 1510142400 获取数据,但 RRD 最后更新时间为 1510030543,大约早了 31 小时。可能没有最后一天的数据?
从命令行尝试 运行 'rrdtool fetch' 和 'rrdtool dump',并验证是否存储了数据,并且它们适合您认为的时间。也许将附加参数传递给 'fetch' 以指定步骤、开始和结束。
我是 rrdtool 的新手,所以没有意识到我已经错过了收集数据的开始时间。这些文件几天前来自服务器。获取命令缺少“-s”时间,因此打印了 None 对象。添加“-s”和“-96h”打印数据。感谢@steve-shipway