INT-3753: Expose More Metrics via IMBE

JIRA: https://jira.spring.io/browse/INT-3753

INT-3753: Add Channel Send Count to IMBE

Missing accessor for channel send counts.

Expose Full Metrics Objects
This commit is contained in:
Gary Russell
2015-06-30 09:31:30 -04:00
committed by Artem Bilan
parent 85a4bff69b
commit d9a7e90993
3 changed files with 100 additions and 12 deletions

View File

@@ -659,6 +659,14 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
return channelsByName.keySet().toArray(new String[channelsByName.size()]);
}
public MessageHandlerMetrics getHandlerMetrics(String name) {
if (handlersByName.containsKey(name)) {
return handlersByName.get(name);
}
logger.debug("No handler found for (" + name + ")");
return null;
}
public Statistics getHandlerDuration(String name) {
if (handlersByName.containsKey(name)) {
return handlersByName.get(name).getDuration();
@@ -667,6 +675,14 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
return null;
}
public MessageSourceMetrics getSourceMetrics(String name) {
if (sourcesByName.containsKey(name)) {
return sourcesByName.get(name);
}
logger.debug("No source found for (" + name + ")");
return null;
}
public int getSourceMessageCount(String name) {
return (int) getSourceMessageCountLong(name);
}
@@ -679,6 +695,38 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
return -1;
}
public MessageChannelMetrics getChannelMetrics(String name) {
if (channelsByName.containsKey(name)) {
return channelsByName.get(name);
}
logger.debug("No channel found for (" + name + ")");
return null;
}
public int getChannelSendCount(String name) {
return (int) getChannelSendCountLong(name);
}
public long getChannelSendCountLong(String name) {
if (channelsByName.containsKey(name)) {
return channelsByName.get(name).getSendCountLong();
}
logger.debug("No channel found for (" + name + ")");
return -1;
}
public int getChannelSendErrorCount(String name) {
return (int) getChannelSendErrorCountLong(name);
}
public long getChannelSendErrorCountLong(String name) {
if (channelsByName.containsKey(name)) {
return channelsByName.get(name).getSendErrorCountLong();
}
logger.debug("No channel found for (" + name + ")");
return -1;
}
public int getChannelReceiveCount(String name) {
return (int) getChannelReceiveCountLong(name);
}

View File

@@ -8,10 +8,11 @@
<int:channel id="requests" />
<int:channel id="intermediate">
<int:queue capacity="99" />
<int:queue capacity="1" />
</int:channel>
<int:bridge id="bridge" input-channel="requests" output-channel="intermediate"/>
<int:bridge id="bridge" input-channel="requests" output-channel="intermediate"
send-timeout="1" />
<bean id="mbeanExporter" class="org.springframework.integration.monitor.IntegrationMBeanExporter">
<property name="server" ref="mbeanServer" />
@@ -22,4 +23,8 @@
<property name="locateExistingServerIfPossible" value="true" />
</bean>
<int:inbound-channel-adapter id="source" channel="nullChannel" expression="''">
<int:poller fixed-delay="10" />
</int:inbound-channel-adapter>
</beans>

View File

@@ -1,31 +1,42 @@
/*
* Copyright 2009-2010 the original author or authors.
*
* Copyright 2009-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.integration.monitor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
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.messaging.MessageChannel;
import org.springframework.messaging.MessageDeliveryException;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Dave Syer
* @author Gary Russell
* @since 2.0
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext
public class ChannelIntegrationTests {
@Autowired
@@ -39,19 +50,43 @@ public class ChannelIntegrationTests {
@Test
public void testMessageChannelStatistics() throws Exception {
requests.send(new GenericMessage<String>("foo"));
String intermediateChannelName = "" + intermediate;
assertEquals(1, messageChannelsMonitor.getChannelSendCount(intermediateChannelName));
double rate = messageChannelsMonitor.getChannelSendRate("" + requests).getMean();
assertTrue("No statistics for requests channel", rate >= 0);
rate = messageChannelsMonitor.getChannelSendRate("" + intermediate).getMean();
rate = messageChannelsMonitor.getChannelSendRate(intermediateChannelName).getMean();
assertTrue("No statistics for intermediate channel", rate >= 0);
assertNotNull(intermediate.receive(100L));
double count = messageChannelsMonitor.getChannelReceiveCount("" + intermediate);
assertTrue("No statistics for intermediate channel", count >= 0);
assertEquals(1, messageChannelsMonitor.getChannelReceiveCount(intermediateChannelName));
requests.send(new GenericMessage<String>("foo"));
try {
requests.send(new GenericMessage<String>("foo"));
}
catch (MessageDeliveryException e) {
}
assertEquals(3, messageChannelsMonitor.getChannelSendCount(intermediateChannelName));
assertEquals(1, messageChannelsMonitor.getChannelSendErrorCount(intermediateChannelName));
MessageHandlerMetrics handlerMetrics = messageChannelsMonitor.getHandlerMetrics("bridge");
assertEquals(3, handlerMetrics.getHandleCount());
assertEquals(1, handlerMetrics.getErrorCount());
Thread.sleep(50);
assertTrue(messageChannelsMonitor.getSourceMessageCount("source") > 0);
assertTrue(messageChannelsMonitor.getSourceMetrics("source").getMessageCount() > 0);
}
}