use of java.lang.management.MemoryMXBean in project karaf by apache.
the class MemoryDumpProvider method writeDump.
@Override
protected void writeDump(OutputStreamWriter outputStream) throws Exception {
MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
outputStream.write("Number of objects waiting finalization: " + memoryMXBean.getObjectPendingFinalizationCount() + "\n\n");
outputStream.write("Heap:\n");
outputStream.write("\tInit: " + memoryMXBean.getHeapMemoryUsage().getInit() + "\n");
outputStream.write("\tUser: " + memoryMXBean.getHeapMemoryUsage().getUsed() + "\n");
outputStream.write("\tCommitted: " + memoryMXBean.getHeapMemoryUsage().getCommitted() + "\n");
outputStream.write("\tMax: " + memoryMXBean.getHeapMemoryUsage().getMax() + "\n");
outputStream.write("Non-Heap: \n");
outputStream.write("\tInit: " + memoryMXBean.getNonHeapMemoryUsage().getInit() + "\n");
outputStream.write("\tUser: " + memoryMXBean.getNonHeapMemoryUsage().getUsed() + "\n");
outputStream.write("\tCommitted: " + memoryMXBean.getNonHeapMemoryUsage().getCommitted() + "\n");
outputStream.write("\tMax: " + memoryMXBean.getNonHeapMemoryUsage().getMax() + "\n");
}
use of java.lang.management.MemoryMXBean in project asterixdb by apache.
the class GetNodeDetailsJSONWork method getCCDetails.
private ObjectNode getCCDetails() {
ObjectNode o = om.createObjectNode();
MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
List<GarbageCollectorMXBean> gcMXBeans = ManagementFactory.getGarbageCollectorMXBeans();
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
OperatingSystemMXBean osMXBean = ManagementFactory.getOperatingSystemMXBean();
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
if (includeConfig) {
o.put("os_name", osMXBean.getName());
o.put("arch", osMXBean.getArch());
o.put("os_version", osMXBean.getVersion());
o.put("num_processors", osMXBean.getAvailableProcessors());
o.put("vm_name", runtimeMXBean.getVmName());
o.put("vm_version", runtimeMXBean.getVmVersion());
o.put("vm_vendor", runtimeMXBean.getVmVendor());
o.putPOJO("classpath", runtimeMXBean.getClassPath().split(File.pathSeparator));
o.putPOJO("library_path", runtimeMXBean.getLibraryPath().split(File.pathSeparator));
o.putPOJO("boot_classpath", runtimeMXBean.getBootClassPath().split(File.pathSeparator));
o.putPOJO("input_arguments", runtimeMXBean.getInputArguments());
o.putPOJO("system_properties", runtimeMXBean.getSystemProperties());
o.put("pid", PidHelper.getPid());
}
if (includeStats) {
MemoryUsage heapUsage = memoryMXBean.getHeapMemoryUsage();
MemoryUsage nonheapUsage = memoryMXBean.getNonHeapMemoryUsage();
List<ObjectNode> gcs = new ArrayList<>();
for (GarbageCollectorMXBean gcMXBean : gcMXBeans) {
ObjectNode gc = om.createObjectNode();
gc.put("name", gcMXBean.getName());
gc.put("collection-time", gcMXBean.getCollectionTime());
gc.put("collection-count", gcMXBean.getCollectionCount());
gcs.add(gc);
}
o.putPOJO("gcs", gcs);
o.put("date", new Date().toString());
o.put("heap_init_size", heapUsage.getInit());
o.put("heap_used_size", heapUsage.getUsed());
o.put("heap_committed_size", heapUsage.getCommitted());
o.put("heap_max_size", heapUsage.getMax());
o.put("nonheap_init_size", nonheapUsage.getInit());
o.put("nonheap_used_size", nonheapUsage.getUsed());
o.put("nonheap_committed_size", nonheapUsage.getCommitted());
o.put("nonheap_max_size", nonheapUsage.getMax());
o.put("thread_count", threadMXBean.getThreadCount());
o.put("peak_thread_count", threadMXBean.getPeakThreadCount());
o.put("started_thread_count", threadMXBean.getTotalStartedThreadCount());
o.put("system_load_average", osMXBean.getSystemLoadAverage());
}
return o;
}
use of java.lang.management.MemoryMXBean in project jdk8u_jdk by JetBrains.
the class MXBeanInteropTest1 method doMemoryMXBeanTest.
private final int doMemoryMXBeanTest(MBeanServerConnection mbsc) {
int errorCount = 0;
System.out.println("---- MemoryMXBean");
try {
ObjectName memoryName = new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME);
MBeanInfo mbInfo = mbsc.getMBeanInfo(memoryName);
errorCount += checkNonEmpty(mbInfo);
System.out.println("getMBeanInfo\t\t" + mbInfo);
MemoryMXBean memory = null;
memory = JMX.newMXBeanProxy(mbsc, memoryName, MemoryMXBean.class, true);
System.out.println("getMemoryHeapUsage\t\t" + memory.getHeapMemoryUsage());
System.out.println("getNonHeapMemoryHeapUsage\t\t" + memory.getNonHeapMemoryUsage());
System.out.println("getObjectPendingFinalizationCount\t\t" + memory.getObjectPendingFinalizationCount());
System.out.println("isVerbose\t\t" + memory.isVerbose());
System.out.println("---- OK\n");
} catch (Exception e) {
Utils.printThrowable(e, true);
errorCount++;
System.out.println("---- ERROR\n");
}
return errorCount;
}
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