我想尝试使用embedded-jmxtrans的基本入门示例。所以我添加以下代码
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jmxtrans="http://www.jmxtrans.org/schema/embedded"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.jmxtrans.org/schema/embedded http://www.jmxtrans.org/schema/embedded/jmxtrans-1.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config/>
<jmxtrans:jmxtrans>
<jmxtrans:configuration>classpath:jvmmonitoring/jmxtrans/jmxtrans.json</jmxtrans:configuration>
<jmxtrans:configuration>classpath:org/jmxtrans/embedded/config/tomcat-6.json</jmxtrans:configuration>
<jmxtrans:configuration>classpath:org/jmxtrans/embedded/config/jmxtrans-internals.json</jmxtrans:configuration>
<jmxtrans:configuration>classpath:org/jmxtrans/embedded/config/jvm-sun-hotspot.json</jmxtrans:configuration>
</jmxtrans:jmxtrans>
</beans>
public class EmbeddedJMXTrans {
public static void main(String[] args) {
System.setProperty("spring.profiles.active", "dev");
System.setProperty("spring.profiles.default", "dev");
System.setProperty("spring.liveBeansView.mbeanDomain", "dev");
ApplicationContext context = new ClassPathXmlApplicationContext("jvmmonitoring/jmxtrans/spring-beans.xml");
while (true) {
}
}
}
添加while循环以保持应用程序,直到在控制台上打印jvm统计信息。这是jmxtrans.json文件
{
"queries": [
{
"objectName": "java.lang:type=Memory",
"resultAlias": "jvm.memory",
"attributes": [
{
"name": "HeapMemoryUsage",
"keys": ["committed", "used"]
},
{
"name": "NonHeapMemoryUsage",
"keys": ["committed", "used"]
}
]
},
{
"objectName": "java.lang:type=Runtime",
"resultAlias": "jvm.runtime",
"attributes": [
"Uptime"
]
},
{
"objectName": "java.lang:type=GarbageCollector,name=*",
"resultAlias": "jvm.gc.%name%",
"attributes": [
"CollectionCount",
"CollectionTime"
]
},
{
"objectName": "java.lang:type=Threading",
"resultAlias": "jvm.thread",
"attributes": [
"ThreadCount"
]
},
{
"objectName": "java.lang:type=OperatingSystem",
"resultAlias": "jvm.os",
"attributes": [
"CommittedVirtualMemorySize",
"FreePhysicalMemorySize",
"FreeSwapSpaceSize",
"OpenFileDescriptorCount",
"ProcessCpuTime",
"SystemLoadAverage"
]
}
],
"outputWriters": [
{
"@class": "org.jmxtrans.embedded.output.ConsoleWriter"
}
]
}
在启用调试级别日志时,我发现由于弹簧循环引用错误而未创建jmxtrans spring bean
DEBUG osbfsDefaultListableBeanFactory 1426 - 忽略FactoryBean上的bean创建异常类型检查:org.springframework.beans.factory.BeanCurrentlyInCreationException:创建名称为&#39; jmxtrans&#39;的请求错误:请求的bean当前正在创建中:是否存在一个无法解决的循环参考?
此处共享完整的春季日志 - http://pastebin.com/p2VeNEzE
可能缺少什么?
谢谢!
答案 0 :(得分:0)
以上关于循环引用的调试日志消息是错误的。从应用程序上下文中获取jmxtrans bean并调用start()方法后,问题得到了解决。