Search in sources :

Example 1 with CacheServerMXBean

use of org.apache.geode.management.CacheServerMXBean in project geode by apache.

the class ClientCommands method describeClient.

@CliCommand(value = CliStrings.DESCRIBE_CLIENT, help = CliStrings.DESCRIBE_CLIENT__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_CLIENT })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result describeClient(@CliOption(key = CliStrings.DESCRIBE_CLIENT__ID, mandatory = true, help = CliStrings.DESCRIBE_CLIENT__ID__HELP) String clientId) {
    Result result = null;
    if (clientId.startsWith("\"")) {
        clientId = clientId.substring(1);
    }
    if (clientId.endsWith("\"")) {
        clientId = clientId.substring(0, clientId.length() - 2);
    }
    if (clientId.endsWith("\";")) {
        clientId = clientId.substring(0, clientId.length() - 2);
    }
    try {
        CompositeResultData compositeResultData = ResultBuilder.createCompositeResultData();
        SectionResultData sectionResult = compositeResultData.addSection("InfoSection");
        InternalCache cache = getCache();
        ManagementService service = ManagementService.getExistingManagementService(cache);
        ObjectName[] cacheServers = service.getDistributedSystemMXBean().listCacheServerObjectNames();
        if (cacheServers.length == 0) {
            return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.DESCRIBE_CLIENT_COULD_NOT_RETRIEVE_SERVER_LIST));
        }
        ClientHealthStatus clientHealthStatus = null;
        for (ObjectName objName : cacheServers) {
            CacheServerMXBean serverMbean = service.getMBeanInstance(objName, CacheServerMXBean.class);
            List<String> listOfClient = new ArrayList<String>(Arrays.asList((String[]) serverMbean.getClientIds()));
            if (listOfClient.contains(clientId)) {
                if (clientHealthStatus == null) {
                    try {
                        clientHealthStatus = serverMbean.showClientStats(clientId);
                        if (clientHealthStatus == null) {
                            return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.DESCRIBE_CLIENT_COULD_NOT_RETRIEVE_STATS_FOR_CLIENT_0, clientId));
                        }
                    } catch (Exception eee) {
                        return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.DESCRIBE_CLIENT_COULD_NOT_RETRIEVE_STATS_FOR_CLIENT_0_REASON_1, clientId, eee.getMessage()));
                    }
                }
            }
        }
        if (clientHealthStatus == null) {
            return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.DESCRIBE_CLIENT__CLIENT__ID__NOT__FOUND__0, clientId));
        }
        Set<DistributedMember> dsMembers = CliUtil.getAllMembers(cache);
        String isDurable = null;
        List<String> primaryServers = new ArrayList<String>();
        List<String> secondaryServers = new ArrayList<String>();
        if (dsMembers.size() > 0) {
            ContunuousQueryFunction contunuousQueryFunction = new ContunuousQueryFunction();
            FunctionService.registerFunction(contunuousQueryFunction);
            List<?> resultList = (List<?>) CliUtil.executeFunction(contunuousQueryFunction, clientId, dsMembers).getResult();
            for (int i = 0; i < resultList.size(); i++) {
                try {
                    Object object = resultList.get(i);
                    if (object instanceof Throwable) {
                        LogWrapper.getInstance().warning("Exception in Describe Client " + ((Throwable) object).getMessage(), ((Throwable) object));
                        continue;
                    }
                    if (object != null) {
                        ClientInfo objectResult = (ClientInfo) object;
                        isDurable = objectResult.isDurable;
                        if (objectResult.primaryServer != null && objectResult.primaryServer.length() > 0) {
                            if (primaryServers.size() == 0) {
                                primaryServers.add(objectResult.primaryServer);
                            } else {
                                primaryServers.add(" ,");
                                primaryServers.add(objectResult.primaryServer);
                            }
                        }
                        if (objectResult.secondaryServer != null && objectResult.secondaryServer.length() > 0) {
                            if (secondaryServers.size() == 0) {
                                secondaryServers.add(objectResult.secondaryServer);
                            } else {
                                secondaryServers.add(" ,");
                                secondaryServers.add(objectResult.secondaryServer);
                            }
                        }
                    }
                } catch (Exception e) {
                    LogWrapper.getInstance().info(CliStrings.DESCRIBE_CLIENT_ERROR_FETCHING_STATS_0 + " :: " + CliUtil.stackTraceAsString(e));
                    return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.DESCRIBE_CLIENT_ERROR_FETCHING_STATS_0, e.getMessage()));
                }
            }
            buildTableResult(sectionResult, clientHealthStatus, isDurable, primaryServers, secondaryServers);
            result = ResultBuilder.buildResult(compositeResultData);
        } else {
            return ResultBuilder.createGemFireErrorResult(CliStrings.DESCRIBE_CLIENT_NO_MEMBERS);
        }
    } catch (Exception e) {
        LogWrapper.getInstance().info("Error in decribe clients. stack trace" + CliUtil.stackTraceAsString(e));
        result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.DESCRIBE_CLIENT_COULD_NOT_RETRIEVE_CLIENT_0, e.getMessage()));
    }
    LogWrapper.getInstance().info("decribe client result " + result);
    return result;
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) ArrayList(java.util.ArrayList) ContunuousQueryFunction(org.apache.geode.management.internal.cli.functions.ContunuousQueryFunction) InternalCache(org.apache.geode.internal.cache.InternalCache) CacheServerMXBean(org.apache.geode.management.CacheServerMXBean) Result(org.apache.geode.management.cli.Result) ObjectName(javax.management.ObjectName) ManagementService(org.apache.geode.management.ManagementService) ClientHealthStatus(org.apache.geode.management.ClientHealthStatus) DistributedMember(org.apache.geode.distributed.DistributedMember) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) ArrayList(java.util.ArrayList) List(java.util.List) ClientInfo(org.apache.geode.management.internal.cli.functions.ContunuousQueryFunction.ClientInfo) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 2 with CacheServerMXBean

