Search in sources :

Example 1 with RegionMXBean

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

the class DistributedSystemBridge method fetchRegionObjectName.

public ObjectName fetchRegionObjectName(String member, String regionPath) throws Exception {
    validateMember(member);
    ObjectName distributedRegionMBeanName = MBeanJMXAdapter.getDistributedRegionMbeanName(regionPath);
    if (distrRegionMap.get(distributedRegionMBeanName) != null) {
        ObjectName regionMBeanName = MBeanJMXAdapter.getRegionMBeanName(member, regionPath);
        RegionMXBean bean = service.getMBeanInstance(regionMBeanName, RegionMXBean.class);
        if (bean != null) {
            return regionMBeanName;
        } else {
            throw new Exception(ManagementStrings.REGION_MBEAN_NOT_FOUND_IN_DS.toString());
        }
    } else {
        throw new Exception(ManagementStrings.REGION_MBEAN_NOT_FOUND_IN_DS.toString());
    }
}
Also used : DistributedRegionMXBean(org.apache.geode.management.DistributedRegionMXBean) RegionMXBean(org.apache.geode.management.RegionMXBean) ManagementException(org.apache.geode.management.ManagementException) ListenerNotFoundException(javax.management.ListenerNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ObjectName(javax.management.ObjectName)

Example 2 with RegionMXBean

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

the class ManagementAdapter method handleRegionCreation.

/**
   * Handles Region Creation. This is the call back which will create the specified RegionMXBean and
   * will send a notification on behalf of Member Mbean
   * 
   * @param region the region for which the call back is invoked
   */
public <K, V> void handleRegionCreation(Region<K, V> region) throws ManagementException {
    if (!isServiceInitialised("handleRegionCreation")) {
        return;
    }
    synchronized (regionOpLock) {
        LocalRegion localRegion = (LocalRegion) region;
        if (localRegion.isDestroyed()) {
            return;
        }
        // Bridge is responsible for extracting data from GemFire Layer
        RegionMBeanBridge<K, V> bridge = RegionMBeanBridge.getInstance(region);
        RegionMXBean regionMBean = new RegionMBean<>(bridge);
        ObjectName regionMBeanName = MBeanJMXAdapter.getRegionMBeanName(internalCache.getDistributedSystem().getDistributedMember(), region.getFullPath());
        ObjectName changedMBeanName = service.registerInternalMBean(regionMBean, regionMBeanName);
        service.federate(changedMBeanName, RegionMXBean.class, true);
        Notification notification = new Notification(JMXNotificationType.REGION_CREATED, memberSource, SequenceNumber.next(), System.currentTimeMillis(), ManagementConstants.REGION_CREATED_PREFIX + region.getFullPath());
        memberLevelNotifEmitter.sendNotification(notification);
        memberMBeanBridge.addRegion(region);
    }
}
Also used : RegionMXBean(org.apache.geode.management.RegionMXBean) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName)

Example 3 with RegionMXBean

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

the class MiscellaneousCommands method getRegionMetricsFromMember.

/**
   * Gets the metrics of region on a given member
   *
   * @return ResultData with required Region statistics or ErrorResultData if Region MBean is not
   *         found to gather metrics
   * @throws ResultDataException if building result fails
   */
private ResultData getRegionMetricsFromMember(String regionName, DistributedMember distributedMember, String export_to_report_to, String[] categoriesArr) throws ResultDataException {
    final InternalCache cache = getCache();
    final SystemManagementService managementService = (SystemManagementService) ManagementService.getManagementService(cache);
    ObjectName regionMBeanName = managementService.getRegionMBeanName(distributedMember, regionName);
    RegionMXBean regionMxBean = managementService.getMBeanInstance(regionMBeanName, RegionMXBean.class);
    if (regionMxBean != null) {
        CompositeResultData crd = ResultBuilder.createCompositeResultData();
        SectionResultData section = crd.addSection();
        TabularResultData metricsTable = section.addTable();
        metricsTable.setHeader("Metrics for region:" + regionName + " On Member " + MBeanJMXAdapter.getMemberNameOrId(distributedMember));
        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');
        }
        /*
       * Region Metrics
       */
        Map<String, Boolean> categoriesMap = getRegionMetricsCategories();
        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());
            }
        }
        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, "", "configuredRedundancy", regionMxBean.getConfiguredRedundancy(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "actualRedundancy", regionMxBean.getActualRedundancy(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "numBucketsWithoutRedundancy", regionMxBean.getNumBucketsWithoutRedundancy(), csvBuilder);
            writeToTableAndCsv(metricsTable, "", "totalBucketSize", regionMxBean.getTotalBucketSize(), 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(), "Region Metrics exported to {0}.", false);
        }
        return crd;
    } else {
        ErrorResultData erd = ResultBuilder.createErrorResultData();
        String errorMessage = CliStrings.format(CliStrings.SHOW_METRICS__ERROR, "Region MBean for " + regionName + " on member " + MBeanJMXAdapter.getMemberNameOrId(distributedMember) + " not found");
        erd.addLine(errorMessage);
        return erd;
    }
}
Also used : DistributedRegionMXBean(org.apache.geode.management.DistributedRegionMXBean) RegionMXBean(org.apache.geode.management.RegionMXBean) 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) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) ObjectName(javax.management.ObjectName) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) ErrorResultData(org.apache.geode.management.internal.cli.result.ErrorResultData) HashSet(java.util.HashSet)

Example 4 with RegionMXBean

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

the class CreateAlterDestroyRegionCommands method isClusterWideSameConfig.

