I am trying to pattern match and name prometheus metrics with the jmx_exporter java agent (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
.
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. You can also see in the Attribute Description
in openType
the following:
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_max
etc...
Thanks!
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:
By default, you'll have metrics formatted as below:
But if you're like me, you probably want it like so:
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: