Authored by BuddyJack

Fix

... ... @@ -27,28 +27,36 @@ public class JMXMonitor {
* @param args
*/
public static void main(String[] args) {
if (null == args || 5 != args.length)
System.exit(1);
String jmxHost = args[0];
String jmxPort = args[1];
String user = args[2];
String passwd = args[3];
String service = args[4];
String rawUrl = MessageFormat.format(RAW_URL, jmxHost, jmxPort);
JMXServiceURL serviceURL = null;
try {
serviceURL = new JMXServiceURL(rawUrl);
} catch (MalformedURLException e) {
System.exit(1);
}
Connection con = new Connection(rawUrl, jmxHost, Integer.valueOf(jmxPort), serviceURL, user, passwd, service);
if (null == args || 5 != args.length)
System.exit(1);
String jmxHost = args[0];
String jmxPort = args[1];
String user = args[2];
String passwd = args[3];
String service = args[4];
try {
System.out.println(con.readJvmData());
String rawUrl = MessageFormat.format(RAW_URL, jmxHost, jmxPort);
JMXServiceURL serviceURL = null;
try {
serviceURL = new JMXServiceURL(rawUrl);
} catch (MalformedURLException e) {
e.printStackTrace();
System.exit(1);
}
Connection con = new Connection(rawUrl, jmxHost, Integer.valueOf(jmxPort), serviceURL, user, passwd, service);
try {
System.out.println(con.readJvmData());
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
}
... ...
... ... @@ -24,7 +24,7 @@ public class Connection {
private MBeanServerConnection serverConnection;
private Map<String, ObjectInstance> beanMap = new HashMap<String, ObjectInstance>();
private DecimalFormat df = new DecimalFormat("0.00");
private JvmData jvmData=new JvmData();
private JvmData jvmData = new JvmData();
public Connection(final String rawUrl, final String hostName, final int port, final JMXServiceURL serviceURL, final String username,
... ... @@ -46,6 +46,7 @@ public class Connection {
serverConnector = JMXConnectorFactory.connect(this.serviceURL, envMap);
serverConnection = this.serverConnector.getMBeanServerConnection();
} catch (IOException e) {
System.out.println(e.getMessage());
disConnect();
}
}
... ... @@ -86,8 +87,9 @@ public class Connection {
ObjectInstance threadInstance = this.serverConnection.getObjectInstance(new ObjectName("java.lang:type=Threading"));
beanMap.put("thread", threadInstance);
//Memory Bean
ObjectInstance oldGenInstance = this.serverConnection.getObjectInstance(new ObjectName("java.lang:type=MemoryPool,name=PS Old Gen"));
ObjectInstance oldGenInstance = this.serverConnection.getObjectInstance(new ObjectName("java.lang:type=MemoryPool,name=CMS Old Gen"));
beanMap.put("oldGen", oldGenInstance);
}
... ... @@ -122,6 +124,7 @@ public class Connection {
jvmData.setThreadPeak(peak);
jvmData.setThreadCount(count);
} catch (IOException e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
... ... @@ -140,6 +143,7 @@ public class Connection {
jvmData.setMaxOldGen(maxOldGenMemory);
} catch (IOException e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
... ... @@ -154,6 +158,7 @@ public class Connection {
geThreadInfo();
return JSON.toJSONString(jvmData);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
} finally {
disConnect();
... ...