`Collector already registered that provides name: executor_completed_tasks_total` when using `ExecutorServiceMetrics`
See original GitHub issueHi thanks for the lib! I am facing a problem: I have several ExecutorServices, and want to monitor their metrics. I use code like the following:
scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(config.getBackForthScheduledThreadPoolCoreSize());
scheduledThreadPoolExecutor.setRemoveOnCancelPolicy(true);
new ExecutorServiceMetrics(scheduledThreadPoolExecutor, "ws.back.forth.executor", null)
.bindTo(meterRegistry);
// ... have multiple executors, thus have multiple `new ExecutorServiceMetrics`
However, it throws the following error:
...
Caused by: java.lang.IllegalArgumentException: Collector already registered that provides name: executor_completed_tasks_total
at io.prometheus.client.CollectorRegistry.register(CollectorRegistry.java:54)
at io.prometheus.client.Collector.register(Collector.java:139)
at io.micrometer.prometheus.PrometheusMeterRegistry.lambda$applyToCollector$16(PrometheusMeterRegistry.java:410)
at java.base/java.util.concurrent.ConcurrentHashMap.compute(ConcurrentHashMap.java:1955)
at io.micrometer.prometheus.PrometheusMeterRegistry.applyToCollector(PrometheusMeterRegistry.java:406)
at io.micrometer.prometheus.PrometheusMeterRegistry.newFunctionCounter(PrometheusMeterRegistry.java:240)
at io.micrometer.core.instrument.MeterRegistry$More.lambda$counter$1(MeterRegistry.java:920)
at io.micrometer.core.instrument.MeterRegistry.lambda$registerMeterIfNecessary$5(MeterRegistry.java:561)
at io.micrometer.core.instrument.MeterRegistry.getOrCreateMeter(MeterRegistry.java:614)
at io.micrometer.core.instrument.MeterRegistry.registerMeterIfNecessary(MeterRegistry.java:568)
at io.micrometer.core.instrument.MeterRegistry.registerMeterIfNecessary(MeterRegistry.java:561)
at io.micrometer.core.instrument.MeterRegistry.access$700(MeterRegistry.java:77)
at io.micrometer.core.instrument.MeterRegistry$More.counter(MeterRegistry.java:920)
at io.micrometer.core.instrument.FunctionCounter$Builder.register(FunctionCounter.java:122)
at io.micrometer.core.instrument.binder.jvm.ExecutorServiceMetrics.monitor(ExecutorServiceMetrics.java:312)
at io.micrometer.core.instrument.binder.jvm.ExecutorServiceMetrics.bindTo(ExecutorServiceMetrics.java:275)
at com.rzzsdxx.proj.support_modules.web_socket.back_forth.impl.WsBackForthService.<init>(WsBackForthService.java:60)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:212)
What should I do? Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Comments:27 (13 by maintainers)
Top Results From Across the Web
Prometheus Error: Collector already registered that provides ...
This is probably due to the context being reloaded, and thus collectors trying to re-register to the static CollectorRegistry.
Read more >Error - Collector already registered that provides name
I'm trying to integrate Prometheus to collect Kafka metrics. I'm getting error in starting up Kafka, with the JMX exporter passed as java...
Read more >[prometheus-users] Collector already registered that provides ...
Hey, Your application has probably already registered such metrics. The most popular cause of this is using globals (please avoid those) or ...
Read more >io.prometheus.client.CollectorRegistry.collectorNames java ...
containsKey(name)) { throw new IllegalArgumentException("Collector already registered that provides name: " + name); } } for (String name : names) ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Is it possible that there is code triggering an initial meter being registered, then the subsequent meter is registered (that errors), there are common tags or a filters adding the extra tag?
Just to follow-up, if you wanted to trace and get metrics from an executor service and its submitted tasks using Sleuth and Micrometer, you can make your
ExecutorServicea Spring bean like:And Sleuth will take care of tracing it in auto-configuration.