-
Hello, I would like to expose some JMX metrics by prometheus exporter (https://kamon.io/docs/latest/reporters/prometheus/). Is it possible? I would prefer to not add instrumentation agent if possible. Can I just expose those metrics in such way? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
There is no automatic way to turn JMX attributes into metrics in Kamon 2.x. We used to have something like that in 1.x, but we never got to upgrade it. I'm personally not a fan of using JMX to expose metrics because the only things that sort of make sense to expose are monotonic counters and gauges, and there were not that many people using it so we will probably not upgrade ourselves (open to contributions, though). That said, I wanted to see how hard would it be to take the values exposed by Slick's def registerBean(): Unit = {
val slickBeans = new ObjectName("slick:type=AsyncExecutor,*")
ManagementFactory
.getPlatformMBeanServer
.queryMBeans(slickBeans, null)
.asScala
.foreach(objectInstance => {
val executorName = objectInstance.getObjectName.getKeyProperty("name")
val proxy = JMX.newMBeanProxy(
ManagementFactory.getPlatformMBeanServer,
objectInstance.getObjectName,
classOf[AsyncExecutorMXBean]
)
registerAsyncExecutorMetrics(proxy, executorName)
})
}
def registerAsyncExecutorMetrics(asyncExecutorMXBean: AsyncExecutorMXBean, executorName: String): Unit = {
Kamon.gauge("slick.executor.queue-size.limit")
.withTag("name", executorName)
.autoUpdate(g => g.update(asyncExecutorMXBean.getMaxQueueSize): Unit)
Kamon.gauge("slick.executor.queue-size.current")
.withTag("name", executorName)
.autoUpdate(g => g.update(asyncExecutorMXBean.getQueueSize): Unit)
Kamon.gauge("slick.executor.threads.limit")
.withTag("name", executorName)
.autoUpdate(g => g.update(asyncExecutorMXBean.getMaxThreads): Unit)
Kamon.gauge("slick.executor.threads.active")
.withTag("name", executorName)
.autoUpdate(g => g.update(asyncExecutorMXBean.getActiveThreads): Unit)
} The first function finds all registered
I got it to run for a couple minutes and send the metrics to Kamon APM and got this data for example: Just using kamon-core and the APM reporter. If you are doing Prometheus it should also work just fine. The entire example is on this gist. |
Beta Was this translation helpful? Give feedback.
There is no automatic way to turn JMX attributes into metrics in Kamon 2.x. We used to have something like that in 1.x, but we never got to upgrade it. I'm personally not a fan of using JMX to expose metrics because the only things that sort of make sense to expose are monotonic counters and gauges, and there were not that many people using it so we will probably not upgrade ourselves (open to contributions, though).
That said, I wanted to see how hard would it be to take the values exposed by Slick's
AsyncExecutorMXBean
and turn them into Kamon gauges that get exposed to every reporter. Turns out it is not that complicated! It all boils down to these two functions: