Allow multiple readers/writers to be @ActuatorMetric*
In principle you might have multiple "system" repositories, all of which you want to go to public metrics or not be metrics exporters. This change adds a new annotation and renames the old one, so that reades and writers can be distinguished, and also changes the autowiring of them to accept multiple values. Also adds automatic public metrics for Spring Integration.pull/3002/head
parent
6f38b54800
commit
5ceb35473d
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.autoconfigure;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
|
||||
/**
|
||||
* Qualifier annotation for a metric repository that is used by the actuator (to
|
||||
* distinguish it from others that might be installed by the user).
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@Qualifier
|
||||
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE,
|
||||
ElementType.ANNOTATION_TYPE })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Inherited
|
||||
@Documented
|
||||
public @interface ActuatorMetricWriter {
|
||||
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.boot.actuate.metrics.integration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.boot.actuate.metrics.Metric;
|
||||
import org.springframework.boot.actuate.metrics.reader.MetricReader;
|
||||
import org.springframework.integration.monitor.IntegrationMBeanExporter;
|
||||
import org.springframework.integration.support.management.Statistics;
|
||||
import org.springframework.lang.UsesJava7;
|
||||
|
||||
/**
|
||||
* A {@link MetricReader} for Spring Integration metrics (as provided by spring-integration-jmx).
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@UsesJava7
|
||||
public class SpringIntegrationMetricReader implements MetricReader {
|
||||
|
||||
private final IntegrationMBeanExporter exporter;
|
||||
|
||||
public SpringIntegrationMetricReader(IntegrationMBeanExporter exporter) {
|
||||
this.exporter = exporter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Metric<?> findOne(String metricName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Metric<?>> findAll() {
|
||||
List<Metric<?>> metrics = new ArrayList<Metric<?>>();
|
||||
for (String name : exporter.getChannelNames()) {
|
||||
metrics.addAll(getStatistics("integration.channel." + name + ".errorRate", exporter.getChannelErrorRate(name)));
|
||||
metrics.addAll(getStatistics("integration.channel." + name + ".sendRate", exporter.getChannelSendRate(name)));
|
||||
metrics.add(new Metric<Long>("integration.channel." + name + ".receiveCount", exporter.getChannelReceiveCountLong(name)));
|
||||
}
|
||||
for (String name : exporter.getHandlerNames()) {
|
||||
metrics.addAll(getStatistics("integration.handler." + name + ".duration", exporter.getHandlerDuration(name)));
|
||||
}
|
||||
metrics.add(new Metric<Long>("integration.activeHandlerCount", exporter.getActiveHandlerCountLong()));
|
||||
metrics.add(new Metric<Integer>("integration.handlerCount", exporter.getHandlerCount()));
|
||||
metrics.add(new Metric<Integer>("integration.channelCount", exporter.getChannelCount()));
|
||||
metrics.add(new Metric<Integer>("integration.queuedMessageCount", exporter.getQueuedMessageCount()));
|
||||
return metrics;
|
||||
}
|
||||
|
||||
private Collection<? extends Metric<?>> getStatistics(String name, Statistics statistic) {
|
||||
List<Metric<?>> metrics = new ArrayList<Metric<?>>();
|
||||
metrics.add(new Metric<Double>(name + ".mean", statistic.getMean()));
|
||||
metrics.add(new Metric<Double>(name + ".max", statistic.getMax()));
|
||||
metrics.add(new Metric<Double>(name + ".min", statistic.getMin()));
|
||||
metrics.add(new Metric<Double>(name + ".stdev", statistic.getStandardDeviation()));
|
||||
metrics.add(new Metric<Long>(name + ".count", statistic.getCountLong()));
|
||||
return metrics;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long count() {
|
||||
return exporter.getChannelCount()*11 + exporter.getHandlerCount()*5 + 4;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package org.springframework.boot.actuate.metrics.integration;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.metrics.integration.SpringIntegrationMetricReaderTests.TestConfiguration;
|
||||
import org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.integration.monitor.IntegrationMBeanExporter;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes=TestConfiguration.class)
|
||||
@IntegrationTest("spring.jmx.enabled=true")
|
||||
@DirtiesContext
|
||||
public class SpringIntegrationMetricReaderTests {
|
||||
|
||||
@Autowired
|
||||
private SpringIntegrationMetricReader reader;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
assertTrue(reader.count()>0);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@Import({JmxAutoConfiguration.class, IntegrationAutoConfiguration.class})
|
||||
protected static class TestConfiguration {
|
||||
@Bean
|
||||
public SpringIntegrationMetricReader reader(IntegrationMBeanExporter exporter) {
|
||||
return new SpringIntegrationMetricReader(exporter);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue