forked from spring-projects/spring-boot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
8 changed files
with
219 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...or/src/main/java/org/springframework/boot/actuate/autoconfigure/ActuatorMetricWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...a/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetricReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
.../springframework/boot/actuate/metrics/integration/SpringIntegrationMetricReaderTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
|
||
} |