use of org.apache.geode.management.ManagementService 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;
}
}
use of org.apache.geode.management.ManagementService in project geode by apache.
the class DiskStoreCommands method diskStoreExists.
private boolean diskStoreExists(String diskStoreName) {
InternalCache cache = getCache();
ManagementService managementService = ManagementService.getExistingManagementService(cache);
DistributedSystemMXBean dsMXBean = managementService.getDistributedSystemMXBean();
Map<String, String[]> diskstore = dsMXBean.listMemberDiskstore();
Set<Entry<String, String[]>> entrySet = diskstore.entrySet();
for (Entry<String, String[]> entry : entrySet) {
String[] value = entry.getValue();
if (CliUtil.contains(value, diskStoreName)) {
return true;
}
}
return false;
}
use of org.apache.geode.management.ManagementService in project geode by apache.
the class TestRemoteClusterDUnitTest method checkSenderMBean.
/**
* Checks whether a GatewayReceiverMBean is created or not
*
* @param vm reference to VM
*/
@SuppressWarnings("serial")
protected void checkSenderMBean(final VM vm, final String regionPath) {
SerializableRunnable checkMBean = new SerializableRunnable("Check Sender MBean") {
public void run() {
Cache cache = GemFireCacheImpl.getInstance();
ManagementService service = ManagementService.getManagementService(cache);
GatewaySenderMXBean bean = service.getLocalGatewaySenderMXBean("pn");
assertNotNull(bean);
assertTrue(bean.isConnected());
ObjectName regionBeanName = service.getRegionMBeanName(cache.getDistributedSystem().getDistributedMember(), "/" + regionPath);
RegionMXBean rBean = service.getMBeanInstance(regionBeanName, RegionMXBean.class);
assertTrue(rBean.isGatewayEnabled());
}
};
vm.invoke(checkMBean);
}
use of org.apache.geode.management.ManagementService in project geode by apache.
the class TestRemoteClusterDUnitTest method checkRemoteClusterStatus.
/**
* Checks Proxy GatewaySender
*
* @param vm reference to VM
*/
@SuppressWarnings("serial")
protected void checkRemoteClusterStatus(final VM vm, final DistributedMember senderMember) {
SerializableRunnable checkProxySender = new SerializableRunnable("DS Map Size") {
public void run() {
Cache cache = GemFireCacheImpl.getInstance();
final WaitCriterion waitCriteria2 = new WaitCriterion() {
@Override
public boolean done() {
Cache cache = GemFireCacheImpl.getInstance();
final ManagementService service = ManagementService.getManagementService(cache);
final DistributedSystemMXBean dsBean = service.getDistributedSystemMXBean();
if (dsBean != null) {
return true;
}
return false;
}
@Override
public String description() {
return "wait for getDistributedSystemMXBean to complete and get results";
}
};
Wait.waitForCriterion(waitCriteria2, 2 * 60 * 1000, 5000, true);
ManagementService service = ManagementService.getManagementService(cache);
final DistributedSystemMXBean dsBean = service.getDistributedSystemMXBean();
assertNotNull(dsBean);
Map<String, Boolean> dsMap = dsBean.viewRemoteClusterStatus();
LogWriterUtils.getLogWriter().info("Ds Map is: " + dsMap.size());
assertNotNull(dsMap);
assertEquals(true, dsMap.size() > 0 ? true : false);
}
};
vm.invoke(checkProxySender);
}
use of org.apache.geode.management.ManagementService in project geode by apache.
the class TestRemoteClusterDUnitTest method startGatewaySender.
/**
* start a gateway sender
*
* @param vm reference to VM
*/
@SuppressWarnings("serial")
protected void startGatewaySender(final VM vm) {
SerializableRunnable stopGatewaySender = new SerializableRunnable("Start Gateway Sender") {
public void run() {
Cache cache = GemFireCacheImpl.getInstance();
ManagementService service = ManagementService.getManagementService(cache);
GatewaySenderMXBean bean = service.getLocalGatewaySenderMXBean("pn");
assertNotNull(bean);
bean.start();
assertTrue(bean.isRunning());
}
};
vm.invoke(stopGatewaySender);
}
Aggregations