如何使用rrdtool读取RRD文件
我需要从rrdtool获取特定的数据字段。在这里,我有rrdfile的XML输出。
<ds>
<name> gauge1 </name>
<type> COUNTER </type>
<minimal_heartbeat> 600 </minimal_heartbeat>
<min> 0.0000000000e+00 </min>
<max> 1.0000000000e+08 </max>
<!-- PDP Status -->
<last_ds> 10109068304313 </last_ds>
<value> 1.2791603667e+05 </value>//need to read this value
<unknown_sec> 0 </unknown_sec>
</ds>
<ds>
<name> gauge2 </name>
<type> COUNTER </type>
<minimal_heartbeat> 600 </minimal_heartbeat>
<min> 0.0000000000e+00 </min>
<max> 1.0000000000e+08 </max>
<!-- PDP Status -->
<last_ds> 8604908605180 </last_ds>
<value> 1.2595538667e+05 </value>//need to read this value
<unknown_sec> 0 </unknown_sec>
</ds>
我正在使用以下命令来读取rrdfiles。
file_path=r'/data/rrd_new/XXX.rrd'
rrdfilename = file_path
rrd = rrdtool.lastupdate(rrdfilename)
time = rrd['date']
ds = rrd['ds']
print(time,ds)
但是,这提供了如下的输出,这是&lt; last_ds&gt;
的值,
2022-05-23 11:25:01 {'gauge1': 10109068304313.0, 'gauge2': 8604908605180}
但是我需要获得和外出的值应如下,
2022-05-23 11:25:01 {'gauge1': 127916.03667, 'gauge2': 125955.38667}
有人可以帮助我阅读此内容吗?
I need to get specific data field from rrdtool. Here I have xml output of my rrdfile.
<ds>
<name> gauge1 </name>
<type> COUNTER </type>
<minimal_heartbeat> 600 </minimal_heartbeat>
<min> 0.0000000000e+00 </min>
<max> 1.0000000000e+08 </max>
<!-- PDP Status -->
<last_ds> 10109068304313 </last_ds>
<value> 1.2791603667e+05 </value>//need to read this value
<unknown_sec> 0 </unknown_sec>
</ds>
<ds>
<name> gauge2 </name>
<type> COUNTER </type>
<minimal_heartbeat> 600 </minimal_heartbeat>
<min> 0.0000000000e+00 </min>
<max> 1.0000000000e+08 </max>
<!-- PDP Status -->
<last_ds> 8604908605180 </last_ds>
<value> 1.2595538667e+05 </value>//need to read this value
<unknown_sec> 0 </unknown_sec>
</ds>
I am using following commands to read rrdfiles.
file_path=r'/data/rrd_new/XXX.rrd'
rrdfilename = file_path
rrd = rrdtool.lastupdate(rrdfilename)
time = rrd['date']
ds = rrd['ds']
print(time,ds)
But this provides output as below, which is the value of <last_ds>
2022-05-23 11:25:01 {'gauge1': 10109068304313.0, 'gauge2': 8604908605180}
But I need to get the value of and outout should be as follows,
2022-05-23 11:25:01 {'gauge1': 127916.03667, 'gauge2': 125955.38667}
Can someone help me to read this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如您所见,
lastupdate()
函数返回 last Update 的数据,即更新时间,last_ds
。您在XML中看到的value
实际上是正在构建当前PDP的工作区,并且没有特定功能来检索它。当然,您可以调用
info()
函数,然后从返回的数据提取ds [gauge1] .value
等。这可能是您想要的。更好的方法是使用
XPORT()
,如果您在RRD中有一个,则在1CDP = 1pdp RRA中提取最新值。这将使您在最高粒度RRA中提取最新价值。As you have seen, the
lastupdate()
function returns the data from the last update, IE the update time, and thelast_ds
. Thevalue
you see in the XML is really the workspace where the current pdp is being built, and does not have a specific function to retrieve it.You can, of course, call the
info()
function, and then from the returned data extractds[gauge1].value
and similar. This may be what you want.Probably the better way would be to use
xport()
and extract the latest value in a 1cdp=1pdp RRA, if you have one in the RRD. This will let you pull out the most recent value in the highest-granularity RRA.