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