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);
}
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;
}
Aggregations