Search in sources :

Example 21 with MemoryUsage

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);
}
Also used : MemoryUsage(java.lang.management.MemoryUsage)

Example 22 with MemoryUsage

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;
}
Also used : DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) BufferPoolMXBean(java.lang.management.BufferPoolMXBean) MemoryUsage(java.lang.management.MemoryUsage)

Example 23 with MemoryUsage

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);
    }
}
Also used : CacheClientStatus(org.apache.geode.internal.cache.CacheClientStatus) CacheClosedException(org.apache.geode.cache.CacheClosedException) MemoryUsage(java.lang.management.MemoryUsage) CacheServerInfo(org.apache.geode.management.internal.cli.domain.CacheServerInfo) CacheClosedException(org.apache.geode.cache.CacheClosedException) ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) MemoryMXBean(java.lang.management.MemoryMXBean) MemberInformation(org.apache.geode.management.internal.cli.domain.MemberInformation) CacheServer(org.apache.geode.cache.server.CacheServer) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) Cache(org.apache.geode.cache.Cache)

Example 24 with MemoryUsage

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);
        }
    }
}
Also used : MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) MemoryUsage(java.lang.management.MemoryUsage)

Example 25 with MemoryUsage

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());
}
Also used : CacheServiceMBean(org.apache.cassandra.service.CacheServiceMBean) MemoryUsage(java.lang.management.MemoryUsage)

Aggregations

MemoryUsage (java.lang.management.MemoryUsage)63 MemoryMXBean (java.lang.management.MemoryMXBean)13 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)11 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)6 RuntimeMXBean (java.lang.management.RuntimeMXBean)6 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)4 ThreadMXBean (java.lang.management.ThreadMXBean)4 HashMap (java.util.HashMap)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 NotNull (org.jetbrains.annotations.NotNull)3 ApplicationInfo (com.intellij.openapi.application.ApplicationInfo)2 GarbageCollectionNotificationInfo (com.sun.management.GarbageCollectionNotificationInfo)2 BufferPoolMXBean (java.lang.management.BufferPoolMXBean)2 ClassLoadingMXBean (java.lang.management.ClassLoadingMXBean)2 Date (java.util.Date)2 CacheServiceMBean (org.apache.cassandra.service.CacheServiceMBean)2 Metric (com.codahale.metrics.Metric)1 RatioGauge (com.codahale.metrics.RatioGauge)1