use of org.apache.geode.management.CacheServerMXBean in project geode by apache.

the class MiscellaneousCommands method getMemberMetrics.

/**
   * Gets the Cluster wide metrics for a given member
   *
   * @return ResultData with required Member statistics or ErrorResultData if MemberMbean is not
   *         found to gather metrics
   * @throws ResultDataException if building result fails
   */
private ResultData getMemberMetrics(DistributedMember distributedMember, String export_to_report_to, String[] categoriesArr, int cacheServerPort) throws ResultDataException {
    final InternalCache cache = getCache();
    final SystemManagementService managementService = (SystemManagementService) ManagementService.getManagementService(cache);
    ObjectName memberMBeanName = managementService.getMemberMBeanName(distributedMember);
    MemberMXBean memberMxBean = managementService.getMBeanInstance(memberMBeanName, MemberMXBean.class);
    ObjectName csMxBeanName = null;
    CacheServerMXBean csMxBean = null;
    if (memberMxBean != null) {
        if (cacheServerPort != -1) {
            csMxBeanName = managementService.getCacheServerMBeanName(cacheServerPort, distributedMember);
            csMxBean = managementService.getMBeanInstance(csMxBeanName, CacheServerMXBean.class);
            if (csMxBean == null) {
                ErrorResultData erd = ResultBuilder.createErrorResultData();
                erd.addLine(CliStrings.format(CliStrings.SHOW_METRICS__CACHE__SERVER__NOT__FOUND, cacheServerPort, MBeanJMXAdapter.getMemberNameOrId(distributedMember)));
                return erd;
            }
        }
        JVMMetrics jvmMetrics = memberMxBean.showJVMMetrics();
        CompositeResultData crd = ResultBuilder.createCompositeResultData();
        SectionResultData section = crd.addSection();
        TabularResultData metricsTable = section.addTable();
        metricsTable.setHeader("Member Metrics");
        StringBuilder csvBuilder = null;
        if (export_to_report_to != null && !export_to_report_to.isEmpty()) {
            csvBuilder = new StringBuilder();
            csvBuilder.append("Category");
            csvBuilder.append(',');
            csvBuilder.append(CliStrings.SHOW_METRICS__METRIC__HEADER);
            csvBuilder.append(',');
            csvBuilder.append(CliStrings.SHOW_METRICS__VALUE__HEADER);
            csvBuilder.append('\n');
        }
        Map<String, Boolean> categoriesMap = getMemberMetricsCategories();
        if (categoriesArr != null && categoriesArr.length != 0) {
            Set<String> categories = createSet(categoriesArr);
            Set<String> checkSet = new HashSet<String>(categoriesMap.keySet());
            Set<String> userCategories = getSetDifference(categories, checkSet);
            // Checking if the categories specified by the user are valid or not
            if (userCategories.isEmpty()) {
                for (String category : checkSet) {
                    categoriesMap.put(category, false);
                }
                for (String category : categories) {
                    categoriesMap.put(category.toLowerCase(), true);
                }
            } else {
                StringBuilder sb = new StringBuilder();
                sb.append("Invalid Categories\n");
                for (String category : userCategories) {
                    sb.append(category);
                    sb.append('\n');
                }
                return ResultBuilder.createErrorResultData().addLine(sb.toString());
            }
        }
        // eviction, distribution
        if (categoriesMap.get("member").booleanValue()) {
            writeToTableAndCsv(metricsTable, "member", "upTime", memberMxBean.getMemberUpTime(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "cpuUsage", memberMxBean.getCpuUsage(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "currentHeapSize", memberMxBean.getCurrentHeapSize(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "maximumHeapSize", memberMxBean.getMaximumHeapSize(), csvBuilder);
        }
        /*
       * JVM Metrics
       */
        if (categoriesMap.get("jvm").booleanValue()) {
            writeToTableAndCsv(metricsTable, "jvm ", "jvmThreads ", jvmMetrics.getTotalThreads(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "fileDescriptorLimit", memberMxBean.getFileDescriptorLimit(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "totalFileDescriptorOpen", memberMxBean.getTotalFileDescriptorOpen(), csvBuilder);
        }
        /*
       * Member wide region metrics
       */
        if (categoriesMap.get("region").booleanValue()) {
            writeToTableAndCsv(metricsTable, "region ", "totalRegionCount ", memberMxBean.getTotalRegionCount(), csvBuilder);
            String[] regionNames = memberMxBean.listRegions();
            if (regionNames != null) {
                for (int i = 0; i < regionNames.length; i++) {
                    if (i == 0) {
                        writeToTableAndCsv(metricsTable, "", "listOfRegions", regionNames[i].substring(1), csvBuilder);
                    } else {
                        writeToTableAndCsv(metricsTable, "", "", regionNames[i].substring(1), csvBuilder);
                    }
                }
            }
            String[] rootRegionNames = memberMxBean.getRootRegionNames();
            if (rootRegionNames != null) {
                for (int i = 0; i < rootRegionNames.length; i++) {
                    if (i == 0) {
                        writeToTableAndCsv(metricsTable, "", "rootRegions", rootRegionNames[i], csvBuilder);
                    } else {
                        writeToTableAndCsv(metricsTable, "", "", rootRegionNames[i], csvBuilder);
                    }
                }
            }
            writeToTableAndCsv(metricsTable, "", "totalRegionEntryCount", memberMxBean.getTotalRegionEntryCount(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "totalBucketCount", memberMxBean.getTotalBucketCount(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "totalPrimaryBucketCount", memberMxBean.getTotalPrimaryBucketCount(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "getsAvgLatency", memberMxBean.getGetsAvgLatency(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "putsAvgLatency", memberMxBean.getPutsAvgLatency(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "createsRate", memberMxBean.getCreatesRate(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "destroyRate", memberMxBean.getDestroysRate(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "putAllAvgLatency", memberMxBean.getPutAllAvgLatency(), csvBuilder);
            // Not available from stats. After Stats re-org it will be avaialble
            // writeToTableAndCsv(metricsTable, "", "getAllAvgLatency",
            // memberMxBean.getGetAllAvgLatency(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "totalMissCount", memberMxBean.getTotalMissCount(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "totalHitCount", memberMxBean.getTotalHitCount(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "getsRate", memberMxBean.getGetsRate(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "putsRate", memberMxBean.getPutsRate(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "cacheWriterCallsAvgLatency", memberMxBean.getCacheWriterCallsAvgLatency(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "cacheListenerCallsAvgLatency", memberMxBean.getCacheListenerCallsAvgLatency(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "totalLoadsCompleted", memberMxBean.getTotalLoadsCompleted(), csvBuilder);
        }
        /*
       * SERIALIZATION
       */
        if (categoriesMap.get("serialization").booleanValue()) {
            writeToTableAndCsv(metricsTable, "serialization", "serializationRate", memberMxBean.getSerializationRate(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "serializationLatency", memberMxBean.getSerializationRate(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "deserializationRate", memberMxBean.getDeserializationRate(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "deserializationLatency", memberMxBean.getDeserializationLatency(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "deserializationAvgLatency", memberMxBean.getDeserializationAvgLatency(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "PDXDeserializationAvgLatency", memberMxBean.getPDXDeserializationAvgLatency(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "PDXDeserializationRate", memberMxBean.getPDXDeserializationRate(), csvBuilder);
        }
        /*
       * Communication Metrics
       */
        if (categoriesMap.get("communication").booleanValue()) {
            writeToTableAndCsv(metricsTable, "communication", "bytesSentRate", memberMxBean.getBytesSentRate(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "bytesReceivedRate", memberMxBean.getBytesReceivedRate(), csvBuilder);
            String[] connectedGatewayReceivers = memberMxBean.listConnectedGatewayReceivers();
            writeToTableAndCsv(metricsTable, "", "connectedGatewayReceivers", connectedGatewayReceivers, csvBuilder);
            String[] connectedGatewaySenders = memberMxBean.listConnectedGatewaySenders();
            writeToTableAndCsv(metricsTable, "", "connectedGatewaySenders", connectedGatewaySenders, csvBuilder);
        }
        /*
       * Member wide function metrics
       */
        if (categoriesMap.get("function").booleanValue()) {
            writeToTableAndCsv(metricsTable, "function", "numRunningFunctions", memberMxBean.getNumRunningFunctions(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "functionExecutionRate", memberMxBean.getFunctionExecutionRate(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "numRunningFunctionsHavingResults", memberMxBean.getNumRunningFunctionsHavingResults(), csvBuilder);
        // Not Avaialble from Stats
        // writeToTableAndCsv(metricsTable, "", "funcExecutionQueueSize",
        // memberMxBean.getFuncExecutionQueueSize(), csvBuilder);
        }
        /*
       * totalTransactionsCount currentTransactionalThreadIds transactionCommitsAvgLatency
       * transactionCommittedTotalCount transactionRolledBackTotalCount transactionCommitsRate
       */
        if (categoriesMap.get("transaction").booleanValue()) {
            writeToTableAndCsv(metricsTable, "transaction", "totalTransactionsCount", memberMxBean.getTotalTransactionsCount(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "transactionCommitsAvgLatency", memberMxBean.getTransactionCommitsAvgLatency(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "transactionCommittedTotalCount", memberMxBean.getTransactionCommittedTotalCount(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "transactionRolledBackTotalCount", memberMxBean.getTransactionRolledBackTotalCount(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "transactionCommitsRate", memberMxBean.getTransactionCommitsRate(), csvBuilder);
        }
        /*
       * Member wide disk metrics
       */
        if (categoriesMap.get("diskstore").booleanValue()) {
            writeToTableAndCsv(metricsTable, "diskstore", "totalDiskUsage", memberMxBean.getTotalDiskUsage(), // deadcoded to workaround bug 46397
            csvBuilder);
            writeToTableAndCsv(metricsTable, "", /* 46608 */
            "diskReadsRate", memberMxBean.getDiskReadsRate(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "diskWritesRate", memberMxBean.getDiskWritesRate(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "flushTimeAvgLatency", memberMxBean.getDiskFlushAvgLatency(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "totalQueueSize", memberMxBean.getTotalDiskTasksWaiting(), // deadcoded to workaround bug
            csvBuilder);
            // 46397
            writeToTableAndCsv(metricsTable, "", "totalBackupInProgress", memberMxBean.getTotalBackupInProgress(), csvBuilder);
        }
        /*
       * Member wide Lock
       */
        if (categoriesMap.get("lock").booleanValue()) {
            writeToTableAndCsv(metricsTable, "lock", "lockWaitsInProgress", memberMxBean.getLockWaitsInProgress(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "totalLockWaitTime", memberMxBean.getTotalLockWaitTime(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "totalNumberOfLockService", memberMxBean.getTotalNumberOfLockService(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "requestQueues", memberMxBean.getLockRequestQueues(), csvBuilder);
        }
        /*
       * Eviction
       */
        if (categoriesMap.get("eviction").booleanValue()) {
            writeToTableAndCsv(metricsTable, "eviction", "lruEvictionRate", memberMxBean.getLruEvictionRate(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "lruDestroyRate", memberMxBean.getLruDestroyRate(), csvBuilder);
        }
        /*
       * Distribution
       */
        if (categoriesMap.get("distribution").booleanValue()) {
            writeToTableAndCsv(metricsTable, "distribution", "getInitialImagesInProgress", memberMxBean.getInitialImagesInProgres(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "getInitialImageTime", memberMxBean.getInitialImageTime(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "getInitialImageKeysReceived", memberMxBean.getInitialImageKeysReceived(), csvBuilder);
        }
        /*
       * OffHeap
       */
        if (categoriesMap.get("offheap").booleanValue()) {
            writeToTableAndCsv(metricsTable, "offheap", "maxMemory", memberMxBean.getOffHeapMaxMemory(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "freeMemory", memberMxBean.getOffHeapFreeMemory(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "usedMemory", memberMxBean.getOffHeapUsedMemory(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "objects", memberMxBean.getOffHeapObjects(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "fragmentation", memberMxBean.getOffHeapFragmentation(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "compactionTime", memberMxBean.getOffHeapCompactionTime(), csvBuilder);
        }
        /*
       * CacheServer stats
       */
        if (csMxBean != null) {
            writeToTableAndCsv(metricsTable, "cache-server", "clientConnectionCount", csMxBean.getClientConnectionCount(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "hostnameForClients", csMxBean.getHostNameForClients(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "getRequestAvgLatency", csMxBean.getGetRequestAvgLatency(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "putRequestAvgLatency", csMxBean.getPutRequestAvgLatency(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "totalConnectionsTimedOut", csMxBean.getTotalConnectionsTimedOut(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "threadQueueSize", csMxBean.getPutRequestAvgLatency(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "connectionThreads", csMxBean.getConnectionThreads(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "connectionLoad", csMxBean.getConnectionLoad(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "loadPerConnection", csMxBean.getLoadPerConnection(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "queueLoad", csMxBean.getQueueLoad(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "loadPerQueue", csMxBean.getLoadPerQueue(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "getRequestRate", csMxBean.getGetRequestRate(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "putRequestRate", csMxBean.getPutRequestRate(), csvBuilder);
            /*
         * Notification
         */
            writeToTableAndCsv(metricsTable, "notification", "numClientNotificationRequests", csMxBean.getNumClientNotificationRequests(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "clientNotificationRate", csMxBean.getClientNotificationRate(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "clientNotificationAvgLatency", csMxBean.getClientNotificationAvgLatency(), csvBuilder);
            /*
         * Query
         */
            writeToTableAndCsv(metricsTable, "query", "activeCQCount", csMxBean.getActiveCQCount(), csvBuilder);
            writeToTableAndCsv(metricsTable, "query", "queryRequestRate", csMxBean.getQueryRequestRate(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "indexCount", csMxBean.getIndexCount(), csvBuilder);
            String[] indexList = csMxBean.getIndexList();
            writeToTableAndCsv(metricsTable, "", "index list", indexList, csvBuilder);
            writeToTableAndCsv(metricsTable, "", "totalIndexMaintenanceTime", csMxBean.getTotalIndexMaintenanceTime(), csvBuilder);
        }
        if (export_to_report_to != null && !export_to_report_to.isEmpty()) {
            crd.addAsFile(export_to_report_to, csvBuilder.toString(), "Member metrics exported to {0}.", false);
        }
        return crd;
    } else {
        ErrorResultData erd = ResultBuilder.createErrorResultData();
        String errorMessage = CliStrings.format(CliStrings.SHOW_METRICS__ERROR, "Member MBean for " + MBeanJMXAdapter.getMemberNameOrId(distributedMember) + " not found");
        return ResultBuilder.createErrorResultData().addLine(errorMessage);
    }
}
Also used : JVMMetrics(org.apache.geode.management.JVMMetrics) CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) InternalCache(org.apache.geode.internal.cache.InternalCache) CacheServerMXBean(org.apache.geode.management.CacheServerMXBean) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) ConverterHint(org.apache.geode.management.cli.ConverterHint) ObjectName(javax.management.ObjectName) MemberMXBean(org.apache.geode.management.MemberMXBean) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) ErrorResultData(org.apache.geode.management.internal.cli.result.ErrorResultData) HashSet(java.util.HashSet)

Example 3 with CacheServerMXBean

use of org.apache.geode.management.CacheServerMXBean in project geode by apache.

the class ClientCommandsDUnitTest method waitForMbean.

public void waitForMbean() {
    final VM manager = Host.getHost(0).getVM(0);
    final VM server1 = Host.getHost(0).getVM(1);
    final DistributedMember serverMember = getMember(server1);
    assertNotNull(serverMember);
    manager.invoke(() -> {
        Awaitility.waitAtMost(2 * 60, TimeUnit.SECONDS).pollDelay(2, TimeUnit.SECONDS).until(() -> {
            final SystemManagementService service = (SystemManagementService) ManagementService.getManagementService(getCache());
            if (service == null) {
                getLogWriter().info("waitForMbean Still probing for service");
                return false;
            } else {
                final ObjectName cacheServerMBeanName = service.getCacheServerMBeanName(port0, serverMember);
                CacheServerMXBean bean = service.getMBeanProxy(cacheServerMBeanName, CacheServerMXBean.class);
                try {
                    ClientHealthStatus stats = bean.showClientStats(bean.getClientIds()[0]);
                    Map<String, String> poolStats = stats.getPoolStats();
                    if (poolStats.size() > 0) {
                        Iterator<Entry<String, String>> it = poolStats.entrySet().iterator();
                        while (it.hasNext()) {
                            Entry<String, String> entry = it.next();
                            String poolStatsStr = entry.getValue();
                            String[] str = poolStatsStr.split(";");
                            int numCqs = Integer.parseInt(str[3].substring(str[3].indexOf("=") + 1));
                            if (numCqs == 3) {
                                return true;
                            }
                        }
                    }
                    return false;
                } catch (Exception e) {
                    LogWrapper.getInstance().warning("waitForMbean Exception in waitForMbean ::: " + CliUtil.stackTraceAsString(e));
                }
                return false;
            }
        });
    });
}
Also used : CacheServerMXBean(org.apache.geode.management.CacheServerMXBean) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) ObjectName(javax.management.ObjectName) Entry(java.util.Map.Entry) ClientHealthStatus(org.apache.geode.management.ClientHealthStatus) VM(org.apache.geode.test.dunit.VM) DistributedMember(org.apache.geode.distributed.DistributedMember)

Example 4 with CacheServerMXBean

use of org.apache.geode.management.CacheServerMXBean in project geode by apache.

the class ClientCommandsDUnitTest method waitForListClientMbean3.

public void waitForListClientMbean3() {
    final VM manager = Host.getHost(0).getVM(0);
    final VM server1 = Host.getHost(0).getVM(1);
    final VM server2 = Host.getHost(0).getVM(3);
    final DistributedMember serverMember1 = getMember(server1);
    final DistributedMember serverMember2 = getMember(server2);
    assertNotNull(serverMember1);
    manager.invoke(() -> {
        Awaitility.waitAtMost(2 * 60, TimeUnit.SECONDS).pollDelay(2, TimeUnit.SECONDS).until(() -> {
            final SystemManagementService service = (SystemManagementService) ManagementService.getManagementService(getCache());
            if (service == null) {
                getLogWriter().info("waitForListClientMbean3 Still probing for service");
                return false;
            } else {
                final ObjectName cacheServerMBeanName1 = service.getCacheServerMBeanName(port0, serverMember1);
                final ObjectName cacheServerMBeanName2 = service.getCacheServerMBeanName(port1, serverMember2);
                CacheServerMXBean bean1 = service.getMBeanProxy(cacheServerMBeanName1, CacheServerMXBean.class);
                CacheServerMXBean bean2 = service.getMBeanProxy(cacheServerMBeanName2, CacheServerMXBean.class);
                try {
                    if (bean1 != null && bean2 != null) {
                        if (bean1.getClientIds().length > 0 && bean2.getClientIds().length > 0) {
                            return true;
                        }
                    }
                    return false;
                } catch (Exception e) {
                    LogWrapper.getInstance().warning("waitForListClientMbean3 Exception in waitForListClientMbean ::: " + CliUtil.stackTraceAsString(e));
                }
                return false;
            }
        });
    });
}
Also used : VM(org.apache.geode.test.dunit.VM) DistributedMember(org.apache.geode.distributed.DistributedMember) CacheServerMXBean(org.apache.geode.management.CacheServerMXBean) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) ObjectName(javax.management.ObjectName)

Example 5 with CacheServerMXBean

use of org.apache.geode.management.CacheServerMXBean in project geode by apache.

the class ClientCommandsDUnitTest method waitForMixedClients.

public void waitForMixedClients() {
    final VM manager = Host.getHost(0).getVM(0);
    final VM server1 = Host.getHost(0).getVM(1);
    final DistributedMember serverMember = getMember(server1);
    assertNotNull(serverMember);
    manager.invoke(() -> {
        Awaitility.waitAtMost(5 * 60, TimeUnit.SECONDS).pollDelay(2, TimeUnit.SECONDS).until(() -> {
            try {
                final SystemManagementService service = (SystemManagementService) ManagementService.getManagementService(getCache());
                if (service == null) {
                    getLogWriter().info("waitForMixedClients Still probing for service");
                    return false;
                } else {
                    getLogWriter().info("waitForMixedClients 1");
                    final ObjectName cacheServerMBeanName = service.getCacheServerMBeanName(port0, serverMember);
                    getLogWriter().info("waitForMixedClients 2 cacheServerMBeanName " + cacheServerMBeanName);
                    CacheServerMXBean bean = service.getMBeanProxy(cacheServerMBeanName, CacheServerMXBean.class);
                    getLogWriter().info("waitForMixedClients 2 bean " + bean);
                    if (bean.getClientIds().length > 1) {
                        return true;
                    }
                }
            } catch (Exception e) {
                LogWrapper.getInstance().warning("waitForMixedClients Exception in waitForMbean ::: " + CliUtil.stackTraceAsString(e));
            }
            return false;
        });
    });
}
Also used : VM(org.apache.geode.test.dunit.VM) DistributedMember(org.apache.geode.distributed.DistributedMember) CacheServerMXBean(org.apache.geode.management.CacheServerMXBean) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) ObjectName(javax.management.ObjectName)

Aggregations

CacheServerMXBean (org.apache.geode.management.CacheServerMXBean)19 ObjectName (javax.management.ObjectName)18 SystemManagementService (org.apache.geode.management.internal.SystemManagementService)15 DistributedMember (org.apache.geode.distributed.DistributedMember)14 VM (org.apache.geode.test.dunit.VM)13 CompositeResultData (org.apache.geode.management.internal.cli.result.CompositeResultData)5 SectionResultData (org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)5 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)4 InternalCache (org.apache.geode.internal.cache.InternalCache)3 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)3 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)3 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Entry (java.util.Map.Entry)2 ClientHealthStatus (org.apache.geode.management.ClientHealthStatus)2 ManagementService (org.apache.geode.management.ManagementService)2 CliMetaData (org.apache.geode.management.cli.CliMetaData)2 Result (org.apache.geode.management.cli.Result)2