-1

I am trying to publish custom metrics from my MyCustomExecutor class to the /metrics endpoint using the Prometheus Java Agent. I have implemented a custom executor class as follows:

@Slf4j
public class MyCustomExecutor extends ScheduledThreadPoolExecutor {
    private String cluster;
    private static final PrometheusMeterRegistry prometheusRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
    static{
        Metrics.addRegistry(prometheusRegistry);
    }
    
    public MyCustomExecutor(int corePoolSize, String cluster) {
        super(corePoolSize, new ThreadFactoryBuilder().setNameFormat(cluster+"_Query_Executor"+"-%d").build());
        this.cluster=cluster;
        new ExecutorServiceMetrics(this, cluster+"_Query_Executor", Tags.empty()).bindTo(prometheusRegistry);
    }
}

I want to publish the metrics of MyCustomExecutor to the Prometheus /metrics endpoint. To do this, I've tried using ExecutorServiceMetrics.monitor and MBeanServer to register the ScheduledExecutorService as an MBean. However, the MBean registration is throwing a NotCompliantMBeanException.

I have also tried adding the ScheduledExecutorService as a bean to the Metrics.globalRegistry, but it doesn't seem to publish the metrics to the /metrics endpoint.

Could you please guide me on how to correctly publish the custom ScheduledExecutorService metrics to the /metrics endpoint using the Prometheus Java Agent? Any insights or suggestions on what I might be missing in the configuration would be greatly appreciated.

Thank you!

  • 1
    So, what is your question? Check: [How to ask a good question](https://stackoverflow.com/help/how-to-ask) – TP95 Aug 04 '23 at 17:57
  • Please put all the information in the question, not in comments. You can edit the question to add details. – aled Aug 04 '23 at 18:02

0 Answers0