Search in sources :

Example 41 with MemoryMXBean

use of java.lang.management.MemoryMXBean 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 42 with MemoryMXBean

use of java.lang.management.MemoryMXBean in project Lucee by lucee.

the class MemoryControler method init.

public static synchronized void init(ConfigServer cs) {
    if (init)
        return;
    // set level
    for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
        types.put(pool.getName(), pool.getType());
        // we should rather check for the pool name "Tenured Gen"?
        if (pool.getType() == MemoryType.HEAP && pool.isUsageThresholdSupported()) {
            long maxMemory = pool.getUsage().getMax();
            long warningThreshold = (long) (maxMemory * 0.9);
            // long warningThreshold = maxMemory -(10*1024*1024);
            pool.setUsageThreshold(warningThreshold);
        }
    }
    MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
    NotificationEmitter emitter = (NotificationEmitter) mbean;
    MemoryNotificationListener listener = new MemoryNotificationListener(types);
    emitter.addNotificationListener(listener, null, cs);
    init = true;
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean) NotificationEmitter(javax.management.NotificationEmitter) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean)

Aggregations

MemoryMXBean (java.lang.management.MemoryMXBean)42 MemoryUsage (java.lang.management.MemoryUsage)15 RuntimeMXBean (java.lang.management.RuntimeMXBean)11 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)8 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)7 ThreadMXBean (java.lang.management.ThreadMXBean)7 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)6 ClassLoadingMXBean (java.lang.management.ClassLoadingMXBean)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Properties (java.util.Properties)4 Test (org.junit.Test)4 NotificationEmitter (javax.management.NotificationEmitter)3 File (java.io.File)2 IOException (java.io.IOException)2 LinkedHashMap (java.util.LinkedHashMap)2 ObjectName (javax.management.ObjectName)2 MetricGroup (org.apache.flink.metrics.MetricGroup)2 Action (app.hongs.action.anno.Action)1