【问题标题】:Spring integration with jmxtrans-agent to monitor beanSpring 与 jmxtrans-agent 集成以监控 bean
【发布时间】:2016-10-10 18:03:34
【问题描述】:

我正在使用 Spring 集成,但想使用 jmxtrans-agent 来监控我的拆分器。就像下面的简单示例一样,我尝试计算到达拆分器的请求数。

@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>

我无法查询数据,出现此错误。

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)
  • 此拆分器是否必须实现某个类才能管理资源?
  • 我以为spring集成bean的作用域是每个请求,如果jmxtrans-agent每20s收集一次信息,会不会漏掉数据?

【问题讨论】:

  • 请尝试重新表述您的问题。我花了大约 15 分钟来了解发生了什么。是的,您的类必须用@ManagedResource@ManagedAttribute 标记才能公开为MBean。不,Spring Integration 组件是singleton。您的number 将是任何多线程的集合。虽然不清楚 number 是什么意思...
  • 感谢帮助,我只是试着编一个例子来统计请求到达splitter的数量,并使用jmxtrans-agent来监控它。我做了上面的编码,但我得到了 getAttribute failed 错误。我用大写和小写 C 尝试了“attribute='Count'”。
  • 请确认您真的可以通过 JMX 控制台看到您的 Splitter 并且可以请求该属性。
  • 使用 jconsole 我可以看到拆分器,但在属性中看不到“计数”。
  • 这很奇怪......嗯。尝试使用@ManagedMetric 而不是@ManagedAttribute

标签: spring spring-integration jmx spring-jmx jmxtrans


【解决方案1】:

哦!很抱歉错过了。现在我看到了你的代码:

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

所以,&lt;bean class="Splitter" /&gt; 是内部 bean,对任何其他环境都不可见。

要使其正常工作,您应该将该 bean 定义移动到顶层并从 &lt;splitter&gt; 引用它:

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

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

您使用 &lt;splitter&gt; 组件进行 JMX 导出,它实际上不公开内部 bean,只公开其自己的托管属性/操作。

【讨论】:

  • 有一个问题,如果我使用 concurrentHashMap 为拆分器做一些统计。在一些请求之后,似乎服务超时,想知道这是否会引入潜在的死锁以及如何处理。
  • 看起来像一个新的 SO 问题!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-29
  • 2016-11-12
相关资源
最近更新 更多