Search in sources :

Example 86 with RuntimeMXBean

use of java.lang.management.RuntimeMXBean in project syncany by syncany.

the class PidFileUtil method getProcessPidImpl2.

/**
 * Uses the private method <tt>VMManagement.getProcessId()</tt> of Sun's <tt>sun.management.VMManagement</tt>
 * class to determine the PID (using reflection to make the relevant fields visible).
 *
 * @see http://stackoverflow.com/a/12066696/1440785
 */
private static int getProcessPidImpl2() throws Exception {
    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
    Field jvmField = runtimeMXBean.getClass().getDeclaredField("jvm");
    jvmField.setAccessible(true);
    // The returned object is of the type 'sun.management.VMManagement', but since we
    // don't need the exact type here and we don't want to reference it in the
    // imports, we'll just hope it's there.
    Object vmManagement = jvmField.get(runtimeMXBean);
    Method getProcessIdMethod = vmManagement.getClass().getDeclaredMethod("getProcessId");
    getProcessIdMethod.setAccessible(true);
    int processPid = (Integer) getProcessIdMethod.invoke(vmManagement);
    logger.log(Level.INFO, "Java Process PID is " + processPid);
    return processPid;
}
Also used : Field(java.lang.reflect.Field) RuntimeMXBean(java.lang.management.RuntimeMXBean) Method(java.lang.reflect.Method)

Example 87 with RuntimeMXBean

use of java.lang.management.RuntimeMXBean in project jPOS by jpos.

the class SystemMonitor method generateFrozenDump.

private String generateFrozenDump(String indent) {
    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
    ThreadMXBean mxBean = ManagementFactory.getThreadMXBean();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream p = new PrintStream(baos);
    String newIndent = indent + "  ";
    Runtime r = getRuntimeInstance();
    ZoneId zi = ZoneId.systemDefault();
    Instant instant = Instant.now();
    File cwd = new File(".");
    String freeSpace = ISOUtil.readableFileSize(cwd.getFreeSpace());
    String usableSpace = ISOUtil.readableFileSize(cwd.getUsableSpace());
    p.printf("%s           OS: %s (%s)%n", indent, System.getProperty("os.name"), System.getProperty("os.version"));
    int maxKeyLength = 0;
    try {
        maxKeyLength = Cipher.getMaxAllowedKeyLength("AES");
    } catch (NoSuchAlgorithmException ignored) {
    }
    p.printf("%s         Java: %s (%s) AES-%s%n", indent, System.getProperty("java.version"), System.getProperty("java.vendor"), maxKeyLength == Integer.MAX_VALUE ? "secure" : Integer.toString(maxKeyLength));
    p.printf("%s process name: %s%n", indent, runtimeMXBean.getName());
    p.printf("%s         host: %s%n", indent, getLocalHost());
    p.printf("%s          cwd: %s%n", indent, System.getProperty("user.dir"));
    p.printf("%s   free space: %s%n", indent, freeSpace);
    if (!freeSpace.equals(usableSpace))
        p.printf("%s usable space: %s%n", indent, usableSpace);
    p.printf("%s      version: %s (%s)%n", indent, Q2.getVersion(), getRevision());
    p.printf("%s     instance: %s%n", indent, getInstanceIdAsString());
    p.printf("%s       uptime: %s (%f)%n", indent, ISOUtil.millisToString(getServerUptimeAsMillisecond()), loadAverage());
    p.printf("%s   processors: %d%n", indent, r.availableProcessors());
    p.printf("%s       drift : %d%n", indent, delay);
    p.printf("%smemory(t/u/f): %d/%d/%d%n", indent, r.totalMemory() / MB, (r.totalMemory() - r.freeMemory()) / MB, r.freeMemory() / MB);
    p.printf("%s     encoding: %s%n", indent, Charset.defaultCharset());
    p.printf("%s     timezone: %s (%s) %s%n", indent, zi, zi.getDisplayName(TextStyle.FULL, Locale.getDefault()), zi.getRules().getOffset(instant).toString());
    p.printf("%swatch service: %s%n", indent, getServer().getWatchServiceClassname());
    List<ZoneOffsetTransitionRule> l = zi.getRules().getTransitionRules();
    for (ZoneOffsetTransitionRule tr : l) {
        p.printf("%s         rule: %s%n", indent, tr.toString());
    }
    ZoneOffsetTransition tran = zi.getRules().nextTransition(instant);
    if (tran != null) {
        Instant in = tran.getInstant();
        p.printf("%s   transition: %s (%s)%n", indent, in, in.atZone(zi));
    }
    p.printf("%s        clock: %d %s%n", indent, System.currentTimeMillis() / 1000L, instant);
    if (hasSecurityManager())
        p.printf("%s  sec-manager: %s%n", indent, getSecurityManager());
    p.printf("%s thread count: %d%n", indent, mxBean.getThreadCount());
    p.printf("%s peak threads: %d%n", indent, mxBean.getPeakThreadCount());
    p.printf("%s user threads: %d%n", indent, Thread.activeCount());
    showThreadGroup(Thread.currentThread().getThreadGroup(), p, newIndent);
    NameRegistrar.getInstance().dump(p, indent, detailRequired);
    for (String s : scripts) {
        p.printf("%s%s:%n", indent, s);
        exec(s, p, newIndent);
    }
    return baos.toString();
}
Also used : ZoneOffsetTransitionRule(java.time.zone.ZoneOffsetTransitionRule) ThreadMXBean(java.lang.management.ThreadMXBean) ZoneId(java.time.ZoneId) Instant(java.time.Instant) RuntimeMXBean(java.lang.management.RuntimeMXBean) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ZoneOffsetTransition(java.time.zone.ZoneOffsetTransition)

