use of java.lang.management.MemoryUsage 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.MemoryUsage in project Lucee by lucee.
the class MacAddressWrap method getPermGenFreeSpaceAsAPercentageOfAvailable.
public static int getPermGenFreeSpaceAsAPercentageOfAvailable() {
MemoryUsage mu = getPermGenSpaceSize(null);
if (mu == null)
return -1;
long max = mu.getMax();
long used = mu.getUsed();
if (max < 0 || used < 0)
return -1;
// return a value that equates to a percentage of available free memory
return 100 - ((int) (100 * (((double) used) / ((double) max))));
}
use of java.lang.management.MemoryUsage in project Lucee by lucee.
the class MacAddressWrap method getMemoryUsageAsQuery.
public static Query getMemoryUsageAsQuery(int type) throws DatabaseException {
java.util.List<MemoryPoolMXBean> manager = ManagementFactory.getMemoryPoolMXBeans();
Iterator<MemoryPoolMXBean> it = manager.iterator();
Query qry = new QueryImpl(new Collection.Key[] { KeyConstants._name, KeyConstants._type, KeyConstants._used, KeyConstants._max, KeyConstants._init }, 0, "memory");
int row = 0;
MemoryPoolMXBean bean;
MemoryUsage usage;
MemoryType _type;
while (it.hasNext()) {
bean = it.next();
usage = bean.getUsage();
_type = bean.getType();
if (type == MEMORY_TYPE_HEAP && _type != MemoryType.HEAP)
continue;
if (type == MEMORY_TYPE_NON_HEAP && _type != MemoryType.NON_HEAP)
continue;
row++;
qry.addRow();
qry.setAtEL(KeyConstants._name, row, bean.getName());
qry.setAtEL(KeyConstants._type, row, _type.name());
qry.setAtEL(KeyConstants._max, row, Caster.toDouble(usage.getMax()));
qry.setAtEL(KeyConstants._used, row, Caster.toDouble(usage.getUsed()));
qry.setAtEL(KeyConstants._init, row, Caster.toDouble(usage.getInit()));
}
return qry;
}
use of java.lang.management.MemoryUsage in project Lucee by lucee.
the class MacAddressWrap method getMemoryUsageAsStruct.
public static Struct getMemoryUsageAsStruct(int type) {
java.util.List<MemoryPoolMXBean> manager = ManagementFactory.getMemoryPoolMXBeans();
Iterator<MemoryPoolMXBean> it = manager.iterator();
MemoryPoolMXBean bean;
MemoryUsage usage;
MemoryType _type;
long used = 0, max = 0, init = 0;
while (it.hasNext()) {
bean = it.next();
usage = bean.getUsage();
_type = bean.getType();
if ((type == MEMORY_TYPE_HEAP && _type == MemoryType.HEAP) || (type == MEMORY_TYPE_NON_HEAP && _type == MemoryType.NON_HEAP)) {
used += usage.getUsed();
max += usage.getMax();
init += usage.getInit();
}
}
Struct sct = new StructImpl();
sct.setEL(KeyConstants._used, Caster.toDouble(used));
sct.setEL(KeyConstants._max, Caster.toDouble(max));
sct.setEL(KeyConstants._init, Caster.toDouble(init));
sct.setEL(KeyImpl.init("available"), Caster.toDouble(max - used));
return sct;
}
use of java.lang.management.MemoryUsage in project knime-core by knime.
the class MemoryAlertSystem method gcEvent.
private void gcEvent(final double usageThreshold, final Notification not) {
// Only reset the low memory flag if the last (memory) event was earlier than this event.
// the GC event and the Mem event have the same timestamp in case the threshold is exceeded.
m_lastGcTimestamp.set(not.getTimeStamp());
long prev, next;
do {
prev = m_lastEventTimestamp.get();
next = Math.max(prev, not.getTimeStamp());
} while (!m_lastEventTimestamp.compareAndSet(prev, next));
if (prev < not.getTimeStamp()) {
MemoryUsage collectionUsage = m_memPool.getCollectionUsage();
long used = collectionUsage.getUsed();
long max = collectionUsage.getMax();
double currentUsagePercent = 100.0 * used / max;
LOGGER.debugWithFormat("Memory usage below threshold (%.0f%%) after GC run, currently %.0f%% (%.2fGB/%.2fGB)", usageThreshold * 100.0, currentUsagePercent, (double) used / FileUtils.ONE_GB, (double) max / FileUtils.ONE_GB);
m_lowMemory.set(false);
}
m_gcEventLock.lock();
try {
m_gcEvent.signalAll();
} finally {
m_gcEventLock.unlock();
}
}
Aggregations