0

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?

Shehan
  • 417
  • 2
  • 11

1 Answers1

0

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.

Steve Shipway
  • 3,754
  • 3
  • 22
  • 39