private Set<DiscoveredResourceDetails> createDiscoveredResource( ResourceDiscoveryContext<JMXComponent<?>> ctx, Configuration pluginConfiguration, String objectName) { boolean trace = log.isTraceEnabled(); JMXComponent<?> parentComponent = ctx.getParentResourceComponent(); EmsConnection conn = parentComponent.getEmsConnection(); if (conn != null) { if (trace) log.trace("Connection to ems server established: " + conn); // Run query for manager_object ObjectNameQueryUtility queryUtility = new ObjectNameQueryUtility(objectName); List<EmsBean> beans = conn.queryBeans(queryUtility.getTranslatedQuery()); if (trace) log.trace("Querying [" + queryUtility.getTranslatedQuery() + "] returned beans: " + beans); Set<DiscoveredResourceDetails> discoveredResources = new HashSet<DiscoveredResourceDetails>(); for (EmsBean bean : beans) { // Filter out spurious beans if (CacheManagerComponent.isCacheManagerComponent(bean)) { String managerName = bean.getBeanName().getCanonicalName(); String resourceName = bean.getAttribute("Name").getValue().toString(); String version = bean.getAttribute("Version").getValue().toString(); /* A discovered resource must have a unique key, that must stay the same when the resource is discovered the next time */ if (trace) log.trace( "Add resource with version '" + version + "' and type " + ctx.getResourceType()); DiscoveredResourceDetails detail = new DiscoveredResourceDetails( ctx.getResourceType(), // Resource type resourceName, // Resource key resourceName, // Resource name version, // Resource version "A cache manager within Infinispan", // Description pluginConfiguration, // Plugin config null // Process info from a process scan ); if (log.isInfoEnabled()) { log.info( String.format( "Discovered Infinispan instance with key %s and name %s", resourceName, managerName)); } discoveredResources.add(detail); } else { log.warn( String.format( "MBeanServer returned spurious object %s", bean.getBeanName().getCanonicalName())); } } return discoveredResources; } else { log.debug("Unable to establish connection"); return null; } }
/** * Gather measurement data * * @see * org.rhq.core.pluginapi.measurement.MeasurementFacet#getValues(org.rhq.core.domain.measurement.MeasurementReport, * java.util.Set) */ @Override public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> metrics) { boolean trace = log.isTraceEnabled(); if (trace) log.trace("Get values metrics"); for (MeasurementScheduleRequest req : metrics) { if (trace) log.trace("Inspect metric " + req); String metric = req.getName(); try { EmsBean bean = queryComponentBean(metric); if (bean != null) { if (trace) log.trace("Retrieved mbean with name " + bean.getBeanName()); bean.refreshAttributes(); String attName = metric.substring(metric.indexOf(".") + 1); EmsAttribute att = bean.getAttribute(attName); // Attribute values are of various data types if (att != null) { Object o = att.getValue(); Class<?> attrType = att.getTypeClass(); DataType type = req.getDataType(); if (type == DataType.MEASUREMENT) { if (o != null) { MeasurementDataNumeric res = constructNumericMeasure(attrType, o, req); if (res != null) report.addData(res); } else { if (log.isDebugEnabled()) log.debug("Metric (" + req.getName() + ") has null value, do not add to report"); } } else if (type == DataType.TRAIT) { String value = (String) o; if (trace) log.trace("Metric (" + req.getName() + ") is trait with value " + value); MeasurementDataTrait res = new MeasurementDataTrait(req, value); report.addData(res); } } else { if (log.isWarnEnabled()) { log.warn("Attribute " + attName + " not found"); } } } } catch (Exception e) { if (log.isWarnEnabled()) { log.warn("getValues failed for " + metric, e); } } } }