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;
}
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.");
}
}
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;
}
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);
}
}
}
}
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;
}
Aggregations