use of java.lang.management.MemoryPoolMXBean in project felix by apache.
the class MemoryUsageSupport method setThreshold.
/**
* Sets the threshold percentage.
*
* @param percentage The threshold as a percentage of memory consumption.
* This value may be 0 (zero) to switch off automatic heap dumps
* or in the range {@link #MIN_DUMP_THRESHOLD} to
* {@link #MAX_DUMP_THRESHOLD}. If set to a negative value,
* the default threshold is assumed.
* @throws IllegalArgumentException if the percentage value is outside of
* the valid range of thresholds. The message is the percentage
* value which is not accepted.
*/
final void setThreshold(int percentage) {
if (percentage < 0) {
percentage = defaultThreshold;
}
if (MemoryUsageConstants.isThresholdValid(percentage)) {
TreeSet<String> thresholdPools = new TreeSet<String>();
TreeSet<String> noThresholdPools = new TreeSet<String>();
List<MemoryPoolMXBean> pools = getMemoryPools();
for (MemoryPoolMXBean pool : pools) {
if (pool.isUsageThresholdSupported()) {
long threshold = pool.getUsage().getMax() * percentage / 100;
pool.setUsageThreshold(threshold);
thresholdPools.add(pool.getName());
} else {
noThresholdPools.add(pool.getName());
}
}
this.threshold = percentage;
log(LogService.LOG_INFO, "Setting Automatic Memory Dump Threshold to %d%% for pools %s", threshold, thresholdPools);
log(LogService.LOG_INFO, "Automatic Memory Dump cannot be set for pools %s", noThresholdPools);
} else {
throw new IllegalArgumentException(String.valueOf(percentage));
}
}
use of java.lang.management.MemoryPoolMXBean 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.MemoryPoolMXBean in project Lucee by lucee.
the class MacAddressWrap method getPermGenSpaceBean.
public static MemoryPoolMXBean getPermGenSpaceBean() {
java.util.List<MemoryPoolMXBean> manager = ManagementFactory.getMemoryPoolMXBeans();
MemoryPoolMXBean bean;
// PERM GEN
Iterator<MemoryPoolMXBean> it = manager.iterator();
while (it.hasNext()) {
bean = it.next();
if ("Perm Gen".equalsIgnoreCase(bean.getName()) || "CMS Perm Gen".equalsIgnoreCase(bean.getName())) {
return bean;
}
}
it = manager.iterator();
while (it.hasNext()) {
bean = it.next();
if (StringUtil.indexOfIgnoreCase(bean.getName(), "Perm Gen") != -1 || StringUtil.indexOfIgnoreCase(bean.getName(), "PermGen") != -1) {
return bean;
}
}
// take none-heap when only one
it = manager.iterator();
LinkedList<MemoryPoolMXBean> beans = new LinkedList<MemoryPoolMXBean>();
while (it.hasNext()) {
bean = it.next();
if (bean.getType().equals(MemoryType.NON_HEAP)) {
beans.add(bean);
return bean;
}
}
if (beans.size() == 1)
return beans.getFirst();
// Class Memory/ClassBlock Memory?
it = manager.iterator();
while (it.hasNext()) {
bean = it.next();
if (StringUtil.indexOfIgnoreCase(bean.getName(), "Class Memory") != -1) {
return bean;
}
}
return null;
}
use of java.lang.management.MemoryPoolMXBean 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;
}
use of java.lang.management.MemoryPoolMXBean 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;
}
Aggregations