Skip to content

Commit

Permalink
Implement datacenter.perf.counter.get method
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaeon committed Jan 8, 2015
1 parent 1b24fc3 commit f030ebb
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/vpoller/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ def __init__(self, user, pwd, host):
'method': self.datacenter_get,
'required': ['hostname', 'name', 'properties'],
},
'datacenter.perf.counter.get': {
'method': self.datacenter_perf_counter_get,
'required': ['hostname', 'name', 'properties'],
},
'datacenter.perf.counter.info': {
'method': self.datacenter_perf_counter_info,
'required': ['hostname', 'name'],
Expand Down Expand Up @@ -700,6 +704,8 @@ def _entity_perf_metric_get(self, entity, counter_id, max_sample=1, instance=Non
}

# Get the metric IDs to collect and build our query spec
if not max_sample:
max_sample = 1
to_collect_metric_id = [m for m in metric_id for counter_id in to_collect_counter_id if m.counterId == counter_id]
query_spec = pyVmomi.vim.PerformanceManager.QuerySpec(
maxSample=max_sample,
Expand Down Expand Up @@ -1155,6 +1161,52 @@ def datacenter_discover(self, msg):

return r


def datacenter_perf_counter_get(self, msg):
"""
Get performance metrics for a vim.Datacenter managed object
The properties passed in the message are the performance
counter IDs to be retrieved.
Example client message would be:
{
"method": "datacenter.perf.counter.get",
"hostname": "vc01.example.org",
"name": "MyDatacenter",
"properties": [
256, # VM power on count
257, # VM power off count
258 # VM suspend count
],
"key": 1, # Historical performance interval with key 1 (Past day)
"max_sample": 1,
"instance": ""
}
Returns:
The retrieved performance metrics
"""
obj = self.get_object_by_property(
property_name='name',
property_value=msg['name'],
obj_type=pyVmomi.vim.Datacenter,
)

if not obj:
return {'success': 1, 'msg': 'Cannot find object: %s' % msg['name']}

# Interval ID is passed as the 'key' message attribute
max_sample, key = msg.get('max_sample'), msg.get('key')
return self._entity_perf_metric_get(
entity=obj,
counter_id=msg['properties'],
max_sample=max_sample,
interval_key=key
)

def datacenter_perf_counter_info(self, msg):
"""
Get performance counters available for a vim.Datacenter object
Expand Down

0 comments on commit f030ebb

Please sign in to comment.