
Hi Deepthi, On 09/06/2013 01:12 PM, Deepthi Dharwar wrote:
Hi,
I was trying to get the cpu statistics of a host using the oVirt python sdk. But beyond a point I am unable to deference to the actual cpu stats field and the data.
h_list = api.hosts.list() for h in h_list: y = h.statistics.list() for i in y: print i.get_values()
O/P:
<ovirtsdk.xml.params.Values object at 0x22cbd90> <ovirtsdk.xml.params.Values object at 0x22cbb90> <ovirtsdk.xml.params.Values object at 0x22cba90> <ovirtsdk.xml.params.Values object at 0x22cba10> <ovirtsdk.xml.params.Values object at 0x22cbf10>
Can some one please let me know how I can get individual fields like cpu.current.system or cpu.current.idle stats from here.
you can use sdk client side filtering on collections using map based constraints [1], just note that you cannot use same constrain (name) twice [2] as following entry will always override the former one, to work this out, just use your private inline filtering [3] (it will have same complexity as using sdk filtering) [1] for h in h_list: statistics = h.statistics.list(**{ 'name':'cpu.current.system' } ) for statistic in statistics: print "%s=%0.4f %s" % ( statistic.get_name(), statistic.get_values().get_value()[0].datum, statistics[0].get_unit() ) [2] statistics = h.statistics.list(**{ 'name':'cpu.current.system', 'name':'cpu.current.idle' } ) [3] h_list = api.hosts.list() stats_to_show = ['cpu.current.system', 'cpu.current.idle'] for h in h_list: statistics = h.statistics.list() for statistic in statistics: if statistic.get_name() in stats_to_show: print "%s=%0.4f %s" % ( statistic.get_name(), statistic.get_values().get_value()[0].datum , statistics[0].get_unit() ) hope it helps.
Thanks! Deepthi
-- Michael Pasternak RedHat, ENG-Virtualization R&D