Skip to content
mewald1 edited this page May 9, 2015 · 1 revision

The names of possible metrics can be found using the vSphere API. In the following I will demostrate how to do that with Pysphere for ESXi hosts and VMs:

Prerequisites

Open an interactive Python interpreter and import pysphere:

$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pysphere import *

Next, we need to open a vCenter Server connection and get an instance of performance manager:

viserver = VIServer()
viserver.connect("vc.lab.invalid", "root", "vmware")
pm = viserver.get_performance_manager()

Host Counter Names

To retrieve available host counters, we need the MOREF of a host

hosts = viserver.get_hosts()
host = hosts.keys()[0]

Now we can fetch the list of counters and their ID in the vCenter database:

pm.get_entity_counters(host)
{'hbr.hbrNumVms': 545, 'net.droppedRx': 468, 'disk.write': 131, 'sys.resourceCpuUsage': 482, 'mem.llSwapUsed': 443, 'rescpu.runav15': 515, 'net.packetsRx': 146, 'disk.totalLatency': 132, 'cpu.usage': 2, 'mem.usage': 24, 'storagePath.totalWriteLatency': 533, 'rescpu.maxLimited15': 521, 'disk.usage': 125, 'rescpu.sampleCount': 522, 'datastore.datastoreMaxQueueDepth': 544, 'storagePath.numberReadAveraged': 528, 'disk.read': 130, 'datastore.datastoreNormalWriteLatency': 354, 'cpu.costop': 414, 'storageAdapter.numberReadAveraged': 162, 'mem.swapoutRate': 86, 'datastore.numberWriteAveraged': 179, 'storagePath.totalReadLatency': 532, 'mem.totalCapacity': 433, 'mem.swapout': 424, 'rescpu.samplePeriod': 523, 'cpu.idle': 13, 'disk.numberReadAveraged': 136, 'sys.resourceMemTouched': 485, 'hbr.hbrNetRx': 546, 'mem.consumed': 98, 'mem.heap': 61, 'net.broadcastTx': 473, 'cpu.ready': 12, 'datastore.totalWriteLatency': 183, 'datastore.datastoreReadBytes': 347, 'rescpu.actpk15': 514, 'mem.sysUsage': 428, 'mem.vmmemctl': 90, 'net.errorsTx': 477, 'mem.shared': 37, 'datastore.datastoreNormalReadLatency': 353, 'mem.lowfreethreshold': 438, 'rescpu.actpk5': 511, 'storageAdapter.commandsAveraged': 161, 'mem.compressionRate': 106, 'rescpu.actpk1': 508, 'storagePath.commandsAveraged': 527, 'net.multicastTx': 475, 'disk.totalWriteLatency': 461, 'rescpu.actav5': 510, 'net.usage': 143, 'sys.resourceMemOverhead': 489, 'rescpu.runpk15': 520, 'mem.swapinRate': 85, 'storagePath.write': 531, 'mem.compressed': 105, 'net.received': 148, 'disk.deviceLatency': 463, 'storageAdapter.write': 165, 'mem.swapused': 49, 'datastore.totalReadLatency': 182, 'mem.reservedCapacity': 27, 'disk.deviceReadLatency': 455, 'storagePath.numberWriteAveraged': 529, 'net.droppedTx': 469, 'sys.resourceMemAllocShares': 503, 'cpu.reservedCapacity': 9, 'sys.resourceFdUsage': 506, 'net.broadcastRx': 472, 'disk.busResets': 135, 'mem.decompressionRate': 107, 'mem.llSwapInRate': 440, 'sys.resourceMemConsumed': 505, 'storagePath.maxTotalLatency': 193, 'hbr.hbrNetTx': 547, 'mem.unreserved': 45, 'disk.kernelWriteLatency': 460, 'datastore.datastoreWriteIops': 350, 'disk.totalReadLatency': 457, 'net.errorsRx': 476, 'cpu.demand': 413, 'cpu.coreUtilization': 407, 'datastore.datastoreIops': 185, 'storageAdapter.totalWriteLatency': 167, 'mem.latency': 436, 'disk.numberWrite': 129, 'mem.heapfree': 65, 'power.powerCap': 158, 'sys.resourceMemMapped': 486, 'cpu.wait': 11, 'sys.resourceMemSwapped': 488, 'mem.llSwapOutRate': 441, 'mem.active': 33, 'rescpu.runpk1': 516, 'datastore.datastoreReadOIO': 351, 'sys.resourceMemShared': 487, 'net.multicastRx': 474, 'sys.uptime': 155, 'datastore.write': 181, 'cpu.used': 14, 'net.bytesRx': 470, 'mem.granted': 29, 'mem.llSwapOut': 451, 'datastore.datastoreWriteLoadMetric': 356, 'cpu.latency': 411, 'datastore.numberReadAveraged': 178, 'net.transmitted': 149, 'rescpu.runav5': 512, 'disk.queueLatency': 465, 'rescpu.runav1': 509, 'disk.queueWriteLatency': 462, 'storageAdapter.totalReadLatency': 166, 'mem.overhead': 102, 'disk.queueReadLatency': 458, 'sys.resourceMemCow': 490, 'cpu.swapwait': 401, 'datastore.sizeNormalizedDatastoreLatency': 186, 'power.energy': 159, 'datastore.datastoreWriteBytes': 348, 'cpu.usagemhz': 6, 'disk.maxQueueDepth': 466, 'cpu.utilization': 403, 'rescpu.maxLimited5': 519, 'disk.deviceWriteLatency': 459, 'rescpu.maxLimited1': 517, 'datastore.siocActiveTimePercentage': 191, 'disk.kernelLatency': 464, 'vflashModule.numActiveVMDKs': 548, 'disk.maxTotalLatency': 133, 'disk.commands': 454, 'datastore.read': 180, 'cpu.totalCapacity': 410, 'datastore.maxTotalLatency': 184, 'mem.zero': 41, 'disk.commandsAborted': 134, 'sys.resourceMemAllocMin': 501, 'rescpu.runpk5': 518, 'net.bytesTx': 471, 'power.power': 157, 'datastore.datastoreReadIops': 349, 'mem.sharedcommon': 57, 'mem.state': 68, 'sys.resourceCpuAllocShares': 500, 'datastore.datastoreVMObservedLatency': 357, 'sys.resourceMemAllocMax': 502, 'storageAdapter.numberWriteAveraged': 163, 'net.packetsTx': 147, 'storageAdapter.maxTotalLatency': 168, 'rescpu.actav15': 513, 'net.unknownProtos': 478, 'storagePath.read': 530, 'sys.resourceCpuAllocMin': 498, 'sys.resourceCpuRun5': 495, 'sys.resourceCpuRun1': 492, 'storageAdapter.read': 164, 'datastore.datastoreReadLoadMetric': 355, 'mem.llSwapIn': 447, 'mem.activewrite': 431, 'rescpu.actav1': 507, 'disk.numberWriteAveraged': 137, 'disk.commandsAveraged': 467, 'disk.numberRead': 128, 'mem.swapin': 420, 'disk.kernelReadLatency': 456, 'sys.resourceCpuMaxLimited5': 497, 'sys.resourceCpuAllocMax': 499, 'datastore.datastoreWriteOIO': 352, 'sys.resourceCpuMaxLimited1': 494, 'sys.resourceMemZero': 491, 'sys.resourceCpuAct5': 496, 'sys.resourceCpuAct1': 493}

