...
|
...
|
@@ -22,10 +22,10 @@ public class JMXMonitor { |
|
|
|
|
|
public static final Map<UUID, Connection> conMap = new LinkedHashMap<UUID, Connection>();
|
|
|
|
|
|
public static final String CONFIG_PATH = "/etc/metric_config.json";
|
|
|
//public static final String CONFIG_PATH = "/etc/metric_config.json";
|
|
|
|
|
|
//public static final String CONFIG_PATH = "/Users/jack/Documents/metric/metric_config.json";
|
|
|
public String host = "127.0.0.1";
|
|
|
public static final String CONFIG_PATH = "/Users/jack/Documents/metric_config.json";
|
|
|
public String host = "localhost";
|
|
|
|
|
|
public List<Integer> ports = new ArrayList<Integer>();
|
|
|
|
...
|
...
|
@@ -66,6 +66,9 @@ public class JMXMonitor { |
|
|
if (!javaObject.containsKey("host") || !javaObject.containsKey("ports"))
|
|
|
return false;
|
|
|
this.host = javaObject.getString("host");
|
|
|
if (StringUtils.equals("localhost", host)) {
|
|
|
this.host = getHostIp();
|
|
|
}
|
|
|
JSONArray array = javaObject.getJSONArray("ports");
|
|
|
for (Object obj : array) {
|
|
|
if (obj instanceof Integer)
|
...
|
...
|
@@ -109,6 +112,23 @@ public class JMXMonitor { |
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
public static final String getHostIp() {
|
|
|
try {
|
|
|
for (Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); interfaces.hasMoreElements(); ) {
|
|
|
NetworkInterface networkInterface = interfaces.nextElement();
|
|
|
if (networkInterface.isLoopback() || networkInterface.isVirtual() || !networkInterface.isUp()) {
|
|
|
continue;
|
|
|
}
|
|
|
Enumeration<InetAddress> addresses = networkInterface.getInetAddresses();
|
|
|
if (addresses.hasMoreElements()) {
|
|
|
return addresses.nextElement().getHostAddress();
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
JMXMonitor jmxMonitor = new JMXMonitor();
|
...
|
...
|
|