最近做监控相关的事情,要把本地的所有JAVA应用管理起来,但这些应用的JDK1.4的,有1.5的,1.6的,而且在JDK1.5之前的应用提供的MBeanServer并不是PlatformMBeanServer,这就导致监控时获取堆的信息,线程,Runtime等一些属性的时候没法获取。本打算改造运行在JDK1.4上跑的应用,使其使用PlatFormMBeanServer,但JDK1.4好像并没有提供获取PlatFormMBeanServer的方式,大致想到了以下几个思路:
1.升级JDK,但可能会影响原来应用,因为JDK1.4的时候一些语法像enum这些都还不是关键字。
2.如果可以升级JDK,下面的几点才可以实现:
2.1 改造原应用,获取PlatFormMBeanServer,这样应用的监控数据和java.lang的监控数据就都可以获取
2.2 利用JDK attach 的方式,根据本地的vmid获取其jmxUrl,再获取属性,这个需要JDK1.6了。
JDK中部分Attach的代码:
// load the management agent into the target VM
private void loadManagementAgent() throws IOException {
VirtualMachine vm = null;
String name = String.valueOf(vmid);
try {
vm = VirtualMachine.attach(name);
} catch (AttachNotSupportedException x) {
IOException ioe = new IOException(x.getMessage());
ioe.initCause(x);
throw ioe;
}
String home = vm.getSystemProperties().getProperty("java.home");
// Normally in ${java.home}/jre/lib/management-agent.jar but might
// be in ${java.home}/lib in build environments.
String agent = home + File.separator + "jre" + File.separator +
"lib" + File.separator + "management-agent.jar";
File f = new File(agent);
if (!f.exists()) {
agent = home + File.separator + "lib" + File.separator +
"management-agent.jar";
f = new File(agent);
if (!f.exists()) {
throw new IOException("Management agent not found");
}
}
agent = f.getCanonicalPath();
try {
vm.loadAgent(agent, "com.sun.management.jmxremote");
} catch (AgentLoadException x) {
IOException ioe = new IOException(x.getMessage());
ioe.initCause(x);
throw ioe;
} catch (AgentInitializationException x) {
IOException ioe = new IOException(x.getMessage());
ioe.initCause(x);
throw ioe;
}
// get the connector address
Properties agentProps = vm.getAgentProperties();
address = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP);
vm.detach();
}
InputStream execute(String cmd, Object ... args)
throws AgentLoadException, IOException
{
assert args.length <= 3; // includes null
// create a pipe using a random name
int r = (new Random()).nextInt();
String pipename = "\\\\.\\pipe\\javatool" + r;
long hPipe = createPipe(pipename);
// check if we are detached - in theory it's possible that detach is invoked
// after this check but before we enqueue the command.
if (hProcess == -1) {
closePipe(hPipe);
throw new IOException("Detached from target VM");
}
try {
// enqueue the command to the process
enqueue(hProcess, stub, cmd, pipename, args);
// wait for command to complete - process will connect with the
// com
分享到:
相关推荐
jconsole.jar下载
性能监控JConsole远程监控Tomcat服务
jconsole源码 源码 jconsole jmx
jconsole.1.8.0jar 这个包也经常maven导入报错 也是本人亲测有效
jconsole介绍 和相关配置,简单举例jconsole的配制方法
如果初次接触JConsole,应该会很有用的!
jvm检测工具,jconsole工具介绍,其他同类工具介绍
是不是有时候jconsole配置后重启报错,那么试试这个,万能的远程打开jconsole
介绍通过Jconsole工具对Java的应用进行监控
java开发常用组件,jconsole-1.8.0.jar jconsole-1.8.0.jar
jconsole.jar
JConsole(观察分析Java程序的运行)
maven 项目缺少或报相关jdk- jconsole相关的错,这个jar包使用后就没问题了
介绍了如何使用JConsole分析JVM,一步一步使用JConsole
JConsole是一个基于JMX的GUI工具,用于连接正在运行的JVM,不过此JVM需要使用可管理的模式启动。如果要把一个应用以可管理的形式启动,可以在启动是设置com.sun.management.jmxremote。JConsole能够提供被监控虚拟机...
jconsole工具,内置在jdk8中,主要监控 JVM 的概览、内存、线程、类、vm概要、MBean等内容。内含jconsole的连接使用说明
jconsole使用手册中文版,详细描述了如何配置使用jconsole进行java程序的性能监控
分享 JConsole 源代码,MyEclipse工程
JConsole监控JVM