INT-3496: JMX Metrics: Int->Long for All count
JIRA: https://jira.spring.io/browse/INT-3496 **Cherry-pick to 4.0.x & 3.0.x** INT-3496: revert `int` methods and introduce `long` methods for `count` metrics Conflicts: spring-integration-jmx/src/main/java/org/springframework/integration/monitor/DirectChannelMetrics.java spring-integration-jmx/src/main/java/org/springframework/integration/monitor/PollableChannelMetrics.java spring-integration-jmx/src/main/java/org/springframework/integration/monitor/SimpleMessageHandlerMetrics.java spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests.java Resolved.
This commit is contained in:
committed by
Gary Russell
parent
ffa352fbca
commit
42800b75d2
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2009-2010 the original author or authors.
|
||||
*
|
||||
* Copyright 2009-2014 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.
|
||||
@@ -13,12 +13,13 @@
|
||||
|
||||
package org.springframework.integration.monitor;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
@@ -27,7 +28,7 @@ import org.springframework.util.StopWatch;
|
||||
/**
|
||||
* Registers all message channels, and accumulates statistics about their performance. The statistics are then published
|
||||
* locally for other components to consume and publish remotely.
|
||||
*
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Helena Edelson
|
||||
* @since 2.0
|
||||
@@ -44,7 +45,7 @@ public class DirectChannelMetrics implements MethodInterceptor, MessageChannelMe
|
||||
public static final int DEFAULT_MOVING_AVERAGE_WINDOW = 10;
|
||||
|
||||
|
||||
private ExponentialMovingAverage sendDuration = new ExponentialMovingAverage(
|
||||
private final ExponentialMovingAverage sendDuration = new ExponentialMovingAverage(
|
||||
DEFAULT_MOVING_AVERAGE_WINDOW);
|
||||
|
||||
private final ExponentialMovingAverageRate sendErrorRate = new ExponentialMovingAverageRate(
|
||||
@@ -56,9 +57,9 @@ public class DirectChannelMetrics implements MethodInterceptor, MessageChannelMe
|
||||
private final ExponentialMovingAverageRate sendRate = new ExponentialMovingAverageRate(
|
||||
ONE_SECOND_SECONDS, ONE_MINUTE_SECONDS, DEFAULT_MOVING_AVERAGE_WINDOW);
|
||||
|
||||
private final AtomicInteger sendCount = new AtomicInteger();
|
||||
private final AtomicLong sendCount = new AtomicLong();
|
||||
|
||||
private final AtomicInteger sendErrorCount = new AtomicInteger();
|
||||
private final AtomicLong sendErrorCount = new AtomicLong();
|
||||
|
||||
private final String name;
|
||||
|
||||
@@ -85,6 +86,7 @@ public class DirectChannelMetrics implements MethodInterceptor, MessageChannelMe
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
String method = invocation.getMethod().getName();
|
||||
MessageChannel channel = (MessageChannel) invocation.getThis();
|
||||
@@ -136,7 +138,8 @@ public class DirectChannelMetrics implements MethodInterceptor, MessageChannelMe
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized void reset() {
|
||||
sendDuration.reset();
|
||||
sendErrorRate.reset();
|
||||
@@ -146,54 +149,77 @@ public class DirectChannelMetrics implements MethodInterceptor, MessageChannelMe
|
||||
sendErrorCount.set(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSendCount() {
|
||||
return (int) sendCount.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSendCountLong() {
|
||||
return sendCount.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSendErrorCount() {
|
||||
return (int) sendErrorCount.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSendErrorCountLong() {
|
||||
return sendErrorCount.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTimeSinceLastSend() {
|
||||
return sendRate.getTimeSinceLastMeasurement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMeanSendRate() {
|
||||
return sendRate.getMean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMeanErrorRate() {
|
||||
return sendErrorRate.getMean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMeanErrorRatio() {
|
||||
return 1 - sendSuccessRatio.getMean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMeanSendDuration() {
|
||||
return sendDuration.getMean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMinSendDuration() {
|
||||
return sendDuration.getMin();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxSendDuration() {
|
||||
return sendDuration.getMax();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getStandardDeviationSendDuration() {
|
||||
return sendDuration.getStandardDeviation();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Statistics getSendDuration() {
|
||||
return sendDuration.getStatistics();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Statistics getSendRate() {
|
||||
return sendRate.getStatistics();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statistics getErrorRate() {
|
||||
return sendErrorRate.getStatistics();
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2009-2010 the original author or authors.
|
||||
*
|
||||
* Copyright 2009-2014 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.
|
||||
@@ -20,13 +20,13 @@ package org.springframework.integration.monitor;
|
||||
* weight, with a decay factor determined by a "window" size chosen by the caller. The result is a good approximation to
|
||||
* the statistics of the series but with more weight given to recent measurements, so if the statistics change over time
|
||||
* those trends can be approximately reflected.
|
||||
*
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @since 2.0
|
||||
*/
|
||||
public class ExponentialMovingAverage {
|
||||
|
||||
private volatile int count;
|
||||
private volatile long count;
|
||||
|
||||
private volatile double weight;
|
||||
|
||||
@@ -44,7 +44,7 @@ public class ExponentialMovingAverage {
|
||||
/**
|
||||
* Create a moving average accumulator with decay lapse window provided. Measurements older than this will have
|
||||
* smaller weight than <code>1/e</code>.
|
||||
*
|
||||
*
|
||||
* @param window the exponential lapse window (number of measurements)
|
||||
*/
|
||||
public ExponentialMovingAverage(int window) {
|
||||
@@ -63,7 +63,7 @@ public class ExponentialMovingAverage {
|
||||
|
||||
/**
|
||||
* Add a new measurement to the series.
|
||||
*
|
||||
*
|
||||
* @param value the measurement to append
|
||||
*/
|
||||
public synchronized void append(double value) {
|
||||
@@ -83,6 +83,13 @@ public class ExponentialMovingAverage {
|
||||
* @return the number of measurements recorded
|
||||
*/
|
||||
public int getCount() {
|
||||
return (int) count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of measurements recorded
|
||||
*/
|
||||
public long getCountLong() {
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009-2013 the original author or authors.
|
||||
* Copyright 2009-2014 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
|
||||
@@ -96,6 +96,14 @@ public class ExponentialMovingAverageRate {
|
||||
return rates.getCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of measurements recorded
|
||||
* @since 3.0
|
||||
*/
|
||||
public long getCountLong() {
|
||||
return rates.getCountLong();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the time in seconds since the last measurement
|
||||
*/
|
||||
@@ -107,7 +115,7 @@ public class ExponentialMovingAverageRate {
|
||||
* @return the mean value
|
||||
*/
|
||||
public double getMean() {
|
||||
int count = rates.getCount();
|
||||
long count = rates.getCountLong();
|
||||
if (count == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009-2010 the original author or authors.
|
||||
* Copyright 2009-2014 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
|
||||
@@ -88,6 +88,13 @@ public class ExponentialMovingAverageRatio {
|
||||
return cumulative.getCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of measurements recorded
|
||||
*/
|
||||
public long getCountLong() {
|
||||
return cumulative.getCountLong();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the time in seconds since the last measurement
|
||||
*/
|
||||
@@ -99,7 +106,7 @@ public class ExponentialMovingAverageRatio {
|
||||
* @return the mean success rate
|
||||
*/
|
||||
public double getMean() {
|
||||
int count = cumulative.getCount();
|
||||
long count = cumulative.getCountLong();
|
||||
if (count == 0) {
|
||||
// Optimistic to start: success rate is 100%
|
||||
return 1;
|
||||
|
||||
@@ -695,9 +695,14 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
|
||||
|
||||
@ManagedMetric(metricType = MetricType.GAUGE, displayName = "Active Handler Count")
|
||||
public int getActiveHandlerCount() {
|
||||
return (int) getActiveHandlerCountLong();
|
||||
}
|
||||
|
||||
@ManagedMetric(metricType = MetricType.GAUGE, displayName = "Active Handler Count")
|
||||
public long getActiveHandlerCountLong() {
|
||||
int count = 0;
|
||||
for (MessageHandlerMetrics monitor : handlers) {
|
||||
count += monitor.getActiveCount();
|
||||
count += monitor.getActiveCountLong();
|
||||
}
|
||||
return count;
|
||||
}
|
||||
@@ -727,17 +732,25 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
|
||||
}
|
||||
|
||||
public int getSourceMessageCount(String name) {
|
||||
return (int) getSourceMessageCountLong(name);
|
||||
}
|
||||
|
||||
public long getSourceMessageCountLong(String name) {
|
||||
if (sourcesByName.containsKey(name)) {
|
||||
return sourcesByName.get(name).getMessageCount();
|
||||
return sourcesByName.get(name).getMessageCountLong();
|
||||
}
|
||||
logger.debug("No source found for (" + name + ")");
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int getChannelReceiveCount(String name) {
|
||||
return (int) getChannelReceiveCountLong(name);
|
||||
}
|
||||
|
||||
public long getChannelReceiveCountLong(String name) {
|
||||
if (channelsByName.containsKey(name)) {
|
||||
if (channelsByName.get(name) instanceof PollableChannelMetrics) {
|
||||
return ((PollableChannelMetrics) channelsByName.get(name)).getReceiveCount();
|
||||
return ((PollableChannelMetrics) channelsByName.get(name)).getReceiveCountLong();
|
||||
}
|
||||
}
|
||||
logger.debug("No channel found for (" + name + ")");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -24,7 +24,7 @@ import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
/**
|
||||
* A {@link MessageHandlerMetrics} that exposes in addition the {@link Lifecycle} interface. The lifecycle methods can
|
||||
* be used to stop and start polling endpoints, for instance, in a live system.
|
||||
*
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @since 2.0
|
||||
*/
|
||||
@@ -41,64 +41,92 @@ public class LifecycleMessageHandlerMetrics implements MessageHandlerMetrics, Li
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@ManagedAttribute
|
||||
public boolean isRunning() {
|
||||
return this.lifecycle.isRunning();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ManagedOperation
|
||||
public void start() {
|
||||
this.lifecycle.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ManagedOperation
|
||||
public void stop() {
|
||||
this.lifecycle.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
this.delegate.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getErrorCount() {
|
||||
return this.delegate.getErrorCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHandleCount() {
|
||||
return this.delegate.getHandleCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxDuration() {
|
||||
return this.delegate.getMaxDuration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMeanDuration() {
|
||||
return this.delegate.getMeanDuration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMinDuration() {
|
||||
return this.delegate.getMinDuration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getStandardDeviationDuration() {
|
||||
return this.delegate.getStandardDeviationDuration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statistics getDuration() {
|
||||
return this.delegate.getDuration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.delegate.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSource() {
|
||||
return this.delegate.getSource();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getActiveCount() {
|
||||
return this.delegate.getActiveCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getHandleCountLong() {
|
||||
return this.delegate.getHandleCountLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getErrorCountLong() {
|
||||
return this.delegate.getErrorCountLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getActiveCountLong() {
|
||||
return this.delegate.getActiveCountLong();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -24,7 +24,7 @@ import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
/**
|
||||
* A {@link MessageSourceMetrics} that exposes in addition the {@link Lifecycle} interface. The lifecycle methods can
|
||||
* be used to start and stop polling endpoints, for instance, in a live system.
|
||||
*
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @since 2.0
|
||||
*/
|
||||
@@ -78,4 +78,9 @@ public class LifecycleMessageSourceMetrics implements MessageSourceMetrics, Life
|
||||
return this.delegate.getMessageCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMessageCountLong() {
|
||||
return this.delegate.getMessageCountLong();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -23,7 +23,7 @@ import org.springframework.jmx.support.MetricType;
|
||||
/**
|
||||
* Interface for all message channel monitors containing accessors for various useful metrics that are generic for all
|
||||
* channel types.
|
||||
*
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @since 2.0
|
||||
*/
|
||||
@@ -38,12 +38,26 @@ public interface MessageChannelMetrics {
|
||||
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "MessageChannel Send Count")
|
||||
int getSendCount();
|
||||
|
||||
/**
|
||||
* @return the number of successful sends
|
||||
* @since 3.0
|
||||
*/
|
||||
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "MessageChannel Send Count")
|
||||
long getSendCountLong();
|
||||
|
||||
/**
|
||||
* @return the number of failed sends (either throwing an exception or rejected by the channel)
|
||||
*/
|
||||
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "MessageChannel Send Error Count")
|
||||
int getSendErrorCount();
|
||||
|
||||
/**
|
||||
* @return the number of failed sends (either throwing an exception or rejected by the channel)
|
||||
* @since 3.0
|
||||
*/
|
||||
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "MessageChannel Send Error Count")
|
||||
long getSendErrorCountLong();
|
||||
|
||||
/**
|
||||
* @return the time in seconds since the last send
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -35,12 +35,26 @@ public interface MessageHandlerMetrics {
|
||||
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "Handler Execution Count")
|
||||
int getHandleCount();
|
||||
|
||||
/**
|
||||
* @return the number of successful handler calls
|
||||
* @since 3.0
|
||||
*/
|
||||
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "Handler Execution Count")
|
||||
long getHandleCountLong();
|
||||
|
||||
/**
|
||||
* @return the number of failed handler calls
|
||||
*/
|
||||
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "Handler Error Count")
|
||||
int getErrorCount();
|
||||
|
||||
/**
|
||||
* @return the number of failed handler calls
|
||||
* @since 3.0
|
||||
*/
|
||||
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "Handler Error Count")
|
||||
long getErrorCountLong();
|
||||
|
||||
/**
|
||||
* @return the mean handler duration (milliseconds)
|
||||
*/
|
||||
@@ -64,10 +78,13 @@ public interface MessageHandlerMetrics {
|
||||
*/
|
||||
@ManagedMetric(metricType = MetricType.GAUGE, displayName = "Handler Standard Deviation Duration in Milliseconds")
|
||||
double getStandardDeviationDuration();
|
||||
|
||||
|
||||
@ManagedMetric(metricType = MetricType.GAUGE, displayName = "Handler Active Execution Count")
|
||||
int getActiveCount();
|
||||
|
||||
|
||||
@ManagedMetric(metricType = MetricType.GAUGE, displayName = "Handler Active Execution Count")
|
||||
long getActiveCountLong();
|
||||
|
||||
/**
|
||||
* @return summary statistics about the handler duration (milliseconds)
|
||||
*/
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -32,6 +32,13 @@ public interface MessageSourceMetrics {
|
||||
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "Message Source Message Count")
|
||||
int getMessageCount();
|
||||
|
||||
/**
|
||||
* @return the number of successful handler calls
|
||||
* @since 3.0
|
||||
*/
|
||||
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "Message Source Message Count")
|
||||
long getMessageCountLong();
|
||||
|
||||
String getName();
|
||||
|
||||
String getSource();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -16,9 +16,10 @@
|
||||
|
||||
package org.springframework.integration.monitor;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.jmx.export.annotation.ManagedMetric;
|
||||
import org.springframework.jmx.export.annotation.ManagedOperation;
|
||||
@@ -30,9 +31,9 @@ import org.springframework.jmx.support.MetricType;
|
||||
*/
|
||||
public class PollableChannelMetrics extends DirectChannelMetrics {
|
||||
|
||||
private final AtomicInteger receiveCount = new AtomicInteger();
|
||||
private final AtomicLong receiveCount = new AtomicLong();
|
||||
|
||||
private final AtomicInteger receiveErrorCount = new AtomicInteger();
|
||||
private final AtomicLong receiveErrorCount = new AtomicLong();
|
||||
|
||||
|
||||
public PollableChannelMetrics(MessageChannel messageChannel, String name) {
|
||||
@@ -64,6 +65,7 @@ public class PollableChannelMetrics extends DirectChannelMetrics {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ManagedOperation
|
||||
public synchronized void reset() {
|
||||
super.reset();
|
||||
@@ -73,11 +75,21 @@ public class PollableChannelMetrics extends DirectChannelMetrics {
|
||||
|
||||
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "MessageChannel Receive Count")
|
||||
public int getReceiveCount() {
|
||||
return (int) this.receiveCount.get();
|
||||
}
|
||||
|
||||
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "MessageChannel Receive Count")
|
||||
public long getReceiveCountLong() {
|
||||
return this.receiveCount.get();
|
||||
}
|
||||
|
||||
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "MessageChannel Receive Error Count")
|
||||
public int getReceiveErrorCount() {
|
||||
return (int) this.receiveErrorCount.get();
|
||||
}
|
||||
|
||||
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "MessageChannel Receive Error Count")
|
||||
public long getReceiveErrorCountLong() {
|
||||
return this.receiveErrorCount.get();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -16,12 +16,13 @@
|
||||
|
||||
package org.springframework.integration.monitor;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.core.MessageHandler;
|
||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
@@ -41,11 +42,11 @@ public class SimpleMessageHandlerMetrics implements MethodInterceptor, MessageHa
|
||||
|
||||
private final MessageHandler handler;
|
||||
|
||||
private final AtomicInteger activeCount = new AtomicInteger();
|
||||
private final AtomicLong activeCount = new AtomicLong();
|
||||
|
||||
private final AtomicInteger handleCount = new AtomicInteger();
|
||||
private final AtomicLong handleCount = new AtomicLong();
|
||||
|
||||
private final AtomicInteger errorCount = new AtomicInteger();
|
||||
private final AtomicLong errorCount = new AtomicLong();
|
||||
|
||||
private final ExponentialMovingAverage duration = new ExponentialMovingAverage(DEFAULT_MOVING_AVERAGE_WINDOW);
|
||||
|
||||
@@ -63,6 +64,7 @@ public class SimpleMessageHandlerMetrics implements MethodInterceptor, MessageHa
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
@@ -71,6 +73,7 @@ public class SimpleMessageHandlerMetrics implements MethodInterceptor, MessageHa
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSource() {
|
||||
return this.source;
|
||||
}
|
||||
@@ -79,6 +82,7 @@ public class SimpleMessageHandlerMetrics implements MethodInterceptor, MessageHa
|
||||
return this.handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
String method = invocation.getMethod().getName();
|
||||
if ("handleMessage".equals(method)) {
|
||||
@@ -117,43 +121,67 @@ public class SimpleMessageHandlerMetrics implements MethodInterceptor, MessageHa
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void reset() {
|
||||
this.duration.reset();
|
||||
this.errorCount.set(0);
|
||||
this.handleCount.set(0);
|
||||
}
|
||||
|
||||
public int getHandleCount() {
|
||||
@Override
|
||||
public long getHandleCountLong() {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Getting Handle Count:" + this);
|
||||
}
|
||||
return this.handleCount.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHandleCount() {
|
||||
return (int) getHandleCountLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getErrorCount() {
|
||||
return (int) this.errorCount.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getErrorCountLong() {
|
||||
return this.errorCount.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMeanDuration() {
|
||||
return this.duration.getMean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMinDuration() {
|
||||
return this.duration.getMin();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxDuration() {
|
||||
return this.duration.getMax();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getStandardDeviationDuration() {
|
||||
return this.duration.getStandardDeviation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getActiveCount() {
|
||||
return (int) this.activeCount.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getActiveCountLong() {
|
||||
return this.activeCount.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statistics getDuration() {
|
||||
return this.duration.getStatistics();
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -13,10 +13,11 @@
|
||||
|
||||
package org.springframework.integration.monitor;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import org.springframework.integration.core.MessageSource;
|
||||
|
||||
/**
|
||||
@@ -25,7 +26,7 @@ import org.springframework.integration.core.MessageSource;
|
||||
*/
|
||||
public class SimpleMessageSourceMetrics implements MethodInterceptor, MessageSourceMetrics {
|
||||
|
||||
private final AtomicInteger messageCount = new AtomicInteger();
|
||||
private final AtomicLong messageCount = new AtomicLong();
|
||||
|
||||
private final MessageSource<?> messageSource;
|
||||
|
||||
@@ -35,7 +36,7 @@ public class SimpleMessageSourceMetrics implements MethodInterceptor, MessageSou
|
||||
|
||||
|
||||
public SimpleMessageSourceMetrics(MessageSource<?> messageSource) {
|
||||
this.messageSource = messageSource;
|
||||
this.messageSource = messageSource;
|
||||
}
|
||||
|
||||
|
||||
@@ -64,6 +65,10 @@ public class SimpleMessageSourceMetrics implements MethodInterceptor, MessageSou
|
||||
}
|
||||
|
||||
public int getMessageCount() {
|
||||
return (int) this.messageCount.get();
|
||||
}
|
||||
|
||||
public long getMessageCountLong() {
|
||||
return this.messageCount.get();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -22,7 +22,7 @@ package org.springframework.integration.monitor;
|
||||
*/
|
||||
public class Statistics {
|
||||
|
||||
private final int count;
|
||||
private final long count;
|
||||
|
||||
private final double min;
|
||||
|
||||
@@ -33,7 +33,7 @@ public class Statistics {
|
||||
private final double standardDeviation;
|
||||
|
||||
|
||||
public Statistics(int count, double min, double max, double mean, double standardDeviation) {
|
||||
public Statistics(long count, double min, double max, double mean, double standardDeviation) {
|
||||
this.count = count;
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
@@ -43,29 +43,33 @@ public class Statistics {
|
||||
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
return (int) this.count;
|
||||
}
|
||||
|
||||
public long getCountLong() {
|
||||
return this.count;
|
||||
}
|
||||
|
||||
public double getMin() {
|
||||
return min;
|
||||
return this.min;
|
||||
}
|
||||
|
||||
public double getMax() {
|
||||
return max;
|
||||
return this.max;
|
||||
}
|
||||
|
||||
public double getMean() {
|
||||
return mean;
|
||||
return this.mean;
|
||||
}
|
||||
|
||||
public double getStandardDeviation() {
|
||||
return standardDeviation;
|
||||
return this.standardDeviation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("[N=%d, min=%f, max=%f, mean=%f, sigma=%f]",
|
||||
count, min, max, getMean(), getStandardDeviation());
|
||||
this.count, this.min, this.max, getMean(), getStandardDeviation());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -61,7 +61,9 @@
|
||||
<constructor-arg>
|
||||
<array>
|
||||
<value type="java.lang.String">SendCount</value>
|
||||
<value type="java.lang.String">SendCountLong</value>
|
||||
<value type="java.lang.String">SendErrorCount</value>
|
||||
<value type="java.lang.String">SendErrorCountLong</value>
|
||||
</array>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
@@ -105,6 +105,8 @@ public class MBeanAttributeFilterTests {
|
||||
assertEquals(8, bean.size());
|
||||
assertFalse(bean.containsKey("SendCount"));
|
||||
assertFalse(bean.containsKey("SendErrorCount"));
|
||||
assertFalse(bean.containsKey("SendCountLong"));
|
||||
assertFalse(bean.containsKey("SendErrorCountLong"));
|
||||
|
||||
adapterNot.stop();
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -17,6 +17,7 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2009-2010 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.
|
||||
@@ -36,11 +36,11 @@ public class HandlerMonitoringIntegrationTests {
|
||||
private Service service;
|
||||
|
||||
private IntegrationMBeanExporter messageHandlersMonitor;
|
||||
|
||||
|
||||
public void setMessageHandlersMonitor(IntegrationMBeanExporter messageHandlersMonitor) {
|
||||
this.messageHandlersMonitor = messageHandlersMonitor;
|
||||
}
|
||||
|
||||
|
||||
public void setService(Service service) {
|
||||
this.service = service;
|
||||
}
|
||||
@@ -104,7 +104,7 @@ public class HandlerMonitoringIntegrationTests {
|
||||
void execute(String input) throws Exception;
|
||||
int getCounter();
|
||||
}
|
||||
|
||||
|
||||
public static class SimpleService implements Service {
|
||||
private int counter;
|
||||
|
||||
@@ -117,7 +117,7 @@ public class HandlerMonitoringIntegrationTests {
|
||||
return counter;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Aspect
|
||||
public static class HandlerInterceptor {
|
||||
@Before("execution(* *..*Tests*(String)) && args(input)")
|
||||
|
||||
@@ -84,6 +84,8 @@ public class MessageChannelsMonitorIntegrationTests {
|
||||
// The handler monitor is registered under the endpoint id (since it is explicit)
|
||||
int sends = messageChannelsMonitor.getChannelSendRate("" + channel).getCount();
|
||||
assertEquals("No send statistics for input channel", 50, sends, 0.01);
|
||||
long sendsLong = messageChannelsMonitor.getChannelSendRate("" + channel).getCountLong();
|
||||
assertEquals("No send statistics for input channel", sendsLong, sends, 0.01);
|
||||
|
||||
}
|
||||
finally {
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
/*
|
||||
* Copyright 2009-2010 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.integration.monitor;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -26,11 +27,11 @@ public class MessageSourceMonitoringIntegrationTests {
|
||||
private Service service;
|
||||
|
||||
private IntegrationMBeanExporter exporter;
|
||||
|
||||
|
||||
public void setMessageHandlersMonitor(IntegrationMBeanExporter exporter) {
|
||||
this.exporter = exporter;
|
||||
}
|
||||
|
||||
|
||||
public void setService(Service service) {
|
||||
this.service = service;
|
||||
}
|
||||
@@ -78,7 +79,7 @@ public class MessageSourceMonitoringIntegrationTests {
|
||||
String execute() throws Exception;
|
||||
int getCounter();
|
||||
}
|
||||
|
||||
|
||||
public static class SimpleService implements Service {
|
||||
private int counter;
|
||||
|
||||
@@ -92,5 +93,5 @@ public class MessageSourceMonitoringIntegrationTests {
|
||||
return counter;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user