簡體   English   中英

使用JMX監視應用程序服務器

[英]Monitor application server with JMX

我發現了使用JMX和Java監視JBoss的簡單示例

public class JMXExample {

    public static void main(String[] args) throws Exception {
        //Get a connection to the JBoss AS MBean server on localhost
        String host = "localhost";
        int port = 9999;  // management-native port
        String urlString =
            System.getProperty("jmx.service.url","service:jmx:remoting-jmx://" + host + ":" + port);
        JMXServiceURL serviceURL = new JMXServiceURL(urlString);
        JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, null);
        MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();

        //Invoke on the JBoss AS MBean server
        int count = connection.getMBeanCount();
        System.out.println(count);
        jmxConnector.close();
    }
}

我想每3秒調用一次此代碼以獲取實時性能數據。

有沒有辦法打開與服務器的一個連接並發送頻繁的請求?

如果將此代碼部署為EJB,則可以將其設置為@Singleton @Startup ,並通過@PostConstruct方法設置連接,同時根據@Schedule定期收集指標。 例如:

@Singleton
@Startup
public class MetricsGathering {
    @PostConstruct
    public void init() {
        // setup the connection
    }

    @Schedule(second="*/5")
    public void collect() {
        // get the data and do something with it
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM