INT-1508: add reset()
This commit is contained in:
@@ -21,6 +21,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.jmx.export.annotation.ManagedMetric;
|
||||
import org.springframework.jmx.export.annotation.ManagedOperation;
|
||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
import org.springframework.jmx.support.MetricType;
|
||||
import org.springframework.util.StopWatch;
|
||||
@@ -130,6 +131,16 @@ public class DirectChannelMetrics implements MethodInterceptor, MessageChannelMe
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ManagedOperation
|
||||
public synchronized void reset() {
|
||||
sendDuration.reset();
|
||||
sendErrorRate.reset();
|
||||
sendSuccessRatio.reset();
|
||||
sendRate.reset();
|
||||
sendCount.set(0);
|
||||
sendErrorCount.set(0);
|
||||
}
|
||||
|
||||
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "MessageChannel Sends")
|
||||
public int getSendCount() {
|
||||
|
||||
@@ -25,17 +25,17 @@ package org.springframework.integration.monitor;
|
||||
*/
|
||||
public class ExponentialMovingAverage {
|
||||
|
||||
private int count;
|
||||
private volatile int count;
|
||||
|
||||
private double weight;
|
||||
private volatile double weight;
|
||||
|
||||
private double sum;
|
||||
private volatile double sum;
|
||||
|
||||
private double sumSquares;
|
||||
private volatile double sumSquares;
|
||||
|
||||
private double min;
|
||||
private volatile double min;
|
||||
|
||||
private double max;
|
||||
private volatile double max;
|
||||
|
||||
private final double decay;
|
||||
|
||||
@@ -49,12 +49,21 @@ public class ExponentialMovingAverage {
|
||||
this.decay = 1 - 1. / window;
|
||||
}
|
||||
|
||||
public synchronized void reset() {
|
||||
weight = 0;
|
||||
sum = 0;
|
||||
sumSquares = 0;
|
||||
count = 0;
|
||||
min = 0;
|
||||
max = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new measurement to the series.
|
||||
*
|
||||
* @param value the measurement to append
|
||||
*/
|
||||
public void append(double value) {
|
||||
public synchronized void append(double value) {
|
||||
if (value > max || count == 0)
|
||||
max = value;
|
||||
if (value < min || count == 0)
|
||||
|
||||
@@ -32,13 +32,13 @@ public class ExponentialMovingAverageRate {
|
||||
|
||||
private final ExponentialMovingAverage rates;
|
||||
|
||||
private double weight;
|
||||
private volatile double weight;
|
||||
|
||||
private double sum;
|
||||
private volatile double sum;
|
||||
|
||||
private double min;
|
||||
private volatile double min;
|
||||
|
||||
private double max;
|
||||
private volatile double max;
|
||||
|
||||
private volatile long t0 = System.currentTimeMillis();
|
||||
|
||||
@@ -57,10 +57,19 @@ public class ExponentialMovingAverageRate {
|
||||
this.period = period * 1000; // convert to millisecs
|
||||
}
|
||||
|
||||
public synchronized void reset() {
|
||||
min = 0;
|
||||
max = 0;
|
||||
weight = 0;
|
||||
sum = 0;
|
||||
t0 = System.currentTimeMillis();
|
||||
rates.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new event to the series.
|
||||
*/
|
||||
public void increment() {
|
||||
public synchronized void increment() {
|
||||
|
||||
long t = System.currentTimeMillis();
|
||||
double value = t > t0 ? (t - t0) / period : 0;
|
||||
|
||||
@@ -28,9 +28,9 @@ package org.springframework.integration.monitor;
|
||||
*/
|
||||
public class ExponentialMovingAverageRatio {
|
||||
|
||||
private double weight;
|
||||
private volatile double weight;
|
||||
|
||||
private double sum;
|
||||
private volatile double sum;
|
||||
|
||||
private volatile long t0 = System.currentTimeMillis();
|
||||
|
||||
@@ -61,7 +61,14 @@ public class ExponentialMovingAverageRatio {
|
||||
append(0);
|
||||
}
|
||||
|
||||
private void append(int value) {
|
||||
public synchronized void reset() {
|
||||
weight = 0;
|
||||
sum = 0;
|
||||
t0 = System.currentTimeMillis();
|
||||
cumulative.reset();
|
||||
}
|
||||
|
||||
private synchronized void append(int value) {
|
||||
|
||||
long t = System.currentTimeMillis();
|
||||
double alpha = Math.exp((t0 - t) * lapse);
|
||||
|
||||
@@ -56,6 +56,11 @@ public class LifecycleMessageHandlerMetrics implements MessageHandlerMetrics, Li
|
||||
lifecycle.stop();
|
||||
}
|
||||
|
||||
@ManagedOperation
|
||||
public void reset() {
|
||||
delegate.reset();
|
||||
}
|
||||
|
||||
public int getErrorCount() {
|
||||
return delegate.getErrorCount();
|
||||
}
|
||||
|
||||
@@ -41,6 +41,11 @@ public class LifecycleMessageSourceMetrics implements MessageSourceMetrics, Life
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@ManagedOperation
|
||||
public void reset() {
|
||||
delegate.reset();
|
||||
}
|
||||
|
||||
@ManagedAttribute
|
||||
public boolean isRunning() {
|
||||
return lifecycle.isRunning();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.integration.monitor;
|
||||
|
||||
import org.springframework.jmx.export.annotation.ManagedMetric;
|
||||
import org.springframework.jmx.export.annotation.ManagedOperation;
|
||||
import org.springframework.jmx.support.MetricType;
|
||||
|
||||
/**
|
||||
@@ -29,6 +30,9 @@ import org.springframework.jmx.support.MetricType;
|
||||
*/
|
||||
public interface MessageChannelMetrics {
|
||||
|
||||
@ManagedOperation
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* @return the number of successful sends
|
||||
*/
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.integration.monitor;
|
||||
|
||||
import org.springframework.jmx.export.annotation.ManagedMetric;
|
||||
import org.springframework.jmx.export.annotation.ManagedOperation;
|
||||
import org.springframework.jmx.support.MetricType;
|
||||
|
||||
/**
|
||||
@@ -25,6 +26,9 @@ import org.springframework.jmx.support.MetricType;
|
||||
*/
|
||||
public interface MessageHandlerMetrics {
|
||||
|
||||
@ManagedOperation
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* @return the number of successful handler calls
|
||||
*/
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
package org.springframework.integration.monitor;
|
||||
|
||||
import org.springframework.jmx.export.annotation.ManagedMetric;
|
||||
import org.springframework.jmx.export.annotation.ManagedOperation;
|
||||
import org.springframework.jmx.support.MetricType;
|
||||
|
||||
/**
|
||||
@@ -23,10 +24,13 @@ import org.springframework.jmx.support.MetricType;
|
||||
*/
|
||||
public interface MessageSourceMetrics {
|
||||
|
||||
@ManagedOperation
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* @return the number of successful handler calls
|
||||
*/
|
||||
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "Message Source Message Count", description = "rate=1h")
|
||||
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "Message Source Message Count")
|
||||
int getMessageCount();
|
||||
|
||||
String getName();
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.jmx.export.annotation.ManagedMetric;
|
||||
import org.springframework.jmx.export.annotation.ManagedOperation;
|
||||
import org.springframework.jmx.support.MetricType;
|
||||
|
||||
/**
|
||||
@@ -67,6 +68,13 @@ public class PollableChannelMetrics extends DirectChannelMetrics {
|
||||
}
|
||||
}
|
||||
|
||||
@ManagedOperation
|
||||
public synchronized void reset() {
|
||||
super.reset();
|
||||
receiveErrorCount.set(0);
|
||||
receiveCount.set(0);
|
||||
}
|
||||
|
||||
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "MessageChannel Receives")
|
||||
public int getReceiveCount() {
|
||||
return receiveCount.get();
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.springframework.integration.MessageHandlingException;
|
||||
import org.springframework.integration.MessageRejectedException;
|
||||
import org.springframework.integration.core.MessageHandler;
|
||||
import org.springframework.jmx.export.annotation.ManagedMetric;
|
||||
import org.springframework.jmx.export.annotation.ManagedOperation;
|
||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
import org.springframework.jmx.support.MetricType;
|
||||
import org.springframework.util.StopWatch;
|
||||
@@ -125,6 +126,13 @@ public class SimpleMessageHandlerMetrics implements MethodInterceptor, MessageHa
|
||||
}
|
||||
}
|
||||
|
||||
@ManagedOperation
|
||||
public synchronized void reset() {
|
||||
duration.reset();
|
||||
errorCount.set(0);
|
||||
handleCount.set(0);
|
||||
}
|
||||
|
||||
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "Handler Execution Count", description = "rate=1h")
|
||||
public int getHandleCount() {
|
||||
if (logger.isTraceEnabled()) {
|
||||
|
||||
@@ -18,6 +18,9 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.springframework.integration.core.MessageSource;
|
||||
import org.springframework.jmx.export.annotation.ManagedMetric;
|
||||
import org.springframework.jmx.export.annotation.ManagedOperation;
|
||||
import org.springframework.jmx.support.MetricType;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -59,6 +62,12 @@ public class SimpleMessageSourceMetrics implements MethodInterceptor, MessageSou
|
||||
return messageSource;
|
||||
}
|
||||
|
||||
@ManagedOperation
|
||||
public void reset() {
|
||||
messageCount.set(0);
|
||||
}
|
||||
|
||||
@ManagedMetric(metricType = MetricType.COUNTER, displayName = "Message Source Message Count")
|
||||
public int getMessageCount() {
|
||||
return messageCount.get();
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
package org.springframework.integration.monitor;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Ignore;
|
||||
@@ -74,4 +75,17 @@ public class ExponentialMovingAverageRateTests {
|
||||
assertTrue("Standard deviation should be non-zero: " + history, history.getStandardDeviation() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testReset() throws Exception {
|
||||
assertEquals(0, history.getStandardDeviation(), 0.01);
|
||||
history.increment();
|
||||
Thread.sleep(30L);
|
||||
history.increment();
|
||||
assertFalse(0==history.getStandardDeviation());
|
||||
history.reset();
|
||||
assertEquals(0, history.getStandardDeviation(), 0.01);
|
||||
assertEquals("[[N=0, min=0.000000, max=0.000000, mean=0.000000, sigma=0.000000], timeSinceLast=0.000000]", history.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.integration.monitor;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -104,6 +105,17 @@ public class ExponentialMovingAverageRatioTests {
|
||||
assertEquals(0, history.getStandardDeviation(), 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReset() throws Exception {
|
||||
assertEquals(0, history.getStandardDeviation(), 0.01);
|
||||
history.success();
|
||||
history.failure();
|
||||
assertFalse(0==history.getStandardDeviation());
|
||||
history.reset();
|
||||
assertEquals(0, history.getStandardDeviation(), 0.01);
|
||||
assertEquals("[[N=0, min=0.000000, max=0.000000, mean=1.000000, sigma=0.000000], timeSinceLast=0.000000]", history.toString());
|
||||
}
|
||||
|
||||
private double average(double... values) {
|
||||
int count = 0;
|
||||
double sum = 0;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.integration.monitor;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -50,4 +51,15 @@ public class ExponentialMovingAverageTests {
|
||||
assertEquals(0, history.getStandardDeviation(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReset() throws Exception {
|
||||
assertEquals(0, history.getStandardDeviation(), 0.01);
|
||||
history.append(1);
|
||||
history.append(2);
|
||||
assertFalse(0==history.getStandardDeviation());
|
||||
history.reset();
|
||||
assertEquals(0, history.getStandardDeviation(), 0.01);
|
||||
assertEquals("[N=0, min=0.000000, max=0.000000, mean=0.000000, sigma=0.000000]", history.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user