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;
}
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();
}
Aggregations