16 Creating custom performance counter names for VMware

Overview

The VMware performance counter path has the group/counter[rollup] format where:

  • group - the performance counter group, for example cpu
  • counter - the performance counter name, for example usagemhz
  • rollup - the performance counter rollup type, for example average

So the above example would give the following counter path: cpu/usagemhz[average]

The performance counter group descriptions, counter names and rollup types can be found in VMware documentation.

It is possible to obtain internal names and create custom performance counter names by using script item in Zabbix.

Configuration

  1. Create disabled Script item on the main VMware host (where the eventlog[] item is present) with the following parameters:

16 Creating custom performance counter names for VMware - 图1

  • Name: VMware metrics
  • Type: Script
  • Key: vmware.metrics
  • Type of information: Text
  • Script: copy and paste the script provided below
  • Timeout: 10
  • History storage period: Do not keep history
  • Enabled: unmarked

Script

  1. try {
  2. Zabbix.log(4, 'vmware metrics script');
  3. var result, resp,
  4. req = new HttpRequest();
  5. req.addHeader('Content-Type: application/xml');
  6. req.addHeader('SOAPAction: "urn:vim25/6.0"');
  7. login = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:vim25">\
  8. <soapenv:Header/>\
  9. <soapenv:Body>\
  10. <urn:Login>\
  11. <urn:_this type="SessionManager">SessionManager</urn:_this>\
  12. <urn:userName>{$VMWARE.USERNAME}</urn:userName>\
  13. <urn:password>{$VMWARE.PASSWORD}</urn:password>\
  14. </urn:Login>\
  15. </soapenv:Body>\
  16. </soapenv:Envelope>'
  17. resp = req.post("{$VMWARE.URL}", login);
  18. if (req.getStatus() != 200) {
  19. throw 'Response code: '+req.getStatus();
  20. }
  21. query = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:vim25">\
  22. <soapenv:Header/>\
  23. <soapenv:Body>\
  24. <urn:RetrieveProperties>\
  25. <urn:_this type="PropertyCollector">propertyCollector</urn:_this>\
  26. <urn:specSet>\
  27. <urn:propSet>\
  28. <urn:type>PerformanceManager</urn:type>\
  29. <urn:pathSet>perfCounter</urn:pathSet>\
  30. </urn:propSet>\
  31. <urn:objectSet>\
  32. <urn:obj type="PerformanceManager">PerfMgr</urn:obj>\
  33. </urn:objectSet>\
  34. </urn:specSet>\
  35. </urn:RetrieveProperties>\
  36. </soapenv:Body>\
  37. </soapenv:Envelope>'
  38. resp = req.post("{$VMWARE.URL}", query);
  39. if (req.getStatus() != 200) {
  40. throw 'Response code: '+req.getStatus();
  41. }
  42. Zabbix.log(4, 'vmware metrics=' + resp);
  43. result = resp;
  44. logout = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:vim25">\
  45. <soapenv:Header/>\
  46. <soapenv:Body>\
  47. <urn:Logout>\
  48. <urn:_this type="SessionManager">SessionManager</urn:_this>\
  49. </urn:Logout>\
  50. </soapenv:Body>\
  51. </soapenv:Envelope>'
  52. resp = req.post("{$VMWARE.URL}",logout);
  53. if (req.getStatus() != 200) {
  54. throw 'Response code: '+req.getStatus();
  55. }
  56. } catch (error) {
  57. Zabbix.log(4, 'vmware call failed : '+error);
  58. result = {};
  59. }
  60. return result;

Once the item is configured, press Test button, then press Get value.

16 Creating custom performance counter names for VMware - 图2

Copy received XML to any XML formatter and find the desired metric.

An example of XML for one metric:

  1. <PerfCounterInfo xsi:type="PerfCounterInfo">
  2. <key>6</key>
  3. <nameInfo>
  4. <label>Usage in MHz</label>
  5. <summary>CPU usage in megahertz during the interval</summary>
  6. <key>usagemhz</key>
  7. </nameInfo>
  8. <groupInfo>
  9. <label>CPU</label>
  10. <summary>CPU</summary>
  11. <key>cpu</key>
  12. </groupInfo>
  13. <unitInfo>
  14. <label>MHz</label>
  15. <summary>Megahertz</summary>
  16. <key>megaHertz</key>
  17. </unitInfo>
  18. <rollupType>average</rollupType>
  19. <statsType>rate</statsType>
  20. <level>1</level>
  21. <perDeviceLevel>3</perDeviceLevel>
  22. </PerfCounterInfo>

Use XPath to extract the counter path from received XML. For the example above, the XPath will be:

fieldxPathvalue
group//groupInfo[../key=6]/keycpu
counter//nameInfo[../key=6]/keyusagemhz
rollup//rollupType[../key=6]average

Resulting performance counter path in this case is: cpu/usagemhz[average]