简体   繁体   English

Prometheus jmx 导出器模式匹配属性和项目

[英]Prometheus jmx exporter pattern match for attributes and items

I am trying to pattern match and name prometheus metrics with the jmx_exporter java agent ( https://github.com/prometheus/jmx_exporter ).我正在尝试使用 jmx_exporter java 代理( https://github.com/prometheus/jmx_exporter )对普罗米修斯指标进行模式匹配和命名。

There is not much documentation on how to pattern match on MBean attributes and items within these attributes when dealing with CompositeType .在处理CompositeType时,没有太多关于如何对 MBean 属性和这些属性中的项进行模式匹配的文档。

For instance, I got to the point where I pattern in such a way:例如,我达到了我以这种方式进行模式的地步:

rules:
  - pattern: "java.lang<type=Memory><>HeapMemoryUsage"
    name: jmx_jvm_memory_HeapMemoryUsed

But if you look in VisualVM at HeapMemoryUsed attribute.但是,如果您在 VisualVM 中查看HeapMemoryUsed属性。 You can also see in the Attribute Description in openType the following:您还可以在openTypeAttribute Description中看到以下内容:

javax.management.openmbean.CompositeType(
    name=java.lang.management.MemoryUsage,
    items=(
            (itemName=committed,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),
            (itemName=init,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),
            (itemName=max,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),
            (itemName=used,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long))
        )
    )

I want to be able to name the metric based on these items.我希望能够根据这些项目命名指标。 For example, I would like to have a metrics such as:例如,我想要一个指标,例如:

  • jmx_jvm_memory_HeapMemoryUsed_used jmx_jvm_memory_HeapMemoryUsed_used
  • jmx_jvm_memory_HeapMemoryUsed_max jmx_jvm_memory_HeapMemoryUsed_max

etc... ETC...

Thanks!谢谢!

You're right that the documentation is sparse on this topic.你是对的,关于这个主题的文档很少。 If you look into the source code however, you will find that beans with composite data type are unfolded into metrics for each combination of attribute and value ( JMXScraper.java:207-224 ).但是,如果您查看源代码,您会发现具有复合数据类型的 bean 被展开为每个属性和值组合的指标( JMXScraper.java:207-224 )。


In your case, you can achieve the desired result with the following rules item:在您的情况下,您可以使用以下rules项获得所需的结果:

rules:
  # ... other rules
  - pattern: 'java.lang<type=Memory><(HeapMemoryUsage>(\w+): (.*)'
    name: jmx_jvm_memory_HeapMemoryUsed_$1
    help: "JVM heap memory $1"
    value: $2
    type: GAUGE

If you start your server with JMXExporter agent enabled and query the metrics endpoint, you will see something like the following output如果您在启用 JMXExporter 代理的情况下启动服务器并查询指标端点,您将看到类似于以下 output 的内容

$ curl -s ${server-url}:${jmx-exporter-port}/metrics | grep jmx_jvm
# HELP jmx_jvm_memory_HeapMemoryUsed_committed JVM heap memory committed
# TYPE jmx_jvm_memory_HeapMemoryUsed_committed gauge
jmx_jvm_memory_HeapMemoryUsed_committed 7.7856768E8
# HELP jmx_jvm_memory_HeapMemoryUsed_max JVM heap memory max
# TYPE jmx_jvm_memory_HeapMemoryUsed_max gauge
jmx_jvm_memory_HeapMemoryUsed_max 1.908932608E9
# HELP jmx_jvm_memory_HeapMemoryUsed_init JVM heap memory init
# TYPE jmx_jvm_memory_HeapMemoryUsed_init gauge
jmx_jvm_memory_HeapMemoryUsed_init 2.64241152E8
# HELP jmx_jvm_memory_HeapMemoryUsed_used JVM heap memory used
# TYPE jmx_jvm_memory_HeapMemoryUsed_used gauge
jmx_jvm_memory_HeapMemoryUsed_used 4.7050592E8

Note : as Brian already said in his answer, there is no need to do this for standard JMX beans (such as the ones in the java.lang domain), as JMXExporter already handles them in a standardized way.注意:正如 Brian 在他的回答中已经说过的那样,对于标准 JMX bean(例如java.lang域中的那些)没有必要这样做,因为 JMXExporter 已经以标准化的方式处理它们。

For anyone encountering issues with this, and getting stuck.对于任何遇到此问题并陷入困境的人。 I managed to get it to work.我设法让它工作。

I'm currently porting HBase JMX metrics to Prometheus, and was figuring out how to update metrics with composite values, lets look at an example:我目前正在将 HBase JMX 指标移植到 Prometheus,并且正在研究如何使用复合值更新指标,让我们看一个示例:

{
    "name": "java.lang:type=Memory",
    "modelerType": "sun.management.MemoryImpl",
    "ObjectPendingFinalizationCount": 0,
    "Verbose": false,
    "HeapMemoryUsage": {
        "committed": 127729664,
        "init": 132120576,
        "max": 2087452672,
        "used": 26782688
    },
    "NonHeapMemoryUsage": {
        "committed": 50896896,
        "init": 2555904,
        "max": -1,
        "used": 49540216
    },
    "ObjectName": "java.lang:type=Memory"
},

By default, you'll have metrics formatted as below:默认情况下,您的指标格式如下:

# HELP java_lang_Memory_HeapMemoryUsage_init java.lang.management.MemoryUsage (java.lang<type=Memory><HeapMemoryUsage>init)
# TYPE java_lang_Memory_HeapMemoryUsage_init untyped
java_lang_Memory_HeapMemoryUsage_init 1.32120576E8

But if you're like me, you probably want it like so:但如果你像我一样,你可能想要这样:

# HELP hbase_heap_usage java.lang.management.MemoryUsage (java.lang<type=Memory><HeapMemoryUsage>committed)
# TYPE hbase_heap_usage untyped
hbase_heap_usage{type="committed",} 1.27729664E8
hbase_heap_usage{type="init",} 1.32120576E8
hbase_heap_usage{type="max",} 2.087452672E9
hbase_heap_usage{type="used",} 2.8101728E7

To achieve this, the documentation is not great, and a little bit backwards, when using VisualVM, it will tell you that HeapMemoryUsage is the attribute, but in these composite cases, the keys inside the attribute are the attributes, and the attribute is the key... so to achieve the above, your rule will look like as such:要做到这一点,文档不是很好,有点倒退,在使用VisualVM的时候,它会告诉你HeapMemoryUsage是属性,但是在这些复合情况下,属性里面的键是属性,属性是关键...所以要实现上述目标,您的规则将如下所示:

  - pattern: java.lang<type=Memory><HeapMemoryUsage>(\w+)
    name: hbase_heap_usage
    labels:
      type: $1

If you look at the HELP in the metrics output, that's what you're matching against.如果您查看指标 output 中的HELP ,这就是您要匹配的内容。 However there's no need for you to worry about any of the java.lang metrics, the jmx exporter java agent will provide them for you automatically under the jvm_ metrics prefix.但是,您无需担心任何 java.lang 指标,jmx 导出器 java 代理将在jvm_指标前缀下自动为您提供它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM