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

概述

VMware性能计数器路径遵循 group/counter[rollup]格式,其中:

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

    average

因此上述示例将生成以下计数器路径: cpu/usagemhz[average]

性能计数器组描述、计数器名称及汇总类型 可在VMware documentation中查阅。

通过使用Zabbix中的监控项脚本,可获取内部名称及create自定义性能计数器名称。

配置

  1. 在主VMware 主机上创建一个禁用的脚本 监控项(存在 eventlog[] 监控项的地方),并设置以下参数:

  • 名称: VMware指标
  • 类型: 脚本
  • : vmware.metrics
  • 信息类型: 文本
  • 脚本: copy 并粘贴下方提供的脚本
  • 超时: 10
  • 历史数据存储周期: 不保留历史记录
  • Enabled: 未标记

脚本

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]