15 为 VMware 创建自定义性能计数器名称

概述

VMware 性能计数器路径具有 group/counter[rollup] 格式:

  • group - 性能计数器组,例如 cpu
  • counter - 性能计数器名称,例如 usagemhz
  • rollup - 性能计数器汇总类型,例如 average

所以上面的例子会给出以下计数器路径: cpu/usagemhz[average]

性能计数器组描述、计数器名称和汇总类型可以在 VMware 文档中找到。

可以通过使用 Zabbix 中的脚本监控项来获取内部名称并创建自定义性能计数器名称。

配置

  1. 使用以下参数在主要的VMware主机(存在 eventlog[] 监控项的地方)上创建禁用的脚本监控项:

15 为 VMware 创建自定义性能计数器名称 - 图1

  • Name: VMware 指标
  • Type: 脚本
  • Key: vmware.metrics
  • Type of information: 文本
  • Script: 复制并粘贴下面提供的 脚本
  • Timeout: 10
  • History: 不存储
  • Enabled: 未标记

脚本

  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;

配置监控项后,点击 Test 按钮,然后点击 Get value

15 为 VMware 创建自定义性能计数器名称 - 图2

将收到的 XML 复制到任何 XML 格式化程序并找到所需的指标。

一个指标的 XML 示例:

  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>

使用 XPath 从收到的 XML 中提取计数器路径。对于上面的示例,XPath 将是:

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

在这个例子中性能计数器路径是: cpu/usagemhz[average]