use of java.lang.management.MemoryUsage in project drill by apache.
the class MemoryIterator method next.
@Override
public Object next() {
if (!beforeFirst) {
throw new IllegalStateException();
}
beforeFirst = false;
final MemoryInfo memoryInfo = new MemoryInfo();
final DrillbitEndpoint endpoint = context.getIdentity();
memoryInfo.hostname = endpoint.getAddress();
memoryInfo.user_port = endpoint.getUserPort();
final MemoryUsage heapMemoryUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
memoryInfo.heap_current = heapMemoryUsage.getUsed();
memoryInfo.heap_max = heapMemoryUsage.getMax();
BufferPoolMXBean directBean = getDirectBean();
memoryInfo.jvm_direct_current = directBean.getMemoryUsed();
memoryInfo.direct_current = context.getDrillbitContext().getAllocator().getAllocatedMemory();
memoryInfo.direct_max = DrillConfig.getMaxDirectMemory();
return memoryInfo;
}
use of java.lang.management.MemoryUsage in project jdk8u_jdk by JetBrains.
the class LastGCInfo method checkGcInfo.
private static void checkGcInfo(String name, GcInfo info) throws Exception {
System.out.println("GC statistic for : " + name);
System.out.print("GC #" + info.getId());
System.out.print(" start:" + info.getStartTime());
System.out.print(" end:" + info.getEndTime());
System.out.println(" (" + info.getDuration() + "ms)");
Map usage = info.getMemoryUsageBeforeGc();
List pnames = new ArrayList();
for (Iterator iter = usage.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry) iter.next();
String poolname = (String) entry.getKey();
pnames.add(poolname);
MemoryUsage busage = (MemoryUsage) entry.getValue();
MemoryUsage ausage = (MemoryUsage) info.getMemoryUsageAfterGc().get(poolname);
if (ausage == null) {
throw new RuntimeException("After Gc Memory does not exist" + " for " + poolname);
}
System.out.println("Usage for pool " + poolname);
System.out.println(" Before GC: " + busage);
System.out.println(" After GC: " + ausage);
}
// check if memory usage for all memory pools are returned
List pools = ManagementFactory.getMemoryPoolMXBeans();
for (Iterator iter = pools.iterator(); iter.hasNext(); ) {
MemoryPoolMXBean p = (MemoryPoolMXBean) iter.next();
if (!pnames.contains(p.getName())) {
throw new RuntimeException("GcInfo does not contain " + "memory usage for pool " + p.getName());
}
}
}
use of java.lang.management.MemoryUsage in project geode by apache.
the class GetMemberInformationFunction method execute.
@Override
public void execute(FunctionContext functionContext) {
try {
Cache cache = CacheFactory.getAnyInstance();
/*
* TODO: 1) Get the CPU usage%
*/
InternalDistributedSystem system = (InternalDistributedSystem) cache.getDistributedSystem();
DistributionConfig config = system.getConfig();
String serverBindAddress = config.getServerBindAddress();
MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
MemberInformation memberInfo = new MemberInformation();
memberInfo.setGroups(config.getGroups());
memberInfo.setLogFilePath(config.getLogFile().getCanonicalPath());
memberInfo.setStatArchiveFilePath(config.getStatisticArchiveFile().getCanonicalPath());
memberInfo.setWorkingDirPath(System.getProperty("user.dir"));
memberInfo.setCacheXmlFilePath(config.getCacheXmlFile().getCanonicalPath());
memberInfo.setLocators(config.getLocators());
memberInfo.setServerBindAddress(serverBindAddress);
memberInfo.setOffHeapMemorySize(config.getOffHeapMemorySize());
MemoryUsage memUsage = memoryMXBean.getHeapMemoryUsage();
memberInfo.setHeapUsage(Long.toString(bytesToMeg(memUsage.getUsed())));
memberInfo.setMaxHeapSize(Long.toString(bytesToMeg(memUsage.getMax())));
memberInfo.setInitHeapSize(Long.toString(bytesToMeg(memUsage.getInit())));
memberInfo.setHostedRegions(CliUtil.getAllRegionNames());
List<CacheServer> csList = cache.getCacheServers();
// A member is a server only if it has a cacheserver
if (csList != null) {
memberInfo.setServer(true);
Iterator<CacheServer> iters = csList.iterator();
while (iters.hasNext()) {
CacheServer cs = iters.next();
String bindAddress = cs.getBindAddress();
int port = cs.getPort();
boolean isRunning = cs.isRunning();
CacheServerInfo cacheServerInfo = new CacheServerInfo(bindAddress, port, isRunning);
memberInfo.addCacheServerInfo(cacheServerInfo);
}
Map<ClientProxyMembershipID, CacheClientStatus> allConnectedClients = InternalClientMembership.getStatusForAllClientsIgnoreSubscriptionStatus();
Iterator<ClientProxyMembershipID> it = allConnectedClients.keySet().iterator();
int numConnections = 0;
while (it.hasNext()) {
CacheClientStatus status = allConnectedClients.get(it.next());
numConnections = numConnections + status.getNumberOfConnections();
}
memberInfo.setClientCount(numConnections);
} else {
memberInfo.setServer(false);
}
functionContext.getResultSender().lastResult(memberInfo);
} catch (CacheClosedException e) {
functionContext.getResultSender().sendException(e);
} catch (Exception e) {
functionContext.getResultSender().sendException(e);
}
}
use of java.lang.management.MemoryUsage in project metrics by dropwizard.
the class MemoryUsageGaugeSet method getMetrics.
@Override
public Map<String, Metric> getMetrics() {
final Map<String, Metric> gauges = new HashMap<>();
gauges.put("total.init", (Gauge<Long>) () -> mxBean.getHeapMemoryUsage().getInit() + mxBean.getNonHeapMemoryUsage().getInit());
gauges.put("total.used", (Gauge<Long>) () -> mxBean.getHeapMemoryUsage().getUsed() + mxBean.getNonHeapMemoryUsage().getUsed());
gauges.put("total.max", (Gauge<Long>) () -> mxBean.getHeapMemoryUsage().getMax() + mxBean.getNonHeapMemoryUsage().getMax());
gauges.put("total.committed", (Gauge<Long>) () -> mxBean.getHeapMemoryUsage().getCommitted() + mxBean.getNonHeapMemoryUsage().getCommitted());
gauges.put("heap.init", (Gauge<Long>) () -> mxBean.getHeapMemoryUsage().getInit());
gauges.put("heap.used", (Gauge<Long>) () -> mxBean.getHeapMemoryUsage().getUsed());
gauges.put("heap.max", (Gauge<Long>) () -> mxBean.getHeapMemoryUsage().getMax());
gauges.put("heap.committed", (Gauge<Long>) () -> mxBean.getHeapMemoryUsage().getCommitted());
gauges.put("heap.usage", new RatioGauge() {
@Override
protected Ratio getRatio() {
final MemoryUsage usage = mxBean.getHeapMemoryUsage();
return Ratio.of(usage.getUsed(), usage.getMax());
}
});
gauges.put("non-heap.init", (Gauge<Long>) () -> mxBean.getNonHeapMemoryUsage().getInit());
gauges.put("non-heap.used", (Gauge<Long>) () -> mxBean.getNonHeapMemoryUsage().getUsed());
gauges.put("non-heap.max", (Gauge<Long>) () -> mxBean.getNonHeapMemoryUsage().getMax());
gauges.put("non-heap.committed", (Gauge<Long>) () -> mxBean.getNonHeapMemoryUsage().getCommitted());
gauges.put("non-heap.usage", new RatioGauge() {
@Override
protected Ratio getRatio() {
final MemoryUsage usage = mxBean.getNonHeapMemoryUsage();
return Ratio.of(usage.getUsed(), usage.getMax());
}
});
for (final MemoryPoolMXBean pool : memoryPools) {
final String poolName = name("pools", WHITESPACE.matcher(pool.getName()).replaceAll("-"));
gauges.put(name(poolName, "usage"), new RatioGauge() {
@Override
protected Ratio getRatio() {
MemoryUsage usage = pool.getUsage();
return Ratio.of(usage.getUsed(), usage.getMax() == -1 ? usage.getCommitted() : usage.getMax());
}
});
gauges.put(name(poolName, "max"), (Gauge<Long>) () -> pool.getUsage().getMax());
gauges.put(name(poolName, "used"), (Gauge<Long>) () -> pool.getUsage().getUsed());
gauges.put(name(poolName, "committed"), (Gauge<Long>) () -> pool.getUsage().getCommitted());
// Only register GC usage metrics if the memory pool supports usage statistics.
if (pool.getCollectionUsage() != null) {
gauges.put(name(poolName, "used-after-gc"), (Gauge<Long>) () -> pool.getCollectionUsage().getUsed());
}
gauges.put(name(poolName, "init"), (Gauge<Long>) () -> pool.getUsage().getInit());
}
return Collections.unmodifiableMap(gauges);
}
use of java.lang.management.MemoryUsage in project Lucee by lucee.
the class MacAddressWrap method getMemoryUsageCompact.
public static Struct getMemoryUsageCompact(int type) {
java.util.List<MemoryPoolMXBean> manager = ManagementFactory.getMemoryPoolMXBeans();
Iterator<MemoryPoolMXBean> it = manager.iterator();
MemoryPoolMXBean bean;
MemoryUsage usage;
MemoryType _type;
Struct sct = new StructImpl();
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;
double d = ((int) (100D / usage.getMax() * usage.getUsed())) / 100D;
sct.setEL(KeyImpl.init(bean.getName()), Caster.toDouble(d));
}
return sct;
}
Aggregations