Example 88 with RuntimeMXBean

use of java.lang.management.RuntimeMXBean in project suite by stupidsing.

the class FileUtil method getPid.

public static int getPid() {
    RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
    return Rethrow.ex(() -> {
        Field jvm = runtime.getClass().getDeclaredField("jvm");
        jvm.setAccessible(true);
        Object vmm = jvm.get(runtime);
        Method method = vmm.getClass().getDeclaredMethod("getProcessId");
        method.setAccessible(true);
        return (Integer) method.invoke(jvm.get(runtime));
    });
}
Also used : Field(java.lang.reflect.Field) RuntimeMXBean(java.lang.management.RuntimeMXBean) Method(java.lang.reflect.Method)

Example 89 with RuntimeMXBean

use of java.lang.management.RuntimeMXBean in project Payara by payara.

the class PhoneHomeTask method getUptime.

private String getUptime() {
    RuntimeMXBean mxbean = ManagementFactory.getRuntimeMXBean();
    long totalTime_ms = -1;
    if (mxbean != null)
        totalTime_ms = mxbean.getUptime();
    if (totalTime_ms <= 0 && env != null) {
        StartupContext ctx = env.getStartupContext();
        if (ctx != null) {
            long start = ctx.getCreationTime();
            totalTime_ms = System.currentTimeMillis() - start;
        }
    }
    return Long.toString(totalTime_ms);
}
Also used : StartupContext(com.sun.enterprise.module.bootstrap.StartupContext) RuntimeMXBean(java.lang.management.RuntimeMXBean)

Example 90 with RuntimeMXBean

use of java.lang.management.RuntimeMXBean in project Payara by payara.

the class ThreadMonitor method getTitle.

private String getTitle() throws Exception {
    final RuntimeMXBean rt = ManagementFactory.newPlatformMXBeanProxy(mbsc, ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean.class);
    final String vmname = rt.getVmName();
    final String vmversion = rt.getVmVersion();
    final String vmvendor = rt.getVmVendor();
    final String title = sm.getString("td.title", vmname, vmversion, vmvendor);
    return (title);
}
Also used : RuntimeMXBean(java.lang.management.RuntimeMXBean)

Aggregations

RuntimeMXBean (java.lang.management.RuntimeMXBean)92 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)16 MemoryMXBean (java.lang.management.MemoryMXBean)11 IOException (java.io.IOException)9 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)9 ThreadMXBean (java.lang.management.ThreadMXBean)8 MemoryUsage (java.lang.management.MemoryUsage)6 Method (java.lang.reflect.Method)6 ArrayList (java.util.ArrayList)6 ClassLoadingMXBean (java.lang.management.ClassLoadingMXBean)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Properties (java.util.Properties)5 InputStream (java.io.InputStream)4 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)4 Field (java.lang.reflect.Field)4 Date (java.util.Date)4 BufferedReader (java.io.BufferedReader)3 File (java.io.File)3 InputStreamReader (java.io.InputStreamReader)3