Skip to content

Commit

Permalink
Implement a new vPoller method - perf.counter.info
Browse files Browse the repository at this point in the history
* The perf.counter.info vPoller method is used for retrieving all
  performance counters as supported by the vSphere host
  • Loading branch information
dnaeon committed Jan 5, 2015
1 parent 7cbe88a commit 2489bcc
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions src/vpoller/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ def __init__(self, user, pwd, host):
"""
super(VSphereAgent, self).__init__(user, pwd, host)

# A list of supported performance counters by the vSphere host
self._perf_counter_supported = None

# Message attribute types we expect to receive
# before we start processing a task request
self.msg_attr_types = {
Expand Down Expand Up @@ -231,8 +234,18 @@ def __init__(self, user, pwd, host):
'method': self.datastore_vm_get,
'required': ['hostname', 'name'],
},
'perf.counter.info': {
'method': self.perf_counter_info,
'required': ['hostname'],
},
}

@property
def perf_counter_supported(self):
if not self._perf_counter_supported:
self._perf_counter_supported = [c.key for c in self.si.content.perfManager.perfCounter]
return self._perf_counter_supported

def _validate_client_msg(self, msg, required):
"""
Helper method for validating a client message
Expand Down Expand Up @@ -517,6 +530,52 @@ def _object_alarm_get(self,

return r

def _get_perf_counter_info(self, counter_id):
"""
Helper method for retrieving information about performance counter IDs
Args:
counter_id (list): A list of counter IDs to query
Returns:
Information about the specified counter IDs
"""
logging.debug(
'[%s] Retrieving performance counters info for IDs %s',
self.host,
counter_id
)

try:
counter_info = self.si.content.perfManager.QueryPerfCounter(
counterId=counter_id
)
except Exception as e:
return {'success': 1, 'msg': 'Cannot get performance counter info: %s' % e}

data = []
for c in counter_info:
d = {
'key': c.key,
'nameInfo': {k: getattr(c.nameInfo, k) for k in ('label', 'summary', 'key')},
'groupInfo': {k: getattr(c.groupInfo, k) for k in ('label', 'summary', 'key')},
'unitInfo': {k: getattr(c.unitInfo, k) for k in ('label', 'summary', 'key')},
'rollupType': c.rollupType,
'statsType': c.statsType,
'level': c.level,
'perDeviceLevel': c.perDeviceLevel,
}
data.append(d)

result = {
'success': 0,
'msg': 'Successfully retrieved performance counters info',
'result': data
}

return result

def event_latest(self, msg):
"""
Get the latest event registered
Expand Down Expand Up @@ -657,6 +716,28 @@ def session_get(self, msg):

return result

def perf_counter_info(self, msg):
"""
Get all performance counters supported by the vSphere host
Example client message would be:
{
"method": "perf.counter.info",
"hostname": "vc01.example.org",
}
Returns:
The list of supported performance counters by the vSphere host
"""
logging.info(
'[%s] Retrieving supported performance counters',
self.host
)

return self._get_perf_counter_info(counter_id=self.perf_counter_supported)

def net_discover(self, msg):
"""
Discover all pyVmomi.vim.Network managed objects
Expand Down

0 comments on commit 2489bcc

Please sign in to comment.