如何以编程方式转储 JMX 数据?

发布于 2024-08-23 03:50:15 字数 121 浏览 3 评论 0原文

我希望能够记录可通过 jconsole 访问的所有 JMX 数据。有没有办法以编程方式执行此操作?我正在构建一种系统日志记录形式,并且我想创建可使用类似于 jconsole 的工具查看的间隔数据。

我该怎么做呢?

I want to be able to log all JMX data accessible via jconsole. Is there a way to do this programmatically? I'm building a form of logging of the system, and I want to create intervaled data viewable with some tool similar to jconsole.

How would I go about doing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空城旧梦 2024-08-30 03:50:15

java.lang.management.ManagementFactory< /a> 使您可以访问 JMX 数据。

ig

List<MemoryPoolMXBean> memPoolBeans = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean mpb : memPoolBeans) {
    System.out.println("Memory Pool: " + mpb.getName());
}

一些示例可在 SO 查询中找到:[java]+managementfactory

很好的阅读:https://www.ibm.com/developerworks/library/j-jtp09196/index.html

对于连接到远程 VM 的完整实现:

Map<String,String[]> env = new HashMap<String, String[]>();
env.put( JMXConnector.CREDENTIALS, new String[]{"user","pass"} );
JMXServiceURL address = new JMXServiceURL("service:rmi:///jndi/rmi://host:port/jmxrmi");
JMXConnector connector = JMXConnectorFactory.connect(address,env);
MBeanServerConnection mbs = connector.getMBeanServerConnection();

//get all mbeans
Set<ObjectInstance> beans = mbs.queryMBeans(null,null);

for( ObjectInstance instance : beans )
{
    MBeanInfo info = mbs.getMBeanInfo( instance.getObjectName() );
}

​​从信息中,您可以根据需要查询对象名称和属性。

java.lang.management.ManagementFactory gives you access to JMX data.

i.g.

List<MemoryPoolMXBean> memPoolBeans = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean mpb : memPoolBeans) {
    System.out.println("Memory Pool: " + mpb.getName());
}

Some samples are available at SO query: [java]+managementfactory

A good read: https://www.ibm.com/developerworks/library/j-jtp09196/index.html

For full implementation connecting to a remote VM:

Map<String,String[]> env = new HashMap<String, String[]>();
env.put( JMXConnector.CREDENTIALS, new String[]{"user","pass"} );
JMXServiceURL address = new JMXServiceURL("service:rmi:///jndi/rmi://host:port/jmxrmi");
JMXConnector connector = JMXConnectorFactory.connect(address,env);
MBeanServerConnection mbs = connector.getMBeanServerConnection();

//get all mbeans
Set<ObjectInstance> beans = mbs.queryMBeans(null,null);

for( ObjectInstance instance : beans )
{
    MBeanInfo info = mbs.getMBeanInfo( instance.getObjectName() );
}

From the info, you can query object names and attributes as desired.

葬シ愛 2024-08-30 03:50:15

当我想做同样的事情时,我使用这个 命令行 JMX 客户端 作为起点。

I used this command line JMX client as a starting point when I wanted to do the same thing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文