Example usage for org.springframework.integration.support.management.micrometer MicrometerMetricsCaptor loadCaptor

List of usage examples for org.springframework.integration.support.management.micrometer MicrometerMetricsCaptor loadCaptor

Introduction

In this page you can find the example usage for org.springframework.integration.support.management.micrometer MicrometerMetricsCaptor loadCaptor.

Prototype

public static MetricsCaptor loadCaptor(ApplicationContext applicationContext) 

Source Link

Document

Add a MicrometerMetricsCaptor to the context if there's a MeterRegistry; if there's already a MetricsCaptor bean, return that.

Usage

From source file:org.springframework.integration.config.IntegrationManagementConfigurer.java

@Override
public void afterSingletonsInstantiated() {
    Assert.state(this.applicationContext != null, "'applicationContext' must not be null");
    Assert.state(MANAGEMENT_CONFIGURER_NAME.equals(this.beanName),
            getClass().getSimpleName() + " bean name must be " + MANAGEMENT_CONFIGURER_NAME);
    if (ClassUtils.isPresent("io.micrometer.core.instrument.MeterRegistry",
            this.applicationContext.getClassLoader())) {
        this.metricsCaptor = MicrometerMetricsCaptor.loadCaptor(this.applicationContext);
    }//from  w  w w . j a v  a 2  s  . co  m
    if (this.metricsCaptor != null) {
        injectCaptor();
        registerComponentGauges();
    }
    if (this.metricsFactory == null && StringUtils.hasText(this.metricsFactoryBeanName)) {
        this.metricsFactory = this.applicationContext.getBean(this.metricsFactoryBeanName,
                MetricsFactory.class);
    }
    if (this.metricsFactory == null) {
        Map<String, MetricsFactory> factories = this.applicationContext.getBeansOfType(MetricsFactory.class);
        if (factories.size() == 1) {
            this.metricsFactory = factories.values().iterator().next();
        }
    }
    if (this.metricsFactory == null) {
        this.metricsFactory = new DefaultMetricsFactory();
    }
    this.sourceConfigurers.putAll(this.applicationContext.getBeansOfType(MessageSourceMetricsConfigurer.class));
    Map<String, IntegrationManagement> managed = this.applicationContext
            .getBeansOfType(IntegrationManagement.class);
    for (Entry<String, IntegrationManagement> entry : managed.entrySet()) {
        IntegrationManagement bean = entry.getValue();
        if (!bean.getOverrides().loggingConfigured) {
            bean.setLoggingEnabled(this.defaultLoggingEnabled);
        }
        String name = entry.getKey();
        doConfigureMetrics(bean, name);
    }
    this.singletonsInstantiated = true;
}