-
Notifications
You must be signed in to change notification settings - Fork 333
Expand file tree
/
Copy pathJPSUtils.java
More file actions
25 lines (22 loc) · 871 Bytes
/
JPSUtils.java
File metadata and controls
25 lines (22 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package datadog.trace.util;
import de.thetaphi.forbiddenapis.SuppressForbidden;
import java.lang.reflect.Method;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class JPSUtils {
private static final Logger log = LoggerFactory.getLogger(JPSUtils.class);
@SuppressForbidden
public static Set<String> getVMPids() {
try {
Class<?> monitoredHostClass = Class.forName("sun.jvmstat.monitor.MonitoredHost");
Method getMonitoredHostMethod =
monitoredHostClass.getDeclaredMethod("getMonitoredHost", String.class);
Object vmHost = getMonitoredHostMethod.invoke(null, "localhost");
return (Set<String>) monitoredHostClass.getDeclaredMethod("activeVms").invoke(vmHost);
} catch (Exception e) {
log.debug("Failed to invoke jvmstat with exception ", e);
return null;
}
}
}