VMware性能计数器路径遵循 group/counter[rollup]格式,其中:
group - 性能计数器组,例如cpu
counter - 性能计数器名称,例如usagemhz
rollup - 性能计数器汇总类型,例如
average
因此上述示例将生成以下计数器路径: cpu/usagemhz[average]
性能计数器组描述、计数器名称及汇总类型 可在VMware documentation中查阅。
通过使用Zabbix中的监控项脚本,可获取内部名称及create自定义性能计数器名称。

try {
           Zabbix.log(4, 'vmware metrics script');
       
           var result, resp,
       
           req = new HttpRequest();
           req.addHeader('Content-Type: application/xml');
           req.addHeader('SOAPAction: "urn:vim25/6.0"');
       
           login = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:vim25">\
       
           <soapenv:Header/>\
           <soapenv:Body>\
               <urn:Login>\
                   <urn:_this type="SessionManager">SessionManager</urn:_this>\
                   <urn:userName>{$VMWARE.USERNAME}</urn:userName>\
                   <urn:password>{$VMWARE.PASSWORD}</urn:password>\
               </urn:Login>\
           </soapenv:Body>\
       </soapenv:Envelope>'
           resp = req.post("{$VMWARE.URL}", login);
           if (req.getStatus() != 200) {
               throw 'Response code: '+req.getStatus();
           }
       
           query = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:vim25">\
       
       <soapenv:Header/>\
           <soapenv:Body>\
               <urn:RetrieveProperties>\
                   <urn:_this type="PropertyCollector">propertyCollector</urn:_this>\
                   <urn:specSet>\
                       <urn:propSet>\
                          <urn:type>PerformanceManager</urn:type>\
                          <urn:pathSet>perfCounter</urn:pathSet>\
                       </urn:propSet>\
                       <urn:objectSet>\
                          <urn:obj type="PerformanceManager">PerfMgr</urn:obj>\
                       </urn:objectSet>\
                   </urn:specSet>\
               </urn:RetrieveProperties>\
           </soapenv:Body>\
       </soapenv:Envelope>'
           resp = req.post("{$VMWARE.URL}", query);
           if (req.getStatus() != 200) {
               throw 'Response code: '+req.getStatus();
           }
           Zabbix.log(4, 'vmware metrics=' + resp);
           result = resp;
       
           logout = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:vim25">\
       
           <soapenv:Header/>\
           <soapenv:Body>\
               <urn:Logout>\
                   <urn:_this type="SessionManager">SessionManager</urn:_this>\
               </urn:Logout>\
           </soapenv:Body>\
       </soapenv:Envelope>'
       
           resp = req.post("{$VMWARE.URL}",logout);
       
           if (req.getStatus() != 200) {
               throw 'Response code: '+req.getStatus();
           }
       
       } catch (error) {
       
           Zabbix.log(4, 'vmware call failed : '+error);
           result = {};
       }
       
       返回结果;一旦配置好监控项,点击Test按钮,然后点击Get value。

将接收到的XML复制到任意XML格式化工具中并查找所需的指标。
一个指标的XML示例:
<PerfCounterInfo xsi:type="PerfCounterInfo">
           <key>6</key>
           <nameInfo>
               <label>Usage in MHz</label>
               <summary>CPU usage in megahertz during the interval</summary>
               <key>usagemhz</key>
           </nameInfo>
           <groupInfo>
               <label>CPU</label>
               <summary>CPU</summary>
               <key>cpu</key>
           </groupInfo>
           <unitInfo>
               <label>MHz</label>
               <summary>Megahertz</summary>
               <key>megaHertz</key>
           </unitInfo>
           <rollupType>average</rollupType>
           <statsType>rate</statsType>
           <level>1</level>
           <perDeviceLevel>3</perDeviceLevel>
       </PerfCounterInfo>使用XPath从接收到的XML中提取计数器路径。对于上述示例,XPath表达式为:
| 字段 | xPath | 值 | 
|---|---|---|
| group | //groupInfo[../key=6]/key | cpu | 
| counter | //nameInfo[../key=6]/key | usagemhz | 
| rollup | //rollupType[../key=6] | 平均值 | 
在此情况下的性能计数器路径为:cpu/usagemhz[average]