private ResultModel getMemberMetrics(DistributedMember distributedMember,
      String export_to_report_to, String[] categoriesArr, int cacheServerPort,
      StringBuilder csvBuilder) {
    final SystemManagementService managementService = getManagementService();

    ObjectName memberMBeanName = managementService.getMemberMBeanName(distributedMember);
    MemberMXBean memberMxBean =
        managementService.getMBeanInstance(memberMBeanName, MemberMXBean.class);
    ObjectName csMxBeanName;
    CacheServerMXBean csMxBean = null;

    if (memberMxBean == null) {
      String errorMessage = CliStrings.format(CliStrings.SHOW_METRICS__ERROR, "Member MBean for "
          + MBeanJMXAdapter.getMemberNameOrUniqueId(distributedMember) + " not found");
      return ResultModel.createError(errorMessage);
    }

    if (cacheServerPort != -1) {
      csMxBeanName = managementService.getCacheServerMBeanName(cacheServerPort, distributedMember);
      csMxBean = managementService.getMBeanInstance(csMxBeanName, CacheServerMXBean.class);

      if (csMxBean == null) {
        return ResultModel.createError(
            CliStrings.format(CliStrings.SHOW_METRICS__CACHE__SERVER__NOT__FOUND,
                cacheServerPort, MBeanJMXAdapter.getMemberNameOrUniqueId(distributedMember)));
      }
    }

    JVMMetrics jvmMetrics = memberMxBean.showJVMMetrics();

    ResultModel result = new ResultModel();
    TabularResultModel metricsTable = result.addTable("member-metrics");
    metricsTable.setHeader("Member Metrics");

    List<Category> fullCategories =
        csMxBean != null ? MEMBER_WITH_PORT_METRIC_CATEGORIES : MEMBER_METRIC_CATEGORIES;
    Set<Category> categoriesToDisplay = ArrayUtils.isNotEmpty(categoriesArr)
        ? getCategorySet(categoriesArr) : new HashSet<>(fullCategories);

    writeMemberMetricValues(memberMxBean, jvmMetrics, metricsTable, csvBuilder,
        categoriesToDisplay);
    if (csMxBean != null) {
      writeCacheServerMetricValues(csMxBean, metricsTable, csvBuilder, categoriesToDisplay);
    }

    if (StringUtils.isNotEmpty(export_to_report_to)) {
      result.addFile(export_to_report_to, csvBuilder != null ? csvBuilder.toString() : null);
    }

    return result;
  }
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
geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/ShowMetricsCommand.java