I am evaluating pysphere for performance metric collection via Python,
but the getting started wiki page is more focused to the
administration of the VMs.
Can you give a small example on how to do it?
Ideally, I'd like something that returns a host list, their available
performance metrics and their values.
Thank you in advance!
Regards,
Sebastián
--
Ioannis Stoilis
First of all I want to apologize for the delayed answer.
First of all, I encourage you to use the current trunk version for
this example to work. If you don't know how to download and install
that version, let me know and I can provide you with a src
distribution or a windows executable.
#as always we first have to login:
from pysphere import *
s = VIServer()
s.connect("yourhost", "username", "password")
# then retrieve the available hosts
hosts = s._get_hosts()
#this is a dictionary of host names an managed object references. Eg.
{'192.168.100.1': 'host-5583', '192.168.100.2': 'host-185', ...}
#now instance the performance manager
pm = s.get_performance_manager()
#to retrieve the available perf metrics from, for example, the first
host you run
pm.get_entity_counters(hosts['192.168.100.1'])
#This will return a long list of counter names and their ids:
{'actav1': 265,
'actav15': 271,
'actav5': 268,
'active': 25,
'activewrite': 316,
.....
'used': 14,
'utilization': 305,
'vmmemctl': 82,
'write': 325,
'zero': 33}
#Now to get the values of the one you are interested in, for example,
'used', 'write', and 'zero', you should run
statistics = pm.get_entity_statistic(hosts['192.168.100.1'],
[14,325,33])
#that will return a list of EnitityStatistics objects, to display the
values you might run:
for sta in statistics:
print sta.counter
print sta.description
print sta.value
print sta.time
Hope this helps,
Regards
Sebastian
I meant:
hosts = s.get_hosts()
The viperformace Perl lib I am using(and want to replace) returns
something like this:
Counter: Core utilization
Instance :
Description: CPU utilization of the corresponding core (if
hyper-threading is enabled) as a percentage during the interval (A
core is utilized, if either or both of its logical CPUs are utilized)
Units: Percent
Sample info : 20,2011-12-19T02:21:40-07:00,20,2011-12-19T02:22:00-07:00
Value: 871,642
Which is very useful, as I am appending them to the metric name before
publishing, so they can make some sense without lookinto into docs and
specs.
Do you think you can export that piece of information as well?
--
Ioannis Stoilis
You are right, I missed unit information completely. I've just added
it to pysphere, so please check the trunk version.
Besides unit info I also added group info (for example CPU, Memory,
etc) where the counter belongs to.
So when you did:
for sta in statistics:
print sta.counter
print sta.description
print sta.value
print sta.time
Now you can also do:
for sta in statistics:
print sta.counter
print sta.description
print sta.value
print sta.time
print sta.group #e.g. 'mem'
print sta.group_description #e.g. 'Memory'
print sta.unit #e.g. 'kiloBytes'
print sta.unit_description #e.g. 'KB'
Hope this helps!
Sebastian Tello
On Dec 19, 2:28 pm, Ioannis Stoilis <ioan...@stoilis.gr> wrote:
> It works very nice, but I have the following issue: The metrics don't
> seem to come with a unit.
>
> The viperformace Perl lib I am using(and want to replace) returns
> something like this:
> Counter: Core utilization
> Instance :
> Description: CPU utilization of the corresponding core (if
> hyper-threading is enabled) as a percentage during the interval (A
> core is utilized, if either or both of its logical CPUs are utilized)
> Units: Percent
> Sample info : 20,2011-12-19T02:21:40-07:00,20,2011-12-19T02:22:00-07:00
> Value: 871,642
>
> Which is very useful, as I am appending them to the metric name before
> publishing, so they can make some sense without lookinto into docs and
> specs.
>
> Do you think you can export that piece of information as well?
>
--
Ioannis Stoilis
>>> pm.get_entity_counters(hosts['ha-host'])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pysphere/vi_performance_manager.py", line 117, in get_entity_counters
sampling_period = self._check_and_get_interval_by_id(entity, interval)
File "/usr/local/lib/python2.7/dist-packages/pysphere/vi_performance_manager.py", line 197, in _check_and_get_interval_by_id
summary = self.query_perf_provider_summary(entity)
File "/usr/local/lib/python2.7/dist-packages/pysphere/vi_performance_manager.py", line 299, in query_perf_provider_summary
qpps_entity.set_attribute_type(entity.get_attribute_type())
AttributeError: 'str' object has no attribute 'get_attribute_type'