use of javax.management.ReflectionException in project geode by apache.
the class JMXDataUpdater method updateClusterRegion.
/**
* function used to get attribute values of Cluster Region and map them to cluster region vo
*
* @param mbeanName Cluster Region MBean
*/
private void updateClusterRegion(ObjectName mbeanName) throws IOException {
try {
AttributeList attributeList = this.mbs.getAttributes(mbeanName, PulseConstants.REGION_MBEAN_ATTRIBUTES);
// retrieve the full path of the region
String regionObjectName = mbeanName.getKeyProperty("name");
String regionFullPath = null;
for (int i = 0; i < attributeList.size(); i++) {
Attribute attribute = (Attribute) attributeList.get(i);
if (attribute.getName().equals(PulseConstants.MBEAN_ATTRIBUTE_FULLPATH)) {
regionFullPath = getStringAttribute(attribute.getValue(), attribute.getName());
break;
}
}
Cluster.Region region = cluster.getClusterRegions().get(regionFullPath);
if (null == region) {
region = new Cluster.Region();
}
for (int i = 0; i < attributeList.size(); i++) {
Attribute attribute = (Attribute) attributeList.get(i);
String name = attribute.getName();
switch(name) {
case PulseConstants.MBEAN_ATTRIBUTE_MEMBERS:
String[] memName = (String[]) attribute.getValue();
region.getMemberName().clear();
for (int k = 0; k < memName.length; k++) {
region.getMemberName().add(memName[k]);
}
break;
case PulseConstants.MBEAN_ATTRIBUTE_FULLPATH:
region.setFullPath(getStringAttribute(attribute.getValue(), attribute.getName()));
break;
case PulseConstants.MBEAN_ATTRIBUTE_DISKREADSRATE:
region.setDiskReadsRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
break;
case PulseConstants.MBEAN_ATTRIBUTE_DISKWRITESRATE:
region.setDiskWritesRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
break;
case PulseConstants.MBEAN_ATTRIBUTE_EMPTYNODES:
region.setEmptyNode(getIntegerAttribute(attribute.getValue(), attribute.getName()));
break;
case PulseConstants.MBEAN_ATTRIBUTE_GETSRATE:
region.setGetsRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
break;
case PulseConstants.MBEAN_ATTRIBUTE_LRUEVICTIONRATE:
region.setLruEvictionRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
break;
case PulseConstants.MBEAN_ATTRIBUTE_PUTSRATE:
region.setPutsRate(getDoubleAttribute(attribute.getValue(), attribute.getName()));
break;
case PulseConstants.MBEAN_ATTRIBUTE_REGIONTYPE:
region.setRegionType(getStringAttribute(attribute.getValue(), attribute.getName()));
break;
case PulseConstants.MBEAN_ATTRIBUTE_ENTRYSIZE:
region.setEntrySize(getLongAttribute(attribute.getValue(), attribute.getName()));
break;
case PulseConstants.MBEAN_ATTRIBUTE_SYSTEMREGIONENTRYCOUNT:
region.setSystemRegionEntryCount(getLongAttribute(attribute.getValue(), attribute.getName()));
break;
case PulseConstants.MBEAN_ATTRIBUTE_MEMBERCOUNT:
region.setMemberCount(getIntegerAttribute(attribute.getValue(), attribute.getName()));
break;
case PulseConstants.MBEAN_ATTRIBUTE_PERSISTENTENABLED:
region.setPersistentEnabled(getBooleanAttribute(attribute.getValue(), attribute.getName()));
break;
case PulseConstants.MBEAN_ATTRIBUTE_NAME:
region.setName(getStringAttribute(attribute.getValue(), attribute.getName()));
break;
case PulseConstants.MBEAN_ATTRIBUTE_GATEWAYENABLED:
region.setWanEnabled(getBooleanAttribute(attribute.getValue(), attribute.getName()));
break;
case PulseConstants.MBEAN_ATTRIBUTE_DISKUSAGE:
region.setDiskUsage(getLongAttribute(attribute.getValue(), attribute.getName()));
break;
}
}
// add for each member
updateRegionOnMembers(regionObjectName, regionFullPath, region);
cluster.addClusterRegion(regionFullPath, region);
cluster.getDeletedRegions().remove(region.getFullPath());
// Memory Reads and writes
region.getPutsPerSecTrend().add(region.getPutsRate());
region.getGetsPerSecTrend().add(region.getGetsRate());
// Disk Reads and Writes
region.getDiskReadsPerSecTrend().add(region.getDiskReadsRate());
region.getDiskWritesPerSecTrend().add(region.getDiskWritesRate());
} catch (InstanceNotFoundException | ReflectionException infe) {
logger.warn(infe);
}
}
use of javax.management.ReflectionException in project ddf by codice.
the class RrdJmxCollector method updateSamples.
/**
* Configures a scheduled threaded executor to poll the metric's MBean periodically and add a
* sample to the RRD file with the metric's current value.
*
* @throws CollectorException
*/
public void updateSamples() throws CollectorException {
LOGGER.trace("ENTERING: updateSamples");
if (executor == null) {
executor = new ScheduledThreadPoolExecutor(1);
}
final Runnable updater = new Runnable() {
public void run() {
Object attr = null;
try {
attr = localMBeanServer.getAttribute(new ObjectName(mbeanName), mbeanAttributeName);
LOGGER.trace("Sampling attribute {} from MBean {}", mbeanAttributeName, mbeanName);
// Cast the metric's sampled value to the appropriate data type
double val = 0;
if (attr instanceof Integer) {
val = (Integer) attr;
} else if (attr instanceof Long) {
val = ((Long) attr).intValue();
} else if (attr instanceof Float) {
val = ((Float) attr);
} else if (attr instanceof Double) {
val = ((Double) attr);
} else {
throw new IllegalArgumentException("Unsupported type " + attr + " for attribute " + mbeanAttributeName);
}
LOGGER.trace("MBean attribute {} has value = {}", mbeanAttributeName, val);
// sample in the RRD file
if (sample == null) {
sample = rrdDb.createSample();
}
try {
long now = System.currentTimeMillis() / MILLIS_PER_SECOND;
long lastUpdateTime = rrdDb.getLastUpdateTime();
// Add metric's sample to RRD file with current timestamp
if (now - rrdDb.getLastUpdateTime() >= minimumUpdateTimeDelta) {
updateSample(now, val);
} else {
LOGGER.debug("Skipping sample update because time between updates is less than {} seconds", minimumUpdateTimeDelta);
sampleSkipCount++;
LOGGER.debug("now = {}, lastUpdateTime = {} (sampleSkipCount = {})", now, lastUpdateTime, sampleSkipCount);
}
} catch (IllegalArgumentException iae) {
LOGGER.info("Dropping sample of datasource {}", rrdDataSourceName, iae);
}
} catch (MalformedObjectNameException | AttributeNotFoundException | InstanceNotFoundException | MBeanException | ReflectionException e) {
LOGGER.info("Problems getting MBean attribute {}", mbeanAttributeName, e);
} catch (IOException e) {
LOGGER.info("Error updating RRD", e);
}
}
};
// Setup threaded scheduler to retrieve this MBean attribute's value
// at the specified sample rate
LOGGER.debug("Setup ScheduledThreadPoolExecutor for MBean {}", mbeanName);
executor.scheduleWithFixedDelay(updater, 0, sampleRate, TimeUnit.SECONDS);
LOGGER.trace("EXITING: updateSamples");
}
Aggregations