use of java.lang.management.MemoryUsage in project jdk8u_jdk by JetBrains.
the class MemoryUsageCompositeData method createGoodCompositeData.
public static void createGoodCompositeData() throws Exception {
final int K = 1024;
// these values are synchronized with the item names
final Object[] values = { // committed
new Long(5 * K), // init
new Long(1 * K), // max
new Long(10 * K), // used
new Long(2 * K), "Dummy", "Dummy" };
CompositeType muct = new CompositeType("MyMemoryUsageCompositeType", "CompositeType for MemoryUsage", memoryUsageItemNames, memoryUsageItemNames, memoryUsageItemTypes);
CompositeData cd = new CompositeDataSupport(muct, memoryUsageItemNames, values);
MemoryUsage u = MemoryUsage.from(cd);
if (u.getInit() != ((Long) values[INIT]).longValue()) {
throw new RuntimeException("init = " + u.getInit() + " expected = " + values[INIT]);
}
if (u.getUsed() != ((Long) values[USED]).longValue()) {
throw new RuntimeException("used = " + u.getUsed() + " expected = " + values[USED]);
}
if (u.getCommitted() != ((Long) values[COMMITTED]).longValue()) {
throw new RuntimeException("committed = " + u.getCommitted() + " expected = " + values[COMMITTED]);
}
if (u.getMax() != ((Long) values[MAX]).longValue()) {
throw new RuntimeException("max = " + u.getMax() + " expected = " + values[MAX]);
}
System.out.println(u);
}
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 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 heron by twitter.
the class JVMMetrics method updateMemoryPoolMetrics.
// Gather metrics for different memory pools in heap, for instance:
// Par Eden Space, Par Survivor Space, CMS Old Gen, CMS Perm Gen
private void updateMemoryPoolMetrics() {
for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeanList) {
String normalizedKeyName = memoryPoolMXBean.getName().replaceAll("[^\\w]", "-");
MemoryUsage peakUsage = memoryPoolMXBean.getPeakUsage();
if (peakUsage != null) {
jvmPeakUsagePerMemoryPool.safeScope(normalizedKeyName + "-used").setValue(peakUsage.getUsed() / Constants.MB_TO_BYTES);
jvmPeakUsagePerMemoryPool.safeScope(normalizedKeyName + "-committed").setValue(peakUsage.getCommitted() / Constants.MB_TO_BYTES);
jvmPeakUsagePerMemoryPool.safeScope(normalizedKeyName + "-max").setValue(peakUsage.getMax() / Constants.MB_TO_BYTES);
}
MemoryUsage collectionUsage = memoryPoolMXBean.getCollectionUsage();
if (collectionUsage != null) {
jvmCollectionUsagePerMemoryPool.safeScope(normalizedKeyName + "-used").setValue(collectionUsage.getUsed() / Constants.MB_TO_BYTES);
jvmCollectionUsagePerMemoryPool.safeScope(normalizedKeyName + "-committed").setValue(collectionUsage.getCommitted() / Constants.MB_TO_BYTES);
jvmCollectionUsagePerMemoryPool.safeScope(normalizedKeyName + "-max").setValue(collectionUsage.getMax() / Constants.MB_TO_BYTES);
}
MemoryUsage estimatedUsage = memoryPoolMXBean.getUsage();
if (estimatedUsage != null) {
jvmEstimatedUsagePerMemoryPool.safeScope(normalizedKeyName + "-used").setValue(estimatedUsage.getUsed() / Constants.MB_TO_BYTES);
jvmEstimatedUsagePerMemoryPool.safeScope(normalizedKeyName + "-committed").setValue(estimatedUsage.getCommitted() / Constants.MB_TO_BYTES);
jvmEstimatedUsagePerMemoryPool.safeScope(normalizedKeyName + "-max").setValue(estimatedUsage.getMax() / Constants.MB_TO_BYTES);
}
}
}
use of java.lang.management.MemoryUsage in project eiger by wlloyd.
the class NodeCmd method printInfo.
/**
* Write node information.
*
* @param outs the stream to write to
*/
public void printInfo(PrintStream outs) {
boolean gossipInitialized = probe.isInitialized();
outs.printf("%-17s: %s%n", "Token", probe.getToken());
outs.printf("%-17s: %s%n", "Gossip active", gossipInitialized);
outs.printf("%-17s: %s%n", "Load", probe.getLoadString());
if (gossipInitialized)
outs.printf("%-17s: %s%n", "Generation No", probe.getCurrentGenerationNumber());
else
outs.printf("%-17s: %s%n", "Generation No", 0);
// Uptime
long secondsUp = probe.getUptime() / 1000;
outs.printf("%-17s: %d%n", "Uptime (seconds)", secondsUp);
// Memory usage
MemoryUsage heapUsage = probe.getHeapMemoryUsage();
double memUsed = (double) heapUsage.getUsed() / (1024 * 1024);
double memMax = (double) heapUsage.getMax() / (1024 * 1024);
outs.printf("%-17s: %.2f / %.2f%n", "Heap Memory (MB)", memUsed, memMax);
// Data Center/Rack
outs.printf("%-17s: %s%n", "Data Center", probe.getDataCenter());
outs.printf("%-17s: %s%n", "Rack", probe.getRack());
// Exceptions
outs.printf("%-17s: %s%n", "Exceptions", probe.getExceptionCount());
CacheServiceMBean cacheService = probe.getCacheServiceMBean();
// Key Cache: Hits, Requests, RecentHitRate, SavePeriodInSeconds
outs.printf("%-17s: size %d (bytes), capacity %d (bytes), %d hits, %d requests, %.3f recent hit rate, %d save period in seconds%n", "Key Cache", cacheService.getKeyCacheSize(), cacheService.getKeyCacheCapacityInBytes(), cacheService.getKeyCacheHits(), cacheService.getKeyCacheRequests(), cacheService.getKeyCacheRecentHitRate(), cacheService.getKeyCacheSavePeriodInSeconds());
// Row Cache: Hits, Requests, RecentHitRate, SavePeriodInSeconds
outs.printf("%-17s: size %d (bytes), capacity %d (bytes), %d hits, %d requests, %.3f recent hit rate, %d save period in seconds%n", "Row Cache", cacheService.getRowCacheSize(), cacheService.getRowCacheCapacityInBytes(), cacheService.getRowCacheHits(), cacheService.getRowCacheRequests(), cacheService.getRowCacheRecentHitRate(), cacheService.getRowCacheSavePeriodInSeconds());
}
Aggregations