1

I am using Spring integration but want to use jmxtrans-agent to monitor my splitter. Like following simple example, I try to count the number of request arrive at splitter.

@ManagedResource
public class Splitter {
    private final AtomicInteger count = new AtomicInteger();

    @ManagedAttribute
    public int getCount(){
        return this.count.get();
    }

    public List<JsonNode> split(Message<ArrayNode> message) {
        count.incrementAndGet();
        ...
    }
}

// spring integration workflow
<int:gateway id="myGateway" service-interface="someGateway" default-request-channel="splitChannel" error-channel="errorChannel"  default-reply-channel="replyChannel" async-executor="MyThreadPoolTaskExecutor"/>

<int:splitter id="mySplitter" input-channel="splitChannel" output-channel="transformChannel" method="split">
    <bean class="Splitter" />
</int:splitter>

// in MBeanExporter, I added
<entry key="myApplication:type=Splitter,name=splitter" value-ref="mySplitter" />

// query
<query
    objectName='myApplication:type=Splitter,name=splitter'
    attribute='Count'
    resultAlias='myApplication.Splitter.count'/>
<collectIntervalInSeconds>20</collectIntervalInSeconds>

I cannot query the data, getting this error.

javax.management.AttributeNotFoundException: getAttribute failed: ModelMBeanAttributeInfo not found for number
    at javax.management.modelmbean.RequiredModelMBean.getAttribute(RequiredModelMBean.java:1524)
    at org.springframework.jmx.export.SpringModelMBean.getAttribute(SpringModelMBean.java:109)
  • Does this splitter has to implement some class to be managed resource?
  • I thought spring integration bean scope is per request, if jmxtrans-agent collect information every 20s, is it going to missed the data?
edi
  • 223
  • 5
  • 12
  • Please, try to re-phrase your question. I spend at about 15 mins to understand what's going on. Yes, your class has to be marked with `@ManagedResource` and `@ManagedAttribute` to be exposed as a MBean. No, Spring Integration components are `singleton`. Your `number` will be collection for any multi-threading. Although that isn't clear what is that `number` for... – Artem Bilan Oct 10 '16 at 18:33
  • Thanks for helping, I just try to make up an example to count the number of request arrive at splitter, and use jmxtrans-agent to monitoring it. I did above coding but I am getting getAttribute failed error. I tried " attribute='Count' " with both upper and lower case C. – edi Oct 10 '16 at 20:52
  • Confirm, please, that you really can see your `Splitter` trough the JMX console and can request that attribute. – Artem Bilan Oct 10 '16 at 20:55
  • Using jconsole I can see splitter but not 'count' in Attributes. – edi Oct 10 '16 at 21:19
  • That's odd... M-m-m. Try to use `@ManagedMetric` instead of `@ManagedAttribute` – Artem Bilan Oct 10 '16 at 21:32
  • tried, same thing. yes I only see things like beanName, bean factory, componentType, phase, running and etc... Also, is there any requirement for this attributes? like, the class has to implement *MBean interface, override the getter setter? Even I did that, I still cannot see the attributes. – edi Oct 10 '16 at 21:43
  • Hold on. Looks like you are talking about some other bean, but not your `Splitter`. Do you agree with me that there is no lifecycle attributes in that class? – Artem Bilan Oct 10 '16 at 21:49
  • yes it is my Splitter, there is no lifecycle shown from jconsole attributes – edi Oct 10 '16 at 21:53
  • Would you mind to share some simple Spring Boot application to play from my side? Thanks. Everything sounds strange, because it has a place here for a while. Although I'm not familiar with that `jmxtrans-agent`. Maybe it breaks the proper way for JMX exposition? – Artem Bilan Oct 10 '16 at 22:04
  • Will let u know! Thanks – edi Oct 11 '16 at 01:00
  • I have some news, if I have a bean outside I can see the customized Attributes, if I have the bean inside component and the id is on it cannot see the bean customized attributes, which is what I have shown in the question. This make sense, but if I put the id onto a bean which inside component, in my case it will be . it will failed to launch application. wondering why. Any suggestion? – edi Oct 11 '16 at 04:13

1 Answers1

1

Oh! Sorry for missing that. Now I see your code:

<int:splitter id="mySplitter" input-channel="splitChannel" output-channel="transformChannel" method="split">
    <bean class="Splitter" />
</int:splitter>

So, that <bean class="Splitter" /> is inner bean and it isn't visible for any other environment.

To make it working you should move that bean definition on the top level and reference it from the the <splitter>:

<bean id="mySplitter" class="Splitter" />

<int:splitter id="mySplitter" input-channel="splitChannel" output-channel="transformChannel" ref="mySplitter" method="split"/>

You used the <splitter> component for JMX export which really doesn't expose inner beans, only its own managed attributes/operations.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • there is a problem, if I use a concurrentHashMap to do some stats for splitter. after some request, there it seems like service timeout, wondering whether this will introduce potential deadlock and how to deal with this. – edi Oct 13 '16 at 00:14
  • Looks like a new SO question! – Artem Bilan Oct 13 '16 at 01:22