[Users] oVirt-sdk to fetch individual cpu stats
Michael Pasternak
mpastern at redhat.com
Tue Sep 10 11:11:11 EDT 2013
On 09/10/2013 02:04 PM, Deepthi Dharwar wrote:
> Thanks a lot Micheal. Works like a charm :)
>
> How does one know that you need to access first field in
> statistic.get_values().get_value()[0].datum.
> Are these documented any place ?
you can see this in api [1] there is a collection of values
represented by <value> place-hoder, you can find discussion
on statistics api modelling at the old rhevm-api [2] mailing list.
<values type="...">
<value>
<datum>...</datum>
</value>
</values>
[1] GET http://server:[port]/api/hosts/xxx/statistics
[2] https://lists.fedorahosted.org/pipermail/rhevm-api/
>
> Regards,
> Deepthi
>
> On 09/08/2013 03:55 PM, Michael Pasternak wrote:
>
>
>>
>> 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
More information about the Users
mailing list