private static boolean isClusterWideSameConfig(InternalCache cache, String regionPath) {
    ManagementService managementService = ManagementService.getExistingManagementService(cache);
    DistributedSystemMXBean dsMXBean = managementService.getDistributedSystemMXBean();
    Set<DistributedMember> allMembers = CliUtil.getAllNormalMembers(cache);
    RegionAttributesData regionAttributesToValidateAgainst = null;
    for (DistributedMember distributedMember : allMembers) {
        ObjectName regionObjectName;
        try {
            regionObjectName = dsMXBean.fetchRegionObjectName(CliUtil.getMemberNameOrId(distributedMember), regionPath);
            RegionMXBean regionMBean = managementService.getMBeanInstance(regionObjectName, RegionMXBean.class);
            RegionAttributesData regionAttributes = regionMBean.listRegionAttributes();
            if (regionAttributesToValidateAgainst == null) {
                regionAttributesToValidateAgainst = regionAttributes;
            } else if (!(regionAttributesToValidateAgainst.getScope().equals(regionAttributes.getScope()) || regionAttributesToValidateAgainst.getDataPolicy().equals(regionAttributes.getDataPolicy()))) {
                return false;
            }
        } catch (Exception e) {
        // ignore
        }
    }
    return true;
}
Also used : DistributedSystemMXBean(org.apache.geode.management.DistributedSystemMXBean) ManagementService(org.apache.geode.management.ManagementService) RegionAttributesData(org.apache.geode.management.RegionAttributesData) DistributedRegionMXBean(org.apache.geode.management.DistributedRegionMXBean) RegionMXBean(org.apache.geode.management.RegionMXBean) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) MalformedObjectNameException(javax.management.MalformedObjectNameException) ObjectName(javax.management.ObjectName)

Example 5 with RegionMXBean

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

the class CreateAlterDestroyRegionCommands method findMembersForRegion.

private Set<DistributedMember> findMembersForRegion(InternalCache cache, ManagementService managementService, String regionPath) {
    Set<DistributedMember> membersList = new HashSet<>();
    Set<String> regionMemberIds = new HashSet<>();
    MBeanServer mbeanServer = MBeanJMXAdapter.mbeanServer;
    // needs to be escaped with quotes if it contains a hyphen
    if (regionPath.contains("-")) {
        regionPath = "\"" + regionPath + "\"";
    }
    String queryExp = MessageFormat.format(MBeanJMXAdapter.OBJECTNAME__REGION_MXBEAN, regionPath, "*");
    try {
        ObjectName queryExpON = new ObjectName(queryExp);
        Set<ObjectName> queryNames = mbeanServer.queryNames(null, queryExpON);
        if (queryNames == null || queryNames.isEmpty()) {
            // protects against null pointer exception below
            return membersList;
        }
        boolean addedOneRemote = false;
        for (ObjectName regionMBeanObjectName : queryNames) {
            try {
                RegionMXBean regionMXBean = managementService.getMBeanInstance(regionMBeanObjectName, RegionMXBean.class);
                if (regionMXBean != null) {
                    RegionAttributesData regionAttributes = regionMXBean.listRegionAttributes();
                    String scope = regionAttributes.getScope();
                    // propagated.
                    if (Scope.LOCAL.equals(Scope.fromString(scope))) {
                        regionMemberIds.add(regionMXBean.getMember());
                    } else {
                        if (!addedOneRemote) {
                            regionMemberIds.add(regionMXBean.getMember());
                            addedOneRemote = true;
                        }
                    }
                }
            } catch (ClassCastException e) {
                LogWriter logger = cache.getLogger();
                if (logger.finerEnabled()) {
                    logger.finer(regionMBeanObjectName + " is not a " + RegionMXBean.class.getSimpleName(), e);
                }
            }
        }
        if (!regionMemberIds.isEmpty()) {
            membersList = getMembersByIds(cache, regionMemberIds);
        }
    } catch (MalformedObjectNameException | NullPointerException e) {
        LogWrapper.getInstance().info(e.getMessage(), e);
    }
    return membersList;
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) DistributedRegionMXBean(org.apache.geode.management.DistributedRegionMXBean) RegionMXBean(org.apache.geode.management.RegionMXBean) RegionAttributesData(org.apache.geode.management.RegionAttributesData) ObjectName(javax.management.ObjectName) LogWriter(org.apache.geode.LogWriter) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) HashSet(java.util.HashSet) MBeanServer(javax.management.MBeanServer)

Aggregations

RegionMXBean (org.apache.geode.management.RegionMXBean)9 DistributedRegionMXBean (org.apache.geode.management.DistributedRegionMXBean)7 ObjectName (javax.management.ObjectName)6 ManagementService (org.apache.geode.management.ManagementService)3 HashSet (java.util.HashSet)2 MalformedObjectNameException (javax.management.MalformedObjectNameException)2 DistributedMember (org.apache.geode.distributed.DistributedMember)2 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)2 RegionAttributesData (org.apache.geode.management.RegionAttributesData)2 TreeSet (java.util.TreeSet)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 ListenerNotFoundException (javax.management.ListenerNotFoundException)1 MBeanServer (javax.management.MBeanServer)1 Notification (javax.management.Notification)1 LogWriter (org.apache.geode.LogWriter)1 Cache (org.apache.geode.cache.Cache)1 Region (org.apache.geode.cache.Region)1 RegionFactory (org.apache.geode.cache.RegionFactory)1 InternalCache (org.apache.geode.internal.cache.InternalCache)1 LocalRegion (org.apache.geode.internal.cache.LocalRegion)1