Search in sources :

Example 21 with ErrorResultData

use of org.apache.geode.management.internal.cli.result.ErrorResultData in project geode by apache.

the class MiscellaneousCommands method getDistributedRegionMetrics.

/**
   * Gets the Cluster-wide metrics for a region
   *
   * @return ResultData containing the table
   * @throws ResultDataException if building result fails
   */
private ResultData getDistributedRegionMetrics(String regionName, String export_to_report_to, String[] categoriesArr) throws ResultDataException {
    final InternalCache cache = getCache();
    final ManagementService managementService = ManagementService.getManagementService(cache);
    DistributedRegionMXBean regionMxBean = managementService.getDistributedRegionMXBean(regionName);
    if (regionMxBean != null) {
        CompositeResultData crd = ResultBuilder.createCompositeResultData();
        SectionResultData section = crd.addSection();
        TabularResultData metricsTable = section.addTable();
        metricsTable.setHeader("Cluster-wide Region 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 = getSystemRegionMetricsCategories();
        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());
            }
        }
        // cluster, region, partition , diskstore, callback, eviction
        if (categoriesMap.get("cluster").booleanValue()) {
            writeToTableAndCsv(metricsTable, "cluster", "member count", regionMxBean.getMemberCount(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "region entry count", regionMxBean.getSystemRegionEntryCount(), csvBuilder);
        }
        if (categoriesMap.get("region").booleanValue()) {
            writeToTableAndCsv(metricsTable, "region", "lastModifiedTime", regionMxBean.getLastModifiedTime(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "lastAccessedTime", regionMxBean.getLastAccessedTime(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "missCount", regionMxBean.getMissCount(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "hitCount", regionMxBean.getHitCount(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "hitRatio", regionMxBean.getHitRatio(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "getsRate", regionMxBean.getGetsRate(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "putsRate", regionMxBean.getPutsRate(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "createsRate", regionMxBean.getCreatesRate(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "destroyRate", regionMxBean.getDestroyRate(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "putAllRate", regionMxBean.getPutAllRate(), csvBuilder);
        }
        if (categoriesMap.get("partition").booleanValue()) {
            writeToTableAndCsv(metricsTable, "partition", "putLocalRate", regionMxBean.getPutLocalRate(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "putRemoteRate", regionMxBean.getPutRemoteRate(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "putRemoteLatency", regionMxBean.getPutRemoteLatency(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "putRemoteAvgLatency", regionMxBean.getPutRemoteAvgLatency(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "bucketCount", regionMxBean.getBucketCount(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "primaryBucketCount", regionMxBean.getPrimaryBucketCount(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "numBucketsWithoutRedundancy", regionMxBean.getNumBucketsWithoutRedundancy(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "totalBucketSize", regionMxBean.getTotalBucketSize(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "averageBucketSize", regionMxBean.getAvgBucketSize(), csvBuilder);
        }
        /*
       * Disk store
       */
        if (categoriesMap.get("diskstore").booleanValue()) {
            writeToTableAndCsv(metricsTable, "diskstore", "totalEntriesOnlyOnDisk", regionMxBean.getTotalEntriesOnlyOnDisk(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "diskReadsRate", regionMxBean.getDiskReadsRate(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "diskWritesRate", regionMxBean.getDiskWritesRate(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "totalDiskWriteInProgress", regionMxBean.getTotalDiskWritesProgress(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "diskTaskWaiting", regionMxBean.getDiskTaskWaiting(), csvBuilder);
        }
        /*
       * LISTENER
       */
        if (categoriesMap.get("callback").booleanValue()) {
            writeToTableAndCsv(metricsTable, "callback", "cacheWriterCallsAvgLatency", regionMxBean.getCacheWriterCallsAvgLatency(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "cacheListenerCallsAvgLatency", regionMxBean.getCacheListenerCallsAvgLatency(), csvBuilder);
        }
        /*
       * Eviction
       */
        if (categoriesMap.get("eviction").booleanValue()) {
            writeToTableAndCsv(metricsTable, "eviction", "lruEvictionRate", regionMxBean.getLruEvictionRate(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "lruDestroyRate", regionMxBean.getLruDestroyRate(), csvBuilder);
        }
        if (export_to_report_to != null && !export_to_report_to.isEmpty()) {
            crd.addAsFile(export_to_report_to, csvBuilder.toString(), "Aggregate Region Metrics exported to {0}.", false);
        }
        return crd;
    } else {
        ErrorResultData erd = ResultBuilder.createErrorResultData();
        String errorMessage = CliStrings.format(CliStrings.SHOW_METRICS__ERROR, "Distributed Region MBean for " + regionName + " not found");
        erd.addLine(errorMessage);
        return erd;
    }
}
Also used : 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) DistributedRegionMXBean(org.apache.geode.management.DistributedRegionMXBean) ManagementService(org.apache.geode.management.ManagementService) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) ErrorResultData(org.apache.geode.management.internal.cli.result.ErrorResultData) HashSet(java.util.HashSet)

Example 22 with ErrorResultData

use of org.apache.geode.management.internal.cli.result.ErrorResultData in project geode by apache.

the class MiscellaneousCommands method showLog.

@CliCommand(value = CliStrings.SHOW_LOG, help = CliStrings.SHOW_LOG_HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEODE_DEBUG_UTIL })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result showLog(@CliOption(key = CliStrings.SHOW_LOG_MEMBER, optionContext = ConverterHint.ALL_MEMBER_IDNAME, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.SHOW_LOG_MEMBER_HELP, mandatory = true) String memberNameOrId, @CliOption(key = CliStrings.SHOW_LOG_LINE_NUM, unspecifiedDefaultValue = "0", help = CliStrings.SHOW_LOG_LINE_NUM_HELP, mandatory = false) int numberOfLines) {
    Result result = null;
    try {
        InternalCache cache = getCache();
        SystemManagementService service = (SystemManagementService) ManagementService.getExistingManagementService(cache);
        MemberMXBean bean = null;
        DistributedMember memberToBeInvoked = CliUtil.getDistributedMemberByNameOrId(memberNameOrId);
        if (memberToBeInvoked != null) {
            String memberId = memberToBeInvoked.getId();
            if (cache.getDistributedSystem().getDistributedMember().getId().equals(memberId)) {
                bean = service.getMemberMXBean();
            } else {
                ObjectName objectName = service.getMemberMBeanName(memberToBeInvoked);
                bean = service.getMBeanProxy(objectName, MemberMXBean.class);
            }
            if (numberOfLines > ManagementConstants.MAX_SHOW_LOG_LINES) {
                numberOfLines = ManagementConstants.MAX_SHOW_LOG_LINES;
            }
            if (numberOfLines == 0 || numberOfLines < 0) {
                numberOfLines = ManagementConstants.DEFAULT_SHOW_LOG_LINES;
            }
            InfoResultData resultData = ResultBuilder.createInfoResultData();
            if (bean != null) {
                String log = bean.showLog(numberOfLines);
                if (log != null) {
                    resultData.addLine(log);
                } else {
                    resultData.addLine(CliStrings.SHOW_LOG_NO_LOG);
                }
            } else {
                ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(memberNameOrId + CliStrings.SHOW_LOG_MSG_MEMBER_NOT_FOUND);
                return (ResultBuilder.buildResult(errorResultData));
            }
            result = ResultBuilder.buildResult(resultData);
        } else {
            ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(memberNameOrId + CliStrings.SHOW_LOG_MSG_MEMBER_NOT_FOUND);
            return (ResultBuilder.buildResult(errorResultData));
        }
    } catch (Exception e) {
        result = ResultBuilder.createGemFireErrorResult(CliStrings.SHOW_LOG_ERROR + CliUtil.stackTraceAsString(e));
    }
    return result;
}
Also used : InfoResultData(org.apache.geode.management.internal.cli.result.InfoResultData) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) ErrorResultData(org.apache.geode.management.internal.cli.result.ErrorResultData) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) TimeoutException(java.util.concurrent.TimeoutException) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) ResultDataException(org.apache.geode.management.internal.cli.result.ResultDataException) FunctionException(org.apache.geode.cache.execute.FunctionException) DataFormatException(java.util.zip.DataFormatException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) GfshParseResult(org.apache.geode.management.internal.cli.GfshParseResult) Result(org.apache.geode.management.cli.Result) NetstatFunctionResult(org.apache.geode.management.internal.cli.functions.NetstatFunction.NetstatFunctionResult) MemberMXBean(org.apache.geode.management.MemberMXBean) ObjectName(javax.management.ObjectName) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 23 with ErrorResultData

use of org.apache.geode.management.internal.cli.result.ErrorResultData in project geode by apache.

the class DurableClientCommands method buildTableResultForQueueSize.

private Result buildTableResultForQueueSize(List<SubscriptionQueueSizeResult> results, String queueSizeColumnName) {
    Result result = null;
    boolean failure = true;
    Map<String, List<String>> failureMap = new HashMap<String, List<String>>();
    Map<String, Long> memberQueueSizeTable = new TreeMap<String, Long>();
    /***
     * Aggregate the results from the members
     */
    for (SubscriptionQueueSizeResult memberResult : results) {
        if (memberResult.isSuccessful()) {
            failure = false;
            memberResult.getSubscriptionQueueSize();
            memberQueueSizeTable.put(memberResult.getMemberNameOrId(), memberResult.getSubscriptionQueueSize());
        } else {
            groupByMessage(memberResult.getErrorMessage(), memberResult.getMemberNameOrId(), failureMap);
        }
    }
    if (!failure) {
        TabularResultData table = ResultBuilder.createTabularResultData();
        Set<String> members = memberQueueSizeTable.keySet();
        for (String member : members) {
            long queueSize = memberQueueSizeTable.get(member);
            table.accumulate(CliStrings.COUNT_DURABLE_CQ_EVENTS__MEMBER, member);
            table.accumulate(queueSizeColumnName, queueSize);
        }
        result = ResultBuilder.buildResult(table);
    } else {
        ErrorResultData erd = ResultBuilder.createErrorResultData();
        buildErrorResult(erd, failureMap);
        result = ResultBuilder.buildResult(erd);
    }
    return result;
}
Also used : TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) SubscriptionQueueSizeResult(org.apache.geode.management.internal.cli.domain.SubscriptionQueueSizeResult) DurableCqNamesResult(org.apache.geode.management.internal.cli.domain.DurableCqNamesResult) Result(org.apache.geode.management.cli.Result) MemberResult(org.apache.geode.management.internal.cli.domain.MemberResult) LinkedList(java.util.LinkedList) List(java.util.List) ErrorResultData(org.apache.geode.management.internal.cli.result.ErrorResultData) SubscriptionQueueSizeResult(org.apache.geode.management.internal.cli.domain.SubscriptionQueueSizeResult)

Aggregations

ErrorResultData (org.apache.geode.management.internal.cli.result.ErrorResultData)23 Result (org.apache.geode.management.cli.Result)14 CliMetaData (org.apache.geode.management.cli.CliMetaData)13 CliCommand (org.springframework.shell.core.annotation.CliCommand)13 DistributedMember (org.apache.geode.distributed.DistributedMember)11 InternalCache (org.apache.geode.internal.cache.InternalCache)10 HashSet (java.util.HashSet)9 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)8 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)8 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 List (java.util.List)7 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)7 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)7 ConverterHint (org.apache.geode.management.cli.ConverterHint)6 GfshParseResult (org.apache.geode.management.internal.cli.GfshParseResult)6 CompositeResultData (org.apache.geode.management.internal.cli.result.CompositeResultData)6 InfoResultData (org.apache.geode.management.internal.cli.result.InfoResultData)6 HashMap (java.util.HashMap)5 FunctionException (org.apache.geode.cache.execute.FunctionException)5