List of usage examples for javax.management.openmbean TabularData values
public Collection<?> values();
From source file:io.hawt.osgi.jmx.RBACDecorator.java
/** * If we have access to {@link ConfigurationAdmin}, we can add RBAC information * @param result// w w w . j a va2 s . c o m */ @Override @SuppressWarnings("unchecked") public void decorate(Map<String, Object> result) throws Exception { try { ServiceReference<ConfigurationAdmin> cmRef = bundleContext .getServiceReference(ConfigurationAdmin.class); ServiceReference<JMXSecurityMBean> jmxSecRef = bundleContext .getServiceReference(JMXSecurityMBean.class); if (cmRef != null && jmxSecRef != null) { ConfigurationAdmin configAdmin = bundleContext.getService(cmRef); JMXSecurityMBean jmxSec = bundleContext.getService(jmxSecRef); if (configAdmin != null && jmxSec != null) { // 1. each pair of MBean/operation has to be marked with RBAC flag (can/can't invoke) // 2. the information is provided by org.apache.karaf.management.JMXSecurityMBean.canInvoke(java.util.Map) // 3. we'll peek into available configadmin jmx.acl* configs, to see which MBeans/operations have to // be examined and which will produce same results // 4. only then we'll prepare Map as parameter for canInvoke() Configuration[] configurations = configAdmin.listConfigurations("(service.pid=jmx.acl*)"); List<String> allJmxAclPids = new LinkedList<>(); for (Configuration cfg : configurations) { allJmxAclPids.add(cfg.getPid()); } if (allJmxAclPids.size() == 0) { return; } Map<String, Map<String, Object>> domains = (Map<String, Map<String, Object>>) result .get("domains"); // cache contains MBeanInfos for different MBeans/ObjectNames Map<String, Map<String, Object>> cache = (Map<String, Map<String, Object>>) result.get("cache"); // new cache will contain MBeanInfos + RBAC info Map<String, Map<String, Object>> rbacCache = new HashMap<>(); // the fact that some MBeans share JSON MBeanInfo doesn't mean that they can share RBAC info // - each MBean's name may have RBAC information configured in different PIDs. // when iterating through all reapeating MBeans that share MBeanInfo (that doesn't have RBAC info // yet), we have to decide if it'll use shared info after RBAC check or will switch to dedicated // info. we have to be careful not to end with most MBeans *not* sharing MBeanInfo (in case if // somehow the shared info will be "special case" from RBAC point of view) Map<String, List<String>> queryForMBeans = new HashMap<>(); Map<String, List<String>> queryForMBeanOperations = new HashMap<>(); for (String domain : domains.keySet()) { Map<String, Object> domainMBeansCheck = new HashMap<>(domains.get(domain)); Map<String, Object> domainMBeans = domains.get(domain); for (String name : domainMBeansCheck.keySet()) { Object mBeanInfo = domainMBeansCheck.get(name); String fullName = domain + ":" + name; ObjectName n = new ObjectName(fullName); if (mBeanInfo instanceof Map) { // not shared JSONified MBeanInfo prepareKarafRbacInvocations(fullName, (Map<String, Object>) mBeanInfo, queryForMBeans, queryForMBeanOperations); } else /*if (mBeanInfo instanceof String)*/ { // shared JSONified MBeanInfo // shard mbeanNames sharing MBeanInfo by the hierarchy of jmx.acl* PIDs used to // check RBAC info String key = (String) mBeanInfo; String pidListKey = pidListKey(allJmxAclPids, n); if (!rbacCache.containsKey(key + ":" + pidListKey)) { // shallow copy - we can share op/not/attr/desc, but we put specific // canInvoke/opByString keys HashMap<String, Object> sharedMBeanAndRbacInfo = new HashMap<>(cache.get(key)); rbacCache.put(key + ":" + pidListKey, sharedMBeanAndRbacInfo); // we'll be checking RBAC only for single (first) MBean having this pidListKey prepareKarafRbacInvocations(fullName, sharedMBeanAndRbacInfo, queryForMBeans, queryForMBeanOperations); } // switch key from shared MBeanInfo-only to shared MBean+RbacInfo domainMBeans.put(name, key + ":" + pidListKey); } } } // RBAC per MBeans (can invoke *any* operation or attribute?) TabularData dataForMBeans = jmxSec.canInvoke(queryForMBeans); Collection<?> results = dataForMBeans.values(); for (Object cd : results) { ObjectName objectName = new ObjectName((String) ((CompositeData) cd).get("ObjectName")); boolean canInvoke = ((CompositeData) cd).get("CanInvoke") != null ? (Boolean) ((CompositeData) cd).get("CanInvoke") : false; Object mBeanInfoOrKey = domains.get(objectName.getDomain()) .get(objectName.getKeyPropertyListString()); Map<String, Object> mBeanInfo; if (mBeanInfoOrKey instanceof Map) { mBeanInfo = (Map<String, Object>) mBeanInfoOrKey; } else /*if (mBeanInfoOrKey instanceof String) */ { mBeanInfo = rbacCache.get(mBeanInfoOrKey.toString()); } if (mBeanInfo != null) { mBeanInfo.put("canInvoke", canInvoke); } } // RBAC per { MBean,operation } (can invoke status for each operation) TabularData dataForMBeanOperations = jmxSec.canInvoke(queryForMBeanOperations); results = dataForMBeanOperations.values(); for (Object cd : results) { ObjectName objectName = new ObjectName((String) ((CompositeData) cd).get("ObjectName")); String method = (String) ((CompositeData) cd).get("Method"); boolean canInvoke = ((CompositeData) cd).get("CanInvoke") != null ? (Boolean) ((CompositeData) cd).get("CanInvoke") : false; Object mBeanInfoOrKey = domains.get(objectName.getDomain()) .get(objectName.getKeyPropertyListString()); Map<String, Object> mBeanInfo; if (mBeanInfoOrKey instanceof Map) { mBeanInfo = (Map<String, Object>) mBeanInfoOrKey; } else /*if (mBeanInfoOrKey instanceof String) */ { mBeanInfo = rbacCache.get(mBeanInfoOrKey.toString()); } if (mBeanInfo != null) { ((Map<String, Object>) ((Map<String, Object>) mBeanInfo.get("opByString")).get(method)) .put("canInvoke", canInvoke); } } result.remove("cache"); result.put("cache", rbacCache); } } } catch (Exception e) { LOG.error(e.getMessage(), e); // simply do not decorate } }
From source file:dk.netarkivet.harvester.harvesting.controller.JMXHeritrixController.java
/** Check if the crawl has ended, either because Heritrix finished * of its own, or because we terminated it. * * @return True if the crawl has ended, either because Heritrix finished * or because we terminated it. Otherwise we return false. * @see HeritrixController#crawlIsEnded() *//*from ww w . jav a 2 s . c om*/ public synchronized boolean crawlIsEnded() { // End of crawl can be seen in one of three ways: // 1) The Heritrix process has exited. // 2) The job has been moved to the completed jobs list in Heritrix. // 3) The job is in one of the FINISHED states. if (processHasExited()) { return true; } TabularData jobs = (TabularData) executeHeritrixCommand(COMPLETED_JOBS_COMMAND); if (jobs != null && jobs.size() > 0) { for (CompositeData value : (Collection<CompositeData>) jobs.values()) { String thisJobID = value.get(JmxUtils.NAME) + "-" + value.get(UID_PROPERTY); if (thisJobID.equals(jobName)) { return true; } } } String status = (String) getCrawlJobAttribute(STATUS_ATTRIBUTE); return status == null || status.equals(FINISHED_STATUS) || status.equals(ILLEGAL_STATUS); }
From source file:org.jolokia.converter.json.TabularDataExtractor.java
private Object convertToMaps(TabularData pTd, Stack<String> pExtraArgs, ObjectToJsonConverter pConverter) throws AttributeNotFoundException { JSONObject ret = new JSONObject(); TabularType type = pTd.getTabularType(); List<String> indexNames = type.getIndexNames(); boolean found = false; for (CompositeData cd : (Collection<CompositeData>) pTd.values()) { Stack<String> path = (Stack<String>) pExtraArgs.clone(); try {/*from w ww .jav a2s .c o m*/ JSONObject targetJSONObject = ret; // TODO: Check whether all keys can be represented as simple types. If not, well // we dont do any magic and return the tabular data as an array. for (int i = 0; i < indexNames.size() - 1; i++) { Object indexValue = pConverter.extractObject(cd.get(indexNames.get(i)), null, true); targetJSONObject = getNextMap(targetJSONObject, indexValue); } Object row = pConverter.extractObject(cd, path, true); String finalIndex = indexNames.get(indexNames.size() - 1); Object finalIndexValue = pConverter.extractObject(cd.get(finalIndex), null, true); targetJSONObject.put(finalIndexValue, row); found = true; } catch (ValueFaultHandler.AttributeFilteredException exp) { // Ignoring filtered attributes } } if (!pTd.isEmpty() && !found) { throw new ValueFaultHandler.AttributeFilteredException(); } return ret; }
From source file:org.apache.qpid.systest.management.jmx.QueueManagementTest.java
private List<Long> getAMQMessageIdsOn(ManagedQueue managedQueue, long startIndex, long endIndex) throws Exception { final SortedSet<Long> messageIds = new TreeSet<Long>(); final TabularData tab = managedQueue.viewMessages(startIndex, endIndex); final Iterator<CompositeData> rowItr = (Iterator<CompositeData>) tab.values().iterator(); while (rowItr.hasNext()) { final CompositeData row = rowItr.next(); long amqMessageId = (Long) row.get(ManagedQueue.MSG_AMQ_ID); messageIds.add(amqMessageId);//from w w w . j a va2s. c om } return new ArrayList<Long>(messageIds); }
From source file:org.apache.qpid.systest.management.jmx.QueueManagementTest.java
/** * Tests {@link ManagedQueue#viewMessages(long, long)} interface. *///www .java 2 s . c o m public void testViewSingleMessage() throws Exception { final List<Message> sentMessages = sendMessage(_session, _sourceQueue, 1); syncSession(_session); final Message sentMessage = sentMessages.get(0); assertEquals("Unexpected queue depth", 1, _managedSourceQueue.getMessageCount().intValue()); // Check the contents of the message final TabularData tab = _managedSourceQueue.viewMessages(1l, 1l); assertEquals("Unexpected number of rows in table", 1, tab.size()); final Iterator<CompositeData> rowItr = (Iterator<CompositeData>) tab.values().iterator(); final CompositeData row1 = rowItr.next(); assertNotNull("Message should have AMQ message id", row1.get(ManagedQueue.MSG_AMQ_ID)); assertEquals("Unexpected queue position", 1l, row1.get(ManagedQueue.MSG_QUEUE_POS)); assertEquals("Unexpected redelivered flag", Boolean.FALSE, row1.get(ManagedQueue.MSG_REDELIVERED)); // Check the contents of header (encoded in a string array) final String[] headerArray = (String[]) row1.get(ManagedQueue.MSG_HEADER); assertNotNull("Expected message header array", headerArray); final Map<String, String> headers = headerArrayToMap(headerArray); final String expectedJMSMessageID = isBroker010() ? sentMessage.getJMSMessageID().replace("ID:", "") : sentMessage.getJMSMessageID(); final String expectedFormattedJMSTimestamp = FastDateFormat .getInstance(ManagedQueue.JMSTIMESTAMP_DATETIME_FORMAT).format(sentMessage.getJMSTimestamp()); assertEquals("Unexpected JMSMessageID within header", expectedJMSMessageID, headers.get("JMSMessageID")); assertEquals("Unexpected JMSPriority within header", String.valueOf(sentMessage.getJMSPriority()), headers.get("JMSPriority")); assertEquals("Unexpected JMSTimestamp within header", expectedFormattedJMSTimestamp, headers.get("JMSTimestamp")); }
From source file:org.jolokia.converter.json.TabularDataExtractor.java
private Object convertTabularDataDirectly(TabularData pTd, Stack<String> pExtraArgs, ObjectToJsonConverter pConverter) throws AttributeNotFoundException { if (!pExtraArgs.empty()) { throw new IllegalArgumentException("Cannot use a path for converting tabular data with complex keys (" + pTd.getTabularType().getRowType() + ")"); }/*www . jav a 2 s .c om*/ JSONObject ret = new JSONObject(); JSONArray indexNames = new JSONArray(); TabularType type = pTd.getTabularType(); for (String index : type.getIndexNames()) { indexNames.add(index); } ret.put("indexNames", indexNames); JSONArray values = new JSONArray(); // Here no special handling for wildcard pathes since pathes are not supported for this use case (yet) for (CompositeData cd : (Collection<CompositeData>) pTd.values()) { values.add(pConverter.extractObject(cd, pExtraArgs, true)); } ret.put("values", values); return ret; }
From source file:org.apache.geode.tools.pulse.internal.data.JMXDataUpdater.java
/** * function used to get attribute values of Cluster System and map them to cluster vo * // w w w . j a v a2s . c o m * @param mbeanName Cluster System MBean */ private void updateClusterSystem(ObjectName mbeanName) throws IOException { try { if (!this.isAddedNotiListner) { this.mbs.addNotificationListener(mbeanName, this, null, new Object()); this.isAddedNotiListner = true; } String[] serverCnt = (String[]) (this.mbs.invoke(mbeanName, PulseConstants.MBEAN_OPERATION_LISTSERVERS, null, null)); cluster.setServerCount(serverCnt.length); TabularData table = (TabularData) (this.mbs.invoke(mbeanName, PulseConstants.MBEAN_OPERATION_VIEWREMOTECLUSTERSTATUS, null, null)); Collection<CompositeData> rows = (Collection<CompositeData>) table.values(); cluster.getWanInformationObject().clear(); for (CompositeData row : rows) { final Object key = row.get("key"); final Object value = row.get("value"); cluster.getWanInformationObject().put((String) key, (Boolean) value); } AttributeList attributeList = this.mbs.getAttributes(mbeanName, PulseConstants.CLUSTER_MBEAN_ATTRIBUTES); for (int i = 0; i < attributeList.size(); i++) { Attribute attribute = (Attribute) attributeList.get(i); String name = attribute.getName(); switch (name) { case PulseConstants.MBEAN_ATTRIBUTE_MEMBERCOUNT: cluster.setMemberCount(getIntegerAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_NUMCLIENTS: cluster.setClientConnectionCount( getIntegerAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_DISTRIBUTEDSYSTEMID: cluster.setClusterId(getIntegerAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_LOCATORCOUNT: cluster.setLocatorCount(getIntegerAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_NUMRUNNIGFUNCTION: try { cluster.setRunningFunctionCount( getIntegerAttribute(attribute.getValue(), attribute.getName())); } catch (Exception e) { cluster.setRunningFunctionCount(0); continue; } break; case PulseConstants.MBEAN_ATTRIBUTE_REGISTEREDCQCOUNT: cluster.setRegisteredCQCount(getLongAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_NUMSUBSCRIPTIONS: cluster.setSubscriptionCount(getIntegerAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_NUMTXNCOMMITTED: cluster.setTxnCommittedCount(getIntegerAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_NUMTXNROLLBACK: cluster.setTxnRollbackCount(getIntegerAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_TOTALHEAPSIZE: cluster.setTotalHeapSize(getLongAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_USEDHEAPSIZE: try { cluster.setUsedHeapSize(getLongAttribute(attribute.getValue(), attribute.getName())); } catch (Exception e) { cluster.setUsedHeapSize((long) 0); continue; } cluster.getMemoryUsageTrend().add(cluster.getUsedHeapSize()); break; case PulseConstants.MBEAN_ATTRIBUTE_TOTALREGIONENTRYCOUNT: cluster.setTotalRegionEntryCount(getLongAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_CURRENTENTRYCOUNT: cluster.setCurrentQueryCount(getIntegerAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_TOTALDISKUSAGE: try { cluster.setTotalBytesOnDisk(getLongAttribute(attribute.getValue(), attribute.getName())); } catch (Exception e) { cluster.setTotalBytesOnDisk((long) 0); continue; } cluster.getTotalBytesOnDiskTrend().add(cluster.getTotalBytesOnDisk()); break; case PulseConstants.MBEAN_ATTRIBUTE_DISKWRITESRATE: cluster.setDiskWritesRate(getDoubleAttribute(attribute.getValue(), attribute.getName())); cluster.getThroughoutWritesTrend().add(cluster.getDiskWritesRate()); break; case PulseConstants.MBEAN_ATTRIBUTE_AVERAGEWRITES: try { cluster.setWritePerSec(getDoubleAttribute(attribute.getValue(), attribute.getName())); } catch (Exception e) { cluster.setWritePerSec(0); continue; } cluster.getWritePerSecTrend().add(cluster.getWritePerSec()); break; case PulseConstants.MBEAN_ATTRIBUTE_AVERAGEREADS: try { cluster.setReadPerSec(getDoubleAttribute(attribute.getValue(), attribute.getName())); } catch (Exception e) { cluster.setReadPerSec(0); continue; } cluster.getReadPerSecTrend().add(cluster.getReadPerSec()); break; case PulseConstants.MBEAN_ATTRIBUTE_QUERYREQUESTRATE: cluster.setQueriesPerSec(getDoubleAttribute(attribute.getValue(), attribute.getName())); cluster.getQueriesPerSecTrend().add(cluster.getQueriesPerSec()); break; case PulseConstants.MBEAN_ATTRIBUTE_DISKREADSRATE: cluster.setDiskReadsRate(getDoubleAttribute(attribute.getValue(), attribute.getName())); cluster.getThroughoutReadsTrend().add(cluster.getDiskReadsRate()); break; case PulseConstants.MBEAN_ATTRIBUTE_JVMPAUSES: long trendVal = determineCurrentJVMPauses(PulseConstants.JVM_PAUSES_TYPE_CLUSTER, "", getLongAttribute(attribute.getValue(), attribute.getName())); cluster.setGarbageCollectionCount(trendVal); cluster.getGarbageCollectionTrend().add(cluster.getGarbageCollectionCount()); break; case PulseConstants.MBEAN_ATTRIBUTE_TOTALREGIONCOUNT: cluster.setTotalRegionCount(getIntegerAttribute(attribute.getValue(), attribute.getName())); break; } } } catch (InstanceNotFoundException | ReflectionException | MBeanException infe) { logger.warn(infe); } }
From source file:com.pivotal.gemfire.tools.pulse.internal.data.JMXDataUpdater.java
/** * function used to get attribute values of Cluster System and map them to * cluster vo/*from ww w .ja va2s. c o m*/ * * @param mbeanName * Cluster System MBean * @throws IOException * */ private void updateClusterSystem(ObjectName mbeanName) throws IOException { try { if (!this.isAddedNotiListner) { this.mbs.addNotificationListener(mbeanName, this, null, new Object()); this.isAddedNotiListner = true; } if (PulseConstants.PRODUCT_NAME_GEMFIREXD.equalsIgnoreCase(PulseController.getPulseProductSupport())) { // Reset to zero cluster.setServerCount(0); cluster.setTotalRegionCount(0); } else { String[] serverCnt = (String[]) (this.mbs.invoke(mbeanName, PulseConstants.MBEAN_OPERATION_LISTCACHESERVER, null, null)); cluster.setServerCount(serverCnt.length); } TabularData table = (TabularData) (this.mbs.invoke(mbeanName, PulseConstants.MBEAN_OPERATION_VIEWREMOTECLUSTERSTATUS, null, null)); Collection<CompositeData> rows = (Collection<CompositeData>) table.values(); cluster.getWanInformationObject().clear(); for (CompositeData row : rows) { final Object key = row.get("key"); final Object value = row.get("value"); cluster.getWanInformationObject().put((String) key, (Boolean) value); } AttributeList attributeList = this.mbs.getAttributes(mbeanName, PulseConstants.CLUSTER_MBEAN_ATTRIBUTES); for (int i = 0; i < attributeList.size(); i++) { Attribute attribute = (Attribute) attributeList.get(i); if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_MEMBERCOUNT)) { cluster.setMemberCount(getIntegerAttribute(attribute.getValue(), attribute.getName())); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_NUMCLIENTS)) { cluster.setClientConnectionCount( getIntegerAttribute(attribute.getValue(), attribute.getName())); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_DISTRIBUTEDSYSTEMID)) { cluster.setClusterId(getIntegerAttribute(attribute.getValue(), attribute.getName())); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_LOCATORCOUNT)) { cluster.setLocatorCount(getIntegerAttribute(attribute.getValue(), attribute.getName())); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_NUMRUNNIGFUNCTION)) { try { cluster.setRunningFunctionCount( getIntegerAttribute(attribute.getValue(), attribute.getName())); } catch (Exception e) { cluster.setRunningFunctionCount(0); continue; } } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_REGISTEREDCQCOUNT)) { cluster.setRegisteredCQCount(getLongAttribute(attribute.getValue(), attribute.getName())); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_NUMSUBSCRIPTIONS)) { cluster.setSubscriptionCount(getIntegerAttribute(attribute.getValue(), attribute.getName())); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_NUMTXNCOMMITTED)) { cluster.setTxnCommittedCount(getIntegerAttribute(attribute.getValue(), attribute.getName())); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_NUMTXNROLLBACK)) { cluster.setTxnRollbackCount(getIntegerAttribute(attribute.getValue(), attribute.getName())); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_TOTALHEAPSIZE)) { cluster.setTotalHeapSize(getLongAttribute(attribute.getValue(), attribute.getName())); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_USEDHEAPSIZE)) { try { cluster.setUsedHeapSize(getLongAttribute(attribute.getValue(), attribute.getName())); } catch (Exception e) { cluster.setUsedHeapSize((long) 0); continue; } cluster.getMemoryUsageTrend().add(cluster.getUsedHeapSize()); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_TOTALREGIONENTRYCOUNT)) { cluster.setTotalRegionEntryCount(getLongAttribute(attribute.getValue(), attribute.getName())); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_CURRENTENTRYCOUNT)) { cluster.setCurrentQueryCount(getIntegerAttribute(attribute.getValue(), attribute.getName())); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_TOTALDISKUSAGE)) { try { cluster.setTotalBytesOnDisk(getLongAttribute(attribute.getValue(), attribute.getName())); } catch (Exception e) { cluster.setTotalBytesOnDisk((long) 0); continue; } cluster.getTotalBytesOnDiskTrend().add(cluster.getTotalBytesOnDisk()); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_DISKWRITESRATE)) { cluster.setDiskWritesRate(getFloatAttribute(attribute.getValue(), attribute.getName())); cluster.getThroughoutWritesTrend().add(cluster.getDiskWritesRate()); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_AVERAGEWRITES)) { try { cluster.setWritePerSec(getFloatAttribute(attribute.getValue(), attribute.getName())); } catch (Exception e) { cluster.setWritePerSec(0); continue; } cluster.getWritePerSecTrend().add(cluster.getWritePerSec()); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_AVERAGEREADS)) { try { cluster.setReadPerSec(getFloatAttribute(attribute.getValue(), attribute.getName())); } catch (Exception e) { cluster.setReadPerSec(0); continue; } cluster.getReadPerSecTrend().add(cluster.getReadPerSec()); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_QUERYREQUESTRATE)) { cluster.setQueriesPerSec(getFloatAttribute(attribute.getValue(), attribute.getName())); cluster.getQueriesPerSecTrend().add(cluster.getQueriesPerSec()); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_DISKREADSRATE)) { cluster.setDiskReadsRate(getFloatAttribute(attribute.getValue(), attribute.getName())); cluster.getThroughoutReadsTrend().add(cluster.getDiskReadsRate()); } else if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_JVMPAUSES)) { cluster.setGarbageCollectionCount(getLongAttribute(attribute.getValue(), attribute.getName())); cluster.getGarbageCollectionTrend().add(cluster.getGarbageCollectionCount()); } // For GemFireXD or GemFire if (PulseConstants.PRODUCT_NAME_GEMFIREXD .equalsIgnoreCase(PulseController.getPulseProductSupport())) { // For GemFireXD // Do nothing } else { // For GemFire if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_TOTALREGIONCOUNT)) { cluster.setTotalRegionCount(getIntegerAttribute(attribute.getValue(), attribute.getName())); } } } // GEMFIREXD attributes if (PulseConstants.PRODUCT_NAME_GEMFIREXD.equalsIgnoreCase(PulseController.getPulseProductSupport())) { try { // get GemFireXD cluster mbean ObjectName sfMemberMbeansObjectName = new ObjectName(PulseConstants.OBJECT_NAME_SF_CLUSTER); Set<ObjectName> sfCluserMBeans = this.mbs.queryNames(sfMemberMbeansObjectName, null); for (ObjectName sfCluserMBean : sfCluserMBeans) { AttributeList attrList = this.mbs.getAttributes(sfCluserMBean, PulseConstants.SF_CLUSTER_MBEAN_ATTRIBUTES); for (int i = 0; i < attrList.size(); i++) { Attribute attribute = (Attribute) attrList.get(i); if (attribute.getName() .equals(PulseConstants.MBEAN_ATTRIBUTE_PROCEDURECALLSINPROGRESS)) { try { cluster.setRunningFunctionCount( getIntegerAttribute(attribute.getValue(), attribute.getName())); } catch (Exception e) { cluster.setRunningFunctionCount(0); continue; } } else if (attribute.getName() .equals(PulseConstants.MBEAN_ATTRIBUTE_NETWORKSERVERCLIENTCONNECTIONSTATS)) { // set number of cluster's clients CompositeData nscConnStats = (CompositeData) attribute.getValue(); cluster.setClientConnectionCount(getLongAttribute( nscConnStats.get(PulseConstants.COMPOSITE_DATA_KEY_CONNECTIONSOPEN), PulseConstants.COMPOSITE_DATA_KEY_CONNECTIONSOPEN)); } } break; } } catch (MalformedObjectNameException e) { LOGGER.warning(e); } catch (NullPointerException e) { LOGGER.warning(e); } } } catch (InstanceNotFoundException infe) { LOGGER.warning(infe); } catch (ReflectionException re) { LOGGER.warning(re); } catch (MBeanException anfe) { LOGGER.warning(anfe); } }
From source file:edu.nwpu.gemfire.monitor.data.JMXDataUpdater.java
/** * function used to get attribute values of Cluster System and map them to * cluster vo//from ww w . j a v a 2 s. c om * * @param mbeanName * Cluster System MBean * @throws IOException * */ private void updateClusterSystem(ObjectName mbeanName) throws IOException { try { if (!this.isAddedNotiListner) { this.mbs.addNotificationListener(mbeanName, this, null, new Object()); this.isAddedNotiListner = true; } if (PulseConstants.PRODUCT_NAME_SQLFIRE.equalsIgnoreCase(PulseController.getPulseProductSupport())) { // Reset to zero cluster.setServerCount(0); cluster.setTotalRegionCount(0); } else { String[] serverCnt = (String[]) (this.mbs.invoke(mbeanName, PulseConstants.MBEAN_OPERATION_LISTSERVERS, null, null)); cluster.setServerCount(serverCnt.length); } TabularData table = (TabularData) (this.mbs.invoke(mbeanName, PulseConstants.MBEAN_OPERATION_VIEWREMOTECLUSTERSTATUS, null, null)); Collection<CompositeData> rows = (Collection<CompositeData>) table.values(); cluster.getWanInformationObject().clear(); for (CompositeData row : rows) { final Object key = row.get("key"); final Object value = row.get("value"); cluster.getWanInformationObject().put((String) key, (Boolean) value); } AttributeList attributeList = this.mbs.getAttributes(mbeanName, PulseConstants.CLUSTER_MBEAN_ATTRIBUTES); for (int i = 0; i < attributeList.size(); i++) { Attribute attribute = (Attribute) attributeList.get(i); String name = attribute.getName(); switch (name) { case PulseConstants.MBEAN_ATTRIBUTE_MEMBERCOUNT: cluster.setMemberCount(getIntegerAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_NUMCLIENTS: cluster.setClientConnectionCount( getIntegerAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_DISTRIBUTEDSYSTEMID: cluster.setClusterId(getIntegerAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_LOCATORCOUNT: cluster.setLocatorCount(getIntegerAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_NUMRUNNIGFUNCTION: try { cluster.setRunningFunctionCount( getIntegerAttribute(attribute.getValue(), attribute.getName())); } catch (Exception e) { cluster.setRunningFunctionCount(0); continue; } break; case PulseConstants.MBEAN_ATTRIBUTE_REGISTEREDCQCOUNT: cluster.setRegisteredCQCount(getLongAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_NUMSUBSCRIPTIONS: cluster.setSubscriptionCount(getIntegerAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_NUMTXNCOMMITTED: cluster.setTxnCommittedCount(getIntegerAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_NUMTXNROLLBACK: cluster.setTxnRollbackCount(getIntegerAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_TOTALHEAPSIZE: cluster.setTotalHeapSize(getLongAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_USEDHEAPSIZE: try { cluster.setUsedHeapSize(getLongAttribute(attribute.getValue(), attribute.getName())); } catch (Exception e) { cluster.setUsedHeapSize((long) 0); continue; } cluster.getMemoryUsageTrend().add(cluster.getUsedHeapSize()); break; case PulseConstants.MBEAN_ATTRIBUTE_TOTALREGIONENTRYCOUNT: cluster.setTotalRegionEntryCount(getLongAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_CURRENTENTRYCOUNT: cluster.setCurrentQueryCount(getIntegerAttribute(attribute.getValue(), attribute.getName())); break; case PulseConstants.MBEAN_ATTRIBUTE_TOTALDISKUSAGE: try { cluster.setTotalBytesOnDisk(getLongAttribute(attribute.getValue(), attribute.getName())); } catch (Exception e) { cluster.setTotalBytesOnDisk((long) 0); continue; } cluster.getTotalBytesOnDiskTrend().add(cluster.getTotalBytesOnDisk()); break; case PulseConstants.MBEAN_ATTRIBUTE_DISKWRITESRATE: cluster.setDiskWritesRate(getDoubleAttribute(attribute.getValue(), attribute.getName())); cluster.getThroughoutWritesTrend().add(cluster.getDiskWritesRate()); break; case PulseConstants.MBEAN_ATTRIBUTE_AVERAGEWRITES: try { cluster.setWritePerSec(getDoubleAttribute(attribute.getValue(), attribute.getName())); } catch (Exception e) { cluster.setWritePerSec(0); continue; } cluster.getWritePerSecTrend().add(cluster.getWritePerSec()); break; case PulseConstants.MBEAN_ATTRIBUTE_AVERAGEREADS: try { cluster.setReadPerSec(getDoubleAttribute(attribute.getValue(), attribute.getName())); } catch (Exception e) { cluster.setReadPerSec(0); continue; } cluster.getReadPerSecTrend().add(cluster.getReadPerSec()); break; case PulseConstants.MBEAN_ATTRIBUTE_QUERYREQUESTRATE: cluster.setQueriesPerSec(getDoubleAttribute(attribute.getValue(), attribute.getName())); cluster.getQueriesPerSecTrend().add(cluster.getQueriesPerSec()); break; case PulseConstants.MBEAN_ATTRIBUTE_DISKREADSRATE: cluster.setDiskReadsRate(getDoubleAttribute(attribute.getValue(), attribute.getName())); cluster.getThroughoutReadsTrend().add(cluster.getDiskReadsRate()); break; case PulseConstants.MBEAN_ATTRIBUTE_JVMPAUSES: long trendVal = determineCurrentJVMPauses(PulseConstants.JVM_PAUSES_TYPE_CLUSTER, "", getLongAttribute(attribute.getValue(), attribute.getName())); cluster.setGarbageCollectionCount(trendVal); cluster.getGarbageCollectionTrend().add(cluster.getGarbageCollectionCount()); break; case PulseConstants.MBEAN_ATTRIBUTE_TOTALREGIONCOUNT: if (!PulseConstants.PRODUCT_NAME_SQLFIRE .equalsIgnoreCase(PulseController.getPulseProductSupport())) { // for Gemfire cluster.setTotalRegionCount(getIntegerAttribute(attribute.getValue(), attribute.getName())); } break; } } // SQLFIRE attributes if (PulseConstants.PRODUCT_NAME_SQLFIRE.equalsIgnoreCase(PulseController.getPulseProductSupport())) { try { // get sqlfire cluster mbean ObjectName sfMemberMbeansObjectName = new ObjectName(PulseConstants.OBJECT_NAME_SF_CLUSTER); Set<ObjectName> sfCluserMBeans = this.mbs.queryNames(sfMemberMbeansObjectName, null); for (ObjectName sfCluserMBean : sfCluserMBeans) { AttributeList attrList = this.mbs.getAttributes(sfCluserMBean, PulseConstants.SF_CLUSTER_MBEAN_ATTRIBUTES); for (int i = 0; i < attrList.size(); i++) { Attribute attribute = (Attribute) attrList.get(i); if (attribute.getName() .equals(PulseConstants.MBEAN_ATTRIBUTE_PROCEDURECALLSINPROGRESS)) { try { cluster.setRunningFunctionCount( getIntegerAttribute(attribute.getValue(), attribute.getName())); } catch (Exception e) { cluster.setRunningFunctionCount(0); continue; } } else if (attribute.getName() .equals(PulseConstants.MBEAN_ATTRIBUTE_NETWORKSERVERCLIENTCONNECTIONSTATS)) { // set number of cluster's clients CompositeData nscConnStats = (CompositeData) attribute.getValue(); cluster.setClientConnectionCount(getLongAttribute( nscConnStats.get(PulseConstants.COMPOSITE_DATA_KEY_CONNECTIONSACTIVE), PulseConstants.COMPOSITE_DATA_KEY_CONNECTIONSACTIVE)); } } break; } } catch (MalformedObjectNameException e) { LOGGER.warning(e); } catch (NullPointerException e) { LOGGER.warning(e); } } } catch (InstanceNotFoundException infe) { LOGGER.warning(infe); } catch (ReflectionException re) { LOGGER.warning(re); } catch (MBeanException anfe) { LOGGER.warning(anfe); } }