collectd-fast-jmx
collectd-fast-jmx copied to clipboard
Support wildcards in Collect option (enhancement request)
It would be nice to be able to use wildcards when listing what MBeans to collect to avoid having to type each one manually. It would be specially helpful to me since I generate the collectd config from other sources of information. For example, I would like to be able to do Collect "cassandra-*"
instead of listing every one of the dozens of metrics.
I think I understand what you're asking for here (pattern matching the bean name to collect).
Something you might not know about though, is that there's already support for using standard [ObjectName pattern] (https://docs.oracle.com/javase/7/docs/api/javax/management/ObjectName.html#apply(javax.management.ObjectName)) expressions when you're defining the mbeans to collect. You can also define what part of the mbean name is then used when reporting the metrics.
This way you can define the bean types you'd like to collect, then get them named based off the actual instance of the bean type you're collecting (discovering).
A common example of this would be something like this:
# Garbage collector information
<MBean "garbage_collector">
ObjectName "java.lang:type=GarbageCollector,*"
InstancePrefix "gc-"
InstanceFrom "name"
<Value "CollectionTime">
Type "total_time_in_ms"
InstancePrefix "collection_time"
PluginName "JVM"
</Value>
# Reads the Par Eden Space data as a composite table
<Value "LastGcInfo.memoryUsageAfterGc.Par Eden Space">
Type "java_memory"
Composite true
InstancePrefix "pool-eden-after"
PluginName "JVM"
</Value>
# Reads only the "used" portion of the Par Eden Space
<Value "LastGcInfo.memoryUsageAfterGc.Par Eden Space.used">
type "java_memory"
InstancePrefix "pool-eden-after-used"
PluginName "JVM"
</Value>
</MBean>
Where we setup a bean type to collect 'garbage_collector', and then define the instance to report the metrics as using the 'InstanceFrom' directive.
This pulls out part of the MBean ObjectName to use for the instance portion of the reported metric.
Then when we Collect garbage_collector
, any MBean which matches the garbage_collector will be collected, and the name of the metric will be dynamically built based off the actual MBean ObjectName which matches the garbage_collector ObjectName pattern expression.
Would this better cover your use-case, or is it not possible for you to extract part of the MBeanName to use for the InstanceFrom
?
Thank you for the through answer @bvarner! I am actually thinking about the Collect option. I'm already using wildcards in object names. I think an example is the best way to demonstrate my use case.
I have a bunch of different metrics from Apache Kafka that I want to extract with collectd. Some of those metrics have to be collected from brokers (servers) and others from producers and consumers (clients). To make configuration easier, I intend to ship config files with just the MBean definitions to all machines, and just enable the ones that I want in the Connection
block separately.
<Mbean "kafka_broker-replica-manager-isr-expands-per-sec">
ObjectName "kafka.server:type=ReplicaManager,name=IsrExpandsPerSec"
InstancePrefix "replica-manager-isr-expands-per-sec"
<Value>
PluginName "kafka"
Type "gauge"
Attribute "Value"
InstancePrefix ""
</Value>
</Mbean>
<Mbean "kafka_broker-kafka-controller-active-controller-count">
ObjectName "kafka.controller:type=KafkaController,name=ActiveControllerCount"
InstancePrefix "kafka-controller-active-controller-count"
<Value>
PluginName "kafka"
Type "counter"
Attribute "Count"
InstancePrefix ""
</Value>
</Mbean>
<Mbean "kafka_consumer-consumer-fetcher-manager-bytes-per-sec">
ObjectName "kafka.consumer:type=ConsumerFetcherManager,clientId=*,name=BytesPerSec"
InstancePrefix "consumer-fetcher-manager-bytes-per-sec"
InstanceFrom "clientId"
<Value>
PluginName "kafka_consumer"
Type "gauge"
Attribute "Value"
InstancePrefix ""
</Value>
</Mbean>
<Mbean "kafka_consumer-consumer-fetcher-manager-messages-per-sec">
ObjectName "kafka.consumer:type=ConsumerFetcherManager,clientId=*,name=MessagesPerSec"
InstancePrefix "consumer-fetcher-manager-messages-per-sec"
InstanceFrom "clientId"
<Value>
PluginName "kafka_consumer"
Type "gauge"
Attribute "Value"
InstancePrefix ""
</Value>
</Mbean>
Currently, I must have something like the following:
<Connection "kafka-broker">
ServiceURL "service:jmx:rmi:///jndi/rmi://kafka-broker:7199/jmxrmi"
Collect "kafka_broker-replica-manager-isr-expands-per-sec"
Collect "kafka_broker-kafka-controller-active-controller-count"
# Imagine some other dozens of metrics here
</Connection>
I would like to be able to use this instead:
<Connection "kafka-broker">
ServiceURL "service:jmx:rmi:///jndi/rmi://kafka-broker:7199/jmxrmi"
Collect "kafka_broker-*"
</Connection>
Thank YOU for the detailed reply! Yes, I agree your use-case makes sense. I've run into situations like this too, and I've always just sort of 'made due'. I'll leave this ticket open, and if you (or someone else) were to put together a pull request, I'd be happy to review it and merge it in!
Otherwise it may take some time before I'm able to look into implementing it. :-)