When using multiple context the tomcat metrics (e.g. threadpools) only show the first context, because the micrometer TomcatMetrics assume always Tomcat as JMX domain.

I found this issue to set a custom jmx domain, but it seems the TomcatMetricsBinder does not set the JXM domain.

We created a copy for the metrics binder and disabled the autoconfiguration, such that we can set the jmx domain, as there is no way to customize the creation of the tomcat metrics.

  @Override
    public void onApplicationEvent(ApplicationStartedEvent event) {
        ApplicationContext applicationContext = event.getApplicationContext();
        Manager manager = findManager(applicationContext);
        this.tomcatMetrics = new TomcatMetrics(manager, tags);
        this.tomcatMetrics.setJmxDomain(manager.getContext().getDomain());
        this.tomcatMetrics.bindTo(this.meterRegistry);
    }

If this change looks good I could do a PR maybe.

Comment From: wilkinsona

Thanks, @atomfrede. I may have forgotten some context, but if not, I think I made a mistake when reviewing that Micrometer change. Looking at it again now, I think it would make more sense if Micrometer used the domain retrieved via the Manager that's passed to it by default rather than placing the onus on the caller to configure it.

@shakuzen @izeye what do you think about changing Micrometer to use manager.getContext().getDomain() as the default JMX domain for TomcatMetrics? If we can figure out if/when to make that change in Micrometer we can then figure out what, if anything, we need to do in Boot.

Comment From: atomfrede

@wilkinsona Thanks for the reply. Yes I think so too, but was a bit confused about the label spring-boot-change in the micrometer issue. But sure TomcatMetrics has the manager and can use it too, would even be better imho.

Comment From: izeye

When I was working on the fix, I didn't know the API. Looking at its Javadoc, it seems reasonable to me, too. I created https://github.com/micrometer-metrics/micrometer/pull/2298 to try to resolve it in Micrometer.

Comment From: atomfrede

Thanks @izeye. I will close this issue here.

Comment From: wilkinsona

Let's keep this one open till we see where the change lands in Micrometer. We may want to configure the domain in Boot's code until Micrometer starts doing it.

Comment From: wilkinsona

This is going to be fixed in Micrometer 1.1.x so we'll be able to pick up the fix without doing anything in Boot for 2.1.x and later.