Search in sources :

Example 1 with MetricsFactory

use of org.springframework.integration.support.management.MetricsFactory in project spring-integration by spring-projects.

the class IntegrationManagementConfigurer method afterSingletonsInstantiated.

@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);
    ClassLoader classLoader = IntegrationManagementConfigurer.class.getClassLoader();
    if (ClassUtils.isPresent("io.micrometer.core.instrument.MeterRegistry", classLoader)) {
        this.metricsCaptor = MicrometerMetricsCaptor.loadCaptor(this.applicationContext);
    }
    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;
}
Also used : DefaultMetricsFactory(org.springframework.integration.support.management.DefaultMetricsFactory) MessageSourceMetricsConfigurer(org.springframework.integration.support.management.MessageSourceMetricsConfigurer) DefaultMetricsFactory(org.springframework.integration.support.management.DefaultMetricsFactory) MetricsFactory(org.springframework.integration.support.management.MetricsFactory) IntegrationManagement(org.springframework.integration.support.management.IntegrationManagement)

Example 2 with MetricsFactory

use of org.springframework.integration.support.management.MetricsFactory in project spring-integration by spring-projects.

the class MBeanExporterParserTests method testMBeanExporterExists.

@Test
public void testMBeanExporterExists() {
    IntegrationMBeanExporter exporter = this.context.getBean(IntegrationMBeanExporter.class);
    MBeanServer server = this.context.getBean("mbs", MBeanServer.class);
    Properties properties = TestUtils.getPropertyValue(exporter, "objectNameStaticProperties", Properties.class);
    assertNotNull(properties);
    assertEquals(2, properties.size());
    assertTrue(properties.containsKey("foo"));
    assertTrue(properties.containsKey("bar"));
    assertEquals(server, exporter.getServer());
    assertSame(context.getBean("keyNamer"), TestUtils.getPropertyValue(exporter, "namingStrategy"));
    MessageChannelMetrics metrics = context.getBean("foo", MessageChannelMetrics.class);
    assertTrue(metrics.isCountsEnabled());
    assertFalse(metrics.isStatsEnabled());
    checkCustomized(metrics);
    MessageHandlerMetrics handlerMetrics = context.getBean("transformer.handler", MessageHandlerMetrics.class);
    checkCustomized(handlerMetrics);
    metrics = context.getBean("bar", MessageChannelMetrics.class);
    assertTrue(metrics.isCountsEnabled());
    assertFalse(metrics.isStatsEnabled());
    metrics = context.getBean("baz", MessageChannelMetrics.class);
    assertFalse(metrics.isCountsEnabled());
    assertFalse(metrics.isStatsEnabled());
    metrics = context.getBean("qux", MessageChannelMetrics.class);
    assertFalse(metrics.isCountsEnabled());
    assertFalse(metrics.isStatsEnabled());
    metrics = context.getBean("fiz", MessageChannelMetrics.class);
    assertTrue(metrics.isCountsEnabled());
    assertTrue(metrics.isStatsEnabled());
    metrics = context.getBean("buz", MessageChannelMetrics.class);
    assertTrue(metrics.isCountsEnabled());
    assertTrue(metrics.isStatsEnabled());
    metrics = context.getBean("!excluded", MessageChannelMetrics.class);
    assertFalse(metrics.isCountsEnabled());
    assertFalse(metrics.isStatsEnabled());
    checkCustomized(metrics);
    MetricsFactory factory = context.getBean(MetricsFactory.class);
    IntegrationManagementConfigurer configurer = context.getBean(IntegrationManagementConfigurer.class);
    assertSame(factory, TestUtils.getPropertyValue(configurer, "metricsFactory"));
    exporter.destroy();
}
Also used : MessageHandlerMetrics(org.springframework.integration.support.management.MessageHandlerMetrics) AbstractMessageHandlerMetrics(org.springframework.integration.support.management.AbstractMessageHandlerMetrics) DefaultMessageHandlerMetrics(org.springframework.integration.support.management.DefaultMessageHandlerMetrics) IntegrationManagementConfigurer(org.springframework.integration.config.IntegrationManagementConfigurer) IntegrationMBeanExporter(org.springframework.integration.monitor.IntegrationMBeanExporter) DefaultMessageChannelMetrics(org.springframework.integration.support.management.DefaultMessageChannelMetrics) AbstractMessageChannelMetrics(org.springframework.integration.support.management.AbstractMessageChannelMetrics) MessageChannelMetrics(org.springframework.integration.support.management.MessageChannelMetrics) MetricsFactory(org.springframework.integration.support.management.MetricsFactory) Properties(java.util.Properties) MBeanServer(javax.management.MBeanServer) Test(org.junit.Test)

Aggregations

MetricsFactory (org.springframework.integration.support.management.MetricsFactory)2 Properties (java.util.Properties)1 MBeanServer (javax.management.MBeanServer)1 Test (org.junit.Test)1 IntegrationManagementConfigurer (org.springframework.integration.config.IntegrationManagementConfigurer)1 IntegrationMBeanExporter (org.springframework.integration.monitor.IntegrationMBeanExporter)1 AbstractMessageChannelMetrics (org.springframework.integration.support.management.AbstractMessageChannelMetrics)1 AbstractMessageHandlerMetrics (org.springframework.integration.support.management.AbstractMessageHandlerMetrics)1 DefaultMessageChannelMetrics (org.springframework.integration.support.management.DefaultMessageChannelMetrics)1 DefaultMessageHandlerMetrics (org.springframework.integration.support.management.DefaultMessageHandlerMetrics)1 DefaultMetricsFactory (org.springframework.integration.support.management.DefaultMetricsFactory)1 IntegrationManagement (org.springframework.integration.support.management.IntegrationManagement)1 MessageChannelMetrics (org.springframework.integration.support.management.MessageChannelMetrics)1 MessageHandlerMetrics (org.springframework.integration.support.management.MessageHandlerMetrics)1 MessageSourceMetricsConfigurer (org.springframework.integration.support.management.MessageSourceMetricsConfigurer)1