VM Counter Names

To retrieve available host counters, we need the MOREF of a host

vm_paths = viserver.get_registered_vms()
vm_path = vm_paths[0]
vm = viserver.get_vm_by_path(vm_path)
vm_moref = vm._mor

Now we can fetch the list of counters and their ID in the vCenter database:

pm.get_entity_counters(vm_moref)
{'net.droppedRx': 468, 'disk.read': 130, 'mem.llSwapUsed': 443, 'rescpu.runav15': 515, 'cpu.usage': 2, 'mem.usage': 24, 'rescpu.maxLimited15': 521, 'disk.usage': 125, 'rescpu.sampleCount': 522, 'disk.write': 131, 'cpu.costop': 414, 'datastore.numberWriteAveraged': 179, 'mem.swapout': 424, 'rescpu.samplePeriod': 523, 'cpu.idle': 13, 'disk.numberReadAveraged': 136, 'mem.consumed': 98, 'net.broadcastTx': 473, 'net.droppedTx': 469, 'datastore.totalWriteLatency': 183, 'mem.swaptarget': 74, 'rescpu.actpk15': 514, 'cpu.overlap': 416, 'mem.vmmemctl': 90, 'power.energy': 159, 'virtualDisk.writeIOSize': 535, 'mem.overheadTouched': 442, 'mem.shared': 37, 'virtualDisk.readOIO': 343, 'rescpu.actpk5': 511, 'mem.compressionRate': 106, 'rescpu.actpk1': 508, 'net.bytesTx': 471, 'net.multicastTx': 475, 'sys.heartbeat': 479, 'cpu.ready': 12, 'net.usage': 143, 'rescpu.actav1': 507, 'rescpu.runpk15': 520, 'mem.swapinRate': 85, 'mem.compressed': 105, 'mem.vmmemctltarget': 94, 'net.received': 148, 'cpu.maxlimited': 415, 'virtualDisk.writeLatencyUS': 540, 'mem.swapped': 70, 'datastore.totalReadLatency': 182, 'net.broadcastRx': 472, 'disk.busResets': 135, 'mem.decompressionRate': 107, 'mem.llSwapInRate': 440, 'datastore.write': 181, 'cpu.swapwait': 401, 'rescpu.maxLimited1': 517, 'virtualDisk.smallSeeks': 536, 'cpu.demand': 413, 'mem.latency': 436, 'disk.numberWrite': 129, 'virtualDisk.numberReadAveraged': 171, 'cpu.wait': 11, 'mem.llSwapOutRate': 441, 'mem.entitlement': 437, 'net.multicastRx': 474, 'sys.uptime': 155, 'net.bytesRx': 470, 'mem.granted': 29, 'cpu.latency': 411, 'datastore.numberReadAveraged': 178, 'net.transmitted': 149, 'rescpu.runav5': 512, 'virtualDisk.totalWriteLatency': 176, 'rescpu.runav1': 509, 'virtualDisk.numberWriteAveraged': 172, 'mem.zipSaved': 435, 'disk.commandsAveraged': 467, 'virtualDisk.largeSeeks': 538, 'net.packetsRx': 146, 'virtualDisk.writeLoadMetric': 346, 'virtualDisk.mediumSeeks': 537, 'disk.numberRead': 128, 'rescpu.runpk1': 516, 'cpu.usagemhz': 6, 'virtualDisk.read': 173, 'rescpu.maxLimited5': 519, 'virtualDisk.readLoadMetric': 345, 'cpu.used': 14, 'sys.osUptime': 504, 'virtualDisk.write': 174, 'disk.maxTotalLatency': 133, 'disk.commands': 454, 'datastore.read': 180, 'datastore.maxTotalLatency': 184, 'cpu.system': 10, 'mem.zero': 41, 'disk.commandsAborted': 134, 'rescpu.runpk5': 518, 'virtualDisk.readLatencyUS': 539, 'power.power': 157, 'cpu.run': 417, 'net.packetsTx': 147, 'rescpu.actav15': 513, 'rescpu.actav5': 510, 'mem.zipped': 434, 'virtualDisk.totalReadLatency': 175, 'mem.overheadMax': 432, 'mem.active': 33, 'virtualDisk.readIOSize': 534, 'disk.numberWriteAveraged': 137, 'mem.overhead': 102, 'cpu.entitlement': 412, 'mem.activewrite': 431, 'mem.swapin': 420, 'virtualDisk.writeOIO': 344, 'cpu.demandEntitlementRatio': 418, 'mem.swapoutRate': 86}