Search in sources :

Example 1 with ClientHealthStats

use of org.apache.geode.internal.admin.remote.ClientHealthStats in project geode by apache.

the class ClientStatsManager method getClientHealthStats.

/**
   * This method queries the client stats & prepares the client health stats object to be published
   * to the server.
   * 
   * @return the client health stats object to be published to the server.
   */
private static ClientHealthStats getClientHealthStats(InternalCache currentCache, PoolImpl pool) {
    if (currentCache == null) {
        return null;
    }
    ClientHealthStats stats = new ClientHealthStats();
    LogWriterI18n logger = currentCache.getLoggerI18n();
    int gets = -1;
    int puts = -1;
    int misses = -1;
    int cacheListenerCalls = -1;
    if (cachePerfStats != null) {
        gets = cachePerfStats.getInt("gets");
        puts = cachePerfStats.getInt("puts");
        misses = cachePerfStats.getInt("misses");
        cacheListenerCalls = cachePerfStats.getInt("cacheListenerCallsCompleted");
    }
    long processCpuTime = -1;
    int threads = -1;
    int cpus = -1;
    if (vmStats != null) {
        processCpuTime = vmStats.getLong("processCpuTime");
        threads = vmStats.getInt("threads");
        cpus = vmStats.getInt("cpus");
    }
    stats.setNumOfGets(gets);
    stats.setNumOfPuts(puts);
    stats.setNumOfMisses(misses);
    stats.setNumOfCacheListenerCalls(cacheListenerCalls);
    stats.setProcessCpuTime(processCpuTime);
    stats.setNumOfThreads(threads);
    stats.setCpus(cpus);
    String poolName = pool.getName();
    try {
        Map<String, String> newPoolStats = stats.getPoolStats();
        String poolStatsStr = "MinConnections=" + pool.getMinConnections() + ";MaxConnections=" + pool.getMaxConnections() + ";Redundancy=" + pool.getSubscriptionRedundancy() + ";CQS=" + pool.getQueryService().getCqs().length;
        logger.info(LocalizedStrings.DEBUG, "ClientHealthStats for poolName " + poolName + " poolStatsStr=" + poolStatsStr);
        newPoolStats.put(poolName, poolStatsStr);
        // consider old stats
        Region clientHealthMonitoringRegion = ClientHealthMonitoringRegion.getInstance(currentCache);
        if (clientHealthMonitoringRegion != null) {
            InternalDistributedSystem ds = (InternalDistributedSystem) currentCache.getDistributedSystem();
            ClientHealthStats oldStats = (ClientHealthStats) clientHealthMonitoringRegion.get(ds.getMemberId());
            logger.info(LocalizedStrings.DEBUG, "getClientHealthStats got oldStats  " + oldStats);
            if (oldStats != null) {
                Map<String, String> oldPoolStats = oldStats.getPoolStats();
                logger.info(LocalizedStrings.DEBUG, "getClientHealthStats got oldPoolStats  " + oldPoolStats);
                if (oldPoolStats != null) {
                    for (Entry<String, String> entry : oldPoolStats.entrySet()) {
                        if (!poolName.equals(entry.getKey())) {
                            stats.getPoolStats().put(entry.getKey(), entry.getValue());
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        logger.fine("Exception in getting pool stats in  getClientHealthStats " + CliUtil.stackTraceAsString(e));
    }
    stats.setUpdateTime(new Date());
    return stats;
}
Also used : Region(org.apache.geode.cache.Region) LogWriterI18n(org.apache.geode.i18n.LogWriterI18n) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) ClientHealthStats(org.apache.geode.internal.admin.remote.ClientHealthStats) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) CacheWriterException(org.apache.geode.cache.CacheWriterException) Date(java.util.Date)

Example 2 with ClientHealthStats

use of org.apache.geode.internal.admin.remote.ClientHealthStats in project geode by apache.

the class ClientStatsManager method publishClientStats.

/**
   * This method publishes the client stats using the admin region.
   * 
   * @param pool Connection pool which may be used for admin region.
   */
public static synchronized void publishClientStats(PoolImpl pool) {
    InternalCache currentCache = GemFireCacheImpl.getInstance();
    if (!initializeStatistics(currentCache)) {
        // handles null case too
        return;
    }
    LogWriterI18n logger = currentCache.getLoggerI18n();
    if (logger.fineEnabled())
        logger.fine("Entering ClientStatsManager#publishClientStats...");
    ClientHealthStats stats = getClientHealthStats(currentCache, pool);
    try {
        InternalDistributedSystem ds = (InternalDistributedSystem) currentCache.getDistributedSystem();
        ServerRegionProxy regionProxy = new ServerRegionProxy(ClientHealthMonitoringRegion.ADMIN_REGION_NAME, pool);
        EventID eventId = new EventID(ds);
        @Released EntryEventImpl event = new EntryEventImpl((Object) null);
        try {
            event.setEventId(eventId);
            regionProxy.putForMetaRegion(ds.getMemberId(), stats, null, event, null, true);
        } finally {
            event.release();
        }
    } catch (DistributedSystemDisconnectedException e) {
        throw e;
    } catch (CacheWriterException cwx) {
        pool.getCancelCriterion().checkCancelInProgress(cwx);
        currentCache.getCancelCriterion().checkCancelInProgress(cwx);
        // TODO: Need to analyze these exception scenarios.
        logger.warning(LocalizedStrings.ClientStatsManager_FAILED_TO_SEND_CLIENT_HEALTH_STATS_TO_CACHESERVER, cwx);
    } catch (Exception e) {
        pool.getCancelCriterion().checkCancelInProgress(e);
        currentCache.getCancelCriterion().checkCancelInProgress(e);
        logger.info(LocalizedStrings.ClientStatsManager_FAILED_TO_PUBLISH_CLIENT_STATISTICS, e);
    }
    if (logger.fineEnabled()) {
        logger.fine("Exiting ClientStatsManager#publishClientStats.");
    }
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) Released(org.apache.geode.internal.offheap.annotations.Released) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) InternalCache(org.apache.geode.internal.cache.InternalCache) EventID(org.apache.geode.internal.cache.EventID) LogWriterI18n(org.apache.geode.i18n.LogWriterI18n) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) ClientHealthStats(org.apache.geode.internal.admin.remote.ClientHealthStats) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) CacheWriterException(org.apache.geode.cache.CacheWriterException) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Example 3 with ClientHealthStats

use of org.apache.geode.internal.admin.remote.ClientHealthStats in project geode by apache.

the class CacheServerBridge method getClientHealthStatus.

private ClientHealthStatus getClientHealthStatus(ClientConnInfo connInfo) {
    ClientProxyMembershipID proxyId = connInfo.getClientId();
    CacheClientProxy proxy = CacheClientNotifier.getInstance().getClientProxy(proxyId);
    if (proxy != null && !proxy.isConnected() && !proxyId.isDurable()) {
        return null;
    }
    CacheServerBridge.clientVersion.set(getClientVersion(connInfo));
    int clientCQCount = 0;
    CqService cqService = cache.getCqService();
    if (cqService != null) {
        List<ServerCQ> cqs = cqService.getAllClientCqs(proxyId);
        clientCQCount = cqs.size();
    }
    ClientHealthStatus status = new ClientHealthStatus();
    Region clientHealthMonitoringRegion = ClientHealthMonitoringRegion.getInstance(this.cache);
    String clientName = proxyId.getDSMembership();
    status.setClientId(connInfo.toString());
    status.setName(clientName);
    status.setHostName(connInfo.getHostName());
    status.setClientCQCount(clientCQCount);
    // Only available for clients having subscription enabled true
    if (proxy != null) {
        status.setUpTime(proxy.getUpTime());
        status.setQueueSize(proxy.getQueueSizeStat());
        status.setConnected(proxy.isConnected());
        status.setSubscriptionEnabled(true);
    } else {
        status.setConnected(true);
        status.setSubscriptionEnabled(false);
    }
    ClientHealthStats stats = (ClientHealthStats) clientHealthMonitoringRegion.get(clientName);
    if (stats != null) {
        status.setCpus(stats.getCpus());
        status.setNumOfCacheListenerCalls(stats.getNumOfCacheListenerCalls());
        status.setNumOfGets(stats.getNumOfGets());
        status.setNumOfMisses(stats.getNumOfMisses());
        status.setNumOfPuts(stats.getNumOfPuts());
        status.setNumOfThreads(stats.getNumOfThreads());
        status.setProcessCpuTime(stats.getProcessCpuTime());
        status.setPoolStats(stats.getPoolStats());
    }
    return status;
}
Also used : ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) ClientHealthStatus(org.apache.geode.management.ClientHealthStatus) Region(org.apache.geode.cache.Region) ClientHealthMonitoringRegion(org.apache.geode.internal.admin.ClientHealthMonitoringRegion) ServerCQ(org.apache.geode.cache.query.internal.cq.ServerCQ) CqService(org.apache.geode.cache.query.internal.cq.CqService) ClientHealthStats(org.apache.geode.internal.admin.remote.ClientHealthStats)

Example 4 with ClientHealthStats

use of org.apache.geode.internal.admin.remote.ClientHealthStats in project geode by apache.

the class GemFireMemberStatus method initializeServer.

protected void initializeServer() {
    Collection servers = cache.getCacheServers();
    if (servers.size() == 0) {
        setIsServer(false);
    } else {
        setIsServer(true);
        // Get connected clients.
        // The following method returns a map of client member id to a cache
        // client info. For now, keep track of the member ids in the set of
        // _connectedClients.
        Map allConnectedClients = InternalClientMembership.getStatusForAllClientsIgnoreSubscriptionStatus();
        Iterator allConnectedClientsIterator = allConnectedClients.values().iterator();
        while (allConnectedClientsIterator.hasNext()) {
            CacheClientStatus ccs = (CacheClientStatus) allConnectedClientsIterator.next();
            addConnectedClient(ccs.getMemberId());
            // host address is available directly by id, hence CacheClientStatus need not be populated
            putClientHostName(ccs.getMemberId(), ccs.getHostAddress());
        }
        // Get client queue sizes
        Map clientQueueSize = getClientIDMap(InternalClientMembership.getClientQueueSizes());
        setClientQueueSizes(clientQueueSize);
        // Set server acceptor port (set it based on the first CacheServer)
        CacheServer server = (CacheServer) servers.toArray()[0];
        setServerPort(server.getPort());
        // Get Client Health Stats
        // Assert.assertTrue(cache != null); (cannot be null)
        Region clientHealthMonitoringRegion = ClientHealthMonitoringRegion.getInstance((InternalCache) cache);
        if (clientHealthMonitoringRegion != null) {
            String[] clients = (String[]) clientHealthMonitoringRegion.keySet().toArray(new String[0]);
            for (int i = 0; i < clients.length; i++) {
                String clientId = clients[i];
                ClientHealthStats stats = (ClientHealthStats) clientHealthMonitoringRegion.get(clientId);
                setClientHealthStats(clientId, stats);
            }
        }
    }
}
Also used : CacheClientStatus(org.apache.geode.internal.cache.CacheClientStatus) Iterator(java.util.Iterator) Collection(java.util.Collection) CacheServer(org.apache.geode.cache.server.CacheServer) HARegion(org.apache.geode.internal.cache.HARegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) ClientHealthMonitoringRegion(org.apache.geode.internal.admin.ClientHealthMonitoringRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) HashMap(java.util.HashMap) Map(java.util.Map) ClientHealthStats(org.apache.geode.internal.admin.remote.ClientHealthStats)

Example 5 with ClientHealthStats

use of org.apache.geode.internal.admin.remote.ClientHealthStats in project geode by apache.

the class NotificationForwarder method getClientDetails.

/**
   * 
   * @param snapshot
   * @return Map of client details
   */
@SuppressWarnings("rawtypes")
private Map<String, Map<String, ?>> getClientDetails(GemFireMemberStatus snapshot) {
    Map<String, Map<String, ?>> clientsInfo = new LinkedHashMap<String, Map<String, ?>>();
    Set connectedClients = snapshot.getConnectedClients();
    if (!connectedClients.isEmpty()) {
        Map clientHealthStatsMap = snapshot.getClientHealthStats();
        for (Iterator iterator = connectedClients.iterator(); iterator.hasNext(); ) {
            Map<String, Object> clientData = new HashMap<String, Object>();
            String clientId = (String) iterator.next();
            String host = snapshot.getClientHostName(clientId);
            clientData.put(CLIENT_ID, clientId);
            clientData.put(CLIENT_NAME, extractClientName(clientId, host));
            clientData.put(CLIENT_HOST, host);
            clientData.put(CLIENT_QUEUESIZE, snapshot.getClientQueueSize(clientId));
            ClientHealthStats clientHealthStats = (ClientHealthStats) clientHealthStatsMap.get(clientId);
            if (clientHealthStats != null) {
                clientData.put(CLIENT_STATS_GETS, clientHealthStats.getNumOfGets());
                clientData.put(CLIENT_STATS_PUTS, clientHealthStats.getNumOfPuts());
                clientData.put(CLIENT_STATS_CACHEMISSES, clientHealthStats.getNumOfMisses());
                clientData.put(CLIENT_STATS_CPUUSAGE, clientHealthStats.getProcessCpuTime());
                clientData.put(CLIENT_STATS_CPUS, clientHealthStats.getCpus());
                clientData.put(CLIENT_STATS_UPDATETIME, clientHealthStats.getUpdateTime().getTime());
                clientData.put(CLIENT_STATS_THREADS, clientHealthStats.getNumOfThreads());
            } else {
                clientData.put(CLIENT_STATS_GETS, Integer.valueOf(0));
                clientData.put(CLIENT_STATS_PUTS, Integer.valueOf(0));
                clientData.put(CLIENT_STATS_CACHEMISSES, Integer.valueOf(0));
                clientData.put(CLIENT_STATS_CPUUSAGE, Long.valueOf(0));
                clientData.put(CLIENT_STATS_CPUS, Integer.valueOf(0));
                clientData.put(CLIENT_STATS_UPDATETIME, Long.valueOf(0));
                clientData.put(CLIENT_STATS_THREADS, Integer.valueOf(0));
            }
            clientsInfo.put(clientId, clientData);
        }
    }
    return clientsInfo;
}
Also used : ClientHealthStats(org.apache.geode.internal.admin.remote.ClientHealthStats)

Aggregations

ClientHealthStats (org.apache.geode.internal.admin.remote.ClientHealthStats)5 Region (org.apache.geode.cache.Region)3 CacheWriterException (org.apache.geode.cache.CacheWriterException)2 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)2 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)2 LogWriterI18n (org.apache.geode.i18n.LogWriterI18n)2 ClientHealthMonitoringRegion (org.apache.geode.internal.admin.ClientHealthMonitoringRegion)2 Collection (java.util.Collection)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 ServerRegionProxy (org.apache.geode.cache.client.internal.ServerRegionProxy)1 CqService (org.apache.geode.cache.query.internal.cq.CqService)1 ServerCQ (org.apache.geode.cache.query.internal.cq.ServerCQ)1 CacheServer (org.apache.geode.cache.server.CacheServer)1 CacheClientStatus (org.apache.geode.internal.cache.CacheClientStatus)1 EntryEventImpl (org.apache.geode.internal.cache.EntryEventImpl)1 EventID (org.apache.geode.internal.cache.EventID)1 HARegion (org.apache.geode.internal.cache.HARegion)1