如何使用rrdtool读取RRD文件

发布于 2025-02-01 02:33:03 字数 1487 浏览 3 评论 0原文

我需要从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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白云不回头 2025-02-08 02:33:03

如您所见,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 the last_ds. The value 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 extract ds[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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文