【问题标题】:Adding custom jmx metrics to google cloud monitoring collectd configuration将自定义 jmx 指标添加到谷歌云监控 collectd 配置
【发布时间】:2020-10-06 09:38:44
【问题描述】:

我已按照here 的描述添加了 JVM 监控插件

这一切都很好,我可以,但现在我想添加更多 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 部分

这似乎是有效的 collectd 配置,但是当它被发送到 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      "valueErrors": [#012        {#012          "error": {#012            "code": 3,#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 的列表时,我看不到它们如何映射到 collectd 配置中的现有列表。

例如os-open_fd_count 是如何映射到 os/open_files 的?

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

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

我试过了

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

但仍然没有快乐。

以前有没有人这样做过,或者可以就我做错了什么提供任何建议?

【问题讨论】:

    标签: stackdriver google-cloud-stackdriver collectd google-cloud-monitoring


    【解决方案1】:

    要获取此日志记录,我需要添加 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"
      ]
    }
    

    指标资源管理器中的结果图如下所示

    【讨论】:

      【解决方案2】:

      疑难解答文档 [1] 可能有助于确定需要转换哪些点,并确保您的转换行为符合预期。

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

      【讨论】:

      • 感谢@shafiq-i,日志记录实际上并没有那么有用,但链接页面的其余部分却有用。我不知道当我之前试图让它工作时我是怎么错过那个页面的。关键是重写消息以包含stackdriver_metric_type 元数据。它非常冗长,但我至少让它工作了。我将在我的原始帖子的配置中添加一个答案。
      • 能否提供您使用的jvm-sun-hotspot文件?我面临同样的问题
      猜你喜欢
      • 1970-01-01
      • 2021-12-02
      • 1970-01-01
      • 1970-01-01
      • 2015-06-01
      • 2014-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多