将自定义JMX指标添加到Google Cloud Monitoring收集的配置

我已按照here

的说明添加了JVM Monitoring插件。

一切正常,我可以,但是现在我想添加更多的JMX指标。例如MemoryPool专用计数器 所以我已将此配置添加到/opt/stackdriver/collectd/etc/collectd.d/jvm-sun-hotspot.conf

<MBean "jvm_localhost_MemoryPool">
    objectname "java.lang:type=MemoryPool,name=*"
    InstanceFrom "name"
    <Value>
        Type "gauge"
        InstancePrefix "memorypool-usage_used"
        Table false
        Attribute "Usage.used"
    </Value>
</MBean>

Collect "jvm_localhost_MemoryPool"

Connection部分

它似乎是有效的收集配置,但是当它发送到Stackdriver / Google Cloud Monitoring时,它会被拒绝。

012    {#012      "index": 261,#012      "valueErrors": [#012        {#012          "error": {#012            "code": 3,#012            "message": "Unsupported
 collectd id: plugin: \"jvm\" type: \"gauge\" type_instance: \"memorypool-usagecommitted\""#012          }#012        }#012      ]#012    },#012    {#012
"index": 262,#012            "message": "Unsupported collectd id: plug
in: \"jvm\" type: \"gauge\" type_instance: \"memorypool-usageinit\""#012          }#012        }#012      ]#012    },#012    {#012      "index": 263,#012
"valueErrors": [#012        {#012          "error": {#012            "code": 3,#012            "message": "Unsupported collectd id: plugin: \"jvm\" type: \"gau
ge\" type_instance: \"memorypool-usagemax\""#012          }#012        }#012      ]#012    },#012    {#012      "index": 264,#012      "valueErrors": [#012
    {#012          "error": {#012            "code": 3,#012            "message": "Unsupported

根据我的理解,现在需要将其添加为自定义指标,但是this document建议将其自动创建。 确实,当我查看builtin jvm metrics的列表时,看不到它们如何映射到收集配置中的现有配置上。

例如os-open_fd_count如何映射到os/open_files

查看Google custom collectd implementation发送的实际api请求会很有帮助,但是我看不到增加日志记录的方法。

我可以从this post看到我想查看的可能是自定义指标,但是如何在收集的配置中做到这一点?

我尝试过

InstancePrefix "custom.googleapis.com/memorypool-usage"

但仍然没有喜悦。

有人做过这件事吗,或者可以提供关于我做错事情的任何建议?

iCMS 回答:将自定义JMX指标添加到Google Cloud Monitoring收集的配置

要获取此日志记录,我需要添加stackdriver_metric_type元数据。

现在完整的链条了

<Chain "GenericJMX_jvm">
    <Rule "rewrite_custom_jmx">
        <Match regex>
            Plugin "^GenericJMX$"
            PluginInstance "^jvm.*$"
            TypeInstance "^memorypool-usage_used$"
        </Match>
        <Target "set">
            MetaData "stackdriver_metric_type" "custom.googleapis.com/jvm/memorypool/usage_used"
            MetaData "label:pool" "%{plugin_instance}"
        </Target>
        <Target "replace">
            MetaData "label:pool" "jvm" ""
        </Target>
    </Rule>
    <Rule "rewrite_genericjmx_to_jvm">
        <Match regex>
            Plugin "^GenericJMX$"
            PluginInstance "^jvm.*$"
        </Match>
        <Target "replace">
            PluginInstance "jvm" ""
        </Target>
        <Target "set">
            Plugin "jvm"
        </Target>
        Target "return"
    </Rule>
</Chain>

插件实例是池名称(例如G1 Eden Space),这就是为什么我将其复制到“池”标签中的原因。

这确实在Stackdriver中自动创建了指标,但我还在projects.metricDescriptors.create方法中使用了以下正文来添加描述和单位。

{
  "name": "projects/yourprojecthere/metricDescriptors/custom.googleapis.com/jvm/memorypool/usage_used","labels": [
    {
      "key": "pool","description": "Name of the JVM memory pool."
    }
  ],"metricKind": "GAUGE","valueType": "DOUBLE","unit": "By","description": "Current size in bytes of the memory pool.","type": "custom.googleapis.com/jvm/memorypool/usage_used","monitoredResourceTypes": [
    "gce_instance"
  ]
}

度量标准浏览器中的结果图如下所示 metric explorer graph of memory pool usage

,

故障排除文档[1]有助于确定需要转换的点,并确保转换按预期进行。

[1] https://cloud.google.com/monitoring/agent/custom-metrics-agent#troubleshooting

本文链接:https://www.f2er.com/2120106.html

大家都在问