Search in sources :

Example 61 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project HongsCORE by ihongs.

the class InfoAction method search.

@Action("search")
public void search(ActionHelper helper) throws HongsException {
    Map rsp = new HashMap();
    Map req = helper.getRequestData();
    long now = System.currentTimeMillis();
    Set rb = Synt.toTerms(req.get("rb"));
    // 当前时间
    rsp.put("now_msec", now);
    // 应用信息
    if (rb == null || rb.contains("app_info")) {
        Map app = new HashMap();
        rsp.put("app_info", app);
        long tim = Core.STARTS_TIME;
        app.put("server_id", Core.SERVER_ID);
        app.put("base_href", Core.BASE_HREF);
        app.put("base_path", Core.BASE_PATH);
        app.put("open_time", tim);
        app.put("live_time", Tool.humanTime(now - tim));
    }
    // 系统信息
    if (rb == null || rb.contains("sys_info")) {
        Map inf = new HashMap();
        rsp.put("sys_info", inf);
        Properties pps = System.getProperties();
        inf.put("name", pps.getProperty("os.name"));
        inf.put("arch", pps.getProperty("os.arch"));
        inf.put("vers", pps.getProperty("os.version"));
        inf.put("user", pps.getProperty("user.name"));
        inf.put("java", pps.getProperty("java.version"));
        try {
            InetAddress hst = InetAddress.getLocalHost();
            inf.put("addr", hst.getHostAddress());
            inf.put("host", hst.getHostName());
        } catch (UnknownHostException e) {
        // Nothing todo.
        }
    }
    // 运行信息
    if (rb == null || rb.contains("run_info")) {
        OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
        MemoryMXBean mm = ManagementFactory.getMemoryMXBean();
        MemoryUsage nm = mm.getNonHeapMemoryUsage();
        MemoryUsage hm = mm.getHeapMemoryUsage();
        Runtime rt = Runtime.getRuntime();
        double avg = os.getSystemLoadAverage();
        long siz = rt.totalMemory();
        long fre = rt.freeMemory();
        long max = rt.maxMemory();
        long stk = nm.getUsed();
        long use = hm.getUsed();
        Map inf = new HashMap();
        rsp.put("run_info", inf);
        inf.put("load", new Object[] { avg, String.valueOf(avg), "负载" });
        inf.put("size", new Object[] { siz, Tool.humanSize(max), "全部" });
        inf.put("free", new Object[] { fre, Tool.humanSize(fre), "空闲" });
        inf.put("dist", new Object[] { max, Tool.humanSize(fre), "可用" });
        inf.put("used", new Object[] { use, Tool.humanSize(use), "已用" });
        inf.put("uses", new Object[] { stk, Tool.humanSize(stk), "非堆" });
    }
    // 磁盘情况
    if (rb == null || rb.contains("dir_info")) {
        rsp.put("base_dir", getAllSize(new File(Core.BASE_PATH)));
        rsp.put("data_dir", getAllSize(new File(Core.DATA_PATH)));
        rsp.put("conf_dir", getAllSize(new File(Core.CONF_PATH)));
        rsp.put("core_dir", getAllSize(new File(Core.CORE_PATH)));
    }
    /**
     * 公共核心情况和锁情况
     */
    if (rb != null && rb.contains("core_info")) {
        rsp.put("core_set", Core.GLOBAL_CORE.keySet());
    }
    if (rb != null && rb.contains("lock_info")) {
        rsp.put("lock_map", app.hongs.util.Block.counts());
    }
    helper.reply("", rsp);
}
Also used : Set(java.util.Set) UnknownHostException(java.net.UnknownHostException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Properties(java.util.Properties) MemoryUsage(java.lang.management.MemoryUsage) MemoryMXBean(java.lang.management.MemoryMXBean) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) InetAddress(java.net.InetAddress) File(java.io.File) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) Action(app.hongs.action.anno.Action)

Example 62 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project incubator-dubbo-ops by apache.

the class LoadStatusChecker method check.

public Status check() {
    OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
    double load;
    try {
        Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage", new Class<?>[0]);
        load = (Double) method.invoke(operatingSystemMXBean, new Object[0]);
    } catch (Throwable e) {
        load = -1;
    }
    int cpu = operatingSystemMXBean.getAvailableProcessors();
    return new Status(load < 0 ? Status.Level.UNKNOWN : (load < cpu ? Status.Level.OK : Status.Level.WARN), "Load: " + load + " / CPU: " + cpu);
}
Also used : Status(com.alibaba.dubbo.common.status.Status) Method(java.lang.reflect.Method) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Example 63 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project incubator-dubbo-ops by apache.

the class LoadStatusChecker method check.

public Status check() {
    OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
    double load;
    try {
        Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage", new Class<?>[0]);
        load = (Double) method.invoke(operatingSystemMXBean, new Object[0]);
    } catch (Throwable e) {
        load = -1;
    }
    int cpu = operatingSystemMXBean.getAvailableProcessors();
    return new Status(load < 0 ? Status.Level.UNKNOWN : (load < cpu ? Status.Level.OK : Status.Level.WARN), "Load: " + load + " / CPU: " + cpu);
}
Also used : Status(com.alibaba.dubbo.common.status.Status) Method(java.lang.reflect.Method) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Example 64 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project karaf by apache.

the class EnvironmentDumpProvider method dumpOSInformation.

private void dumpOSInformation(final PrintWriter outPW) {
    final OperatingSystemMXBean mxBean = ManagementFactory.getOperatingSystemMXBean();
    if (null == mxBean) {
        return;
    }
    outPW.printf(KEY_VALUE_FORMAT, "Operating System", mxBean.getName() + ' ' + mxBean.getVersion()).println();
    outPW.printf(INDENT_KEY_VALUE_FORMAT, "architecture", mxBean.getArch()).println();
    outPW.printf(INDENT_KEY_VALUE_FORMAT, "processors", mxBean.getAvailableProcessors()).println();
// outPW.printf(INDENT_KEY_VALUE_FORMAT, "current system load average", mxBean.getSystemLoadAverage()).println();
}
Also used : OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Example 65 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project dubbo by alibaba.

the class LoadStatusChecker method check.

public Status check() {
    OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
    double load;
    try {
        Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage", new Class<?>[0]);
        load = (Double) method.invoke(operatingSystemMXBean, new Object[0]);
    } catch (Throwable e) {
        load = -1;
    }
    int cpu = operatingSystemMXBean.getAvailableProcessors();
    return new Status(load < 0 ? Status.Level.UNKNOWN : (load < cpu ? Status.Level.OK : Status.Level.WARN), (load < 0 ? "" : "load:" + load + ",") + "cpu:" + cpu);
}
Also used : Status(com.alibaba.dubbo.common.status.Status) Method(java.lang.reflect.Method) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Aggregations

OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)89 RuntimeMXBean (java.lang.management.RuntimeMXBean)27 Method (java.lang.reflect.Method)20 IOException (java.io.IOException)15 MemoryMXBean (java.lang.management.MemoryMXBean)12 MemoryUsage (java.lang.management.MemoryUsage)8 ThreadMXBean (java.lang.management.ThreadMXBean)8 HashMap (java.util.HashMap)8 UnixOperatingSystemMXBean (com.sun.management.UnixOperatingSystemMXBean)7 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)6 Status (com.alibaba.dubbo.common.status.Status)5 File (java.io.File)5 LinkedHashMap (java.util.LinkedHashMap)5 Map (java.util.Map)5 Test (org.junit.Test)5 Test (org.testng.annotations.Test)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 UnknownHostException (java.net.UnknownHostException)4 Date (java.util.Date)4 ExtendedOperatingSystemMXBeanImpl (com.ibm.lang.management.internal.ExtendedOperatingSystemMXBeanImpl)3