0

我想尝试使用 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"
        }
    ]
}

在启用调试级别日志时,我发现由于 spring 循环引用错误,未创建 jmxtrans spring bean

调试 osbfsDefaultListableBeanFactory 1426 - 忽略 FactoryBean 类型检查中的 bean 创建异常:org.springframework.beans.factory.BeanCurrentlyInCreationException:创建名称为“jmxtrans”的 bean 时出错:当前正在创建请求的 bean:是否存在无法解析的循环引用?

完整的春季日志在这里共享 - http://pastebin.com/p2VeNEzE

可能缺少什么?

谢谢!

4

1 回答 1

0

上述关于循环引用的调试日志消息具有误导性。在我从应用程序上下文中获取 jmxtrans bean 并调用 start() 方法后,问题得到了解决。

于 2014-12-07T06:37:59.607 回答