use of org.opennms.netmgt.config.collectd.jmx.JmxCollection in project opennms by OpenNMS.
the class JMXDataCollectionConfigDao method buildCollectionMap.
/**
* Build collection map which is a hash map of Collection
* objects indexed by collection name...also build
* collection group map which is a hash map indexed
* by collection name with a hash map as the value
* containing a map of the collections's group names
* to the Group object containing all the information
* for that group. So the associations are:
* <p/>
* CollectionMap
* collectionName -> Collection
* <p/>
* CollectionGroupMap
* collectionName -> groupMap
* <p/>
* GroupMap
* groupMapName -> Group
* <p/>
* This is parsed and built at initialization for
* faster processing at run-time.
*/
private void buildCollectionMap(JmxDatacollectionConfig config) {
m_lock.writeLock().lock();
try {
m_collectionMap.clear();
// global to all the mbeans?
for (JmxCollection collection : config.getJmxCollectionList()) {
// Build group map for this collection
Map<String, Mbean> groupMap = new HashMap<String, Mbean>();
for (Mbean mbean : collection.getMbeans()) {
groupMap.put(mbean.getName(), mbean);
}
m_collectionMap.put(collection.getName(), collection);
}
} finally {
m_lock.writeLock().unlock();
}
}
use of org.opennms.netmgt.config.collectd.jmx.JmxCollection in project opennms by OpenNMS.
the class JMXCollector method collect.
@Override
public CollectionSet collect(CollectionAgent agent, Map<String, Object> map) {
final Map<String, String> stringMap = JmxUtils.convertToUnmodifiableStringMap(map);
final InetAddress ipaddr = agent.getAddress();
final JmxCollection jmxCollection = (JmxCollection) map.get(JMX_COLLECTION_KEY);
final MBeanServer mBeanServer = (MBeanServer) map.get(JMX_MBEAN_SERVER_KEY);
final String collectionName = ParameterMap.getKeyedString(map, ParameterName.COLLECTION.toString(), serviceName);
final String port = ParameterMap.getKeyedString(map, ParameterName.PORT.toString(), null);
final String friendlyName = ParameterMap.getKeyedString(map, ParameterName.FRIENDLY_NAME.toString(), port);
final String collDir = JmxUtils.getCollectionDirectory(stringMap, friendlyName, serviceName);
final int retries = ParameterMap.getKeyedInteger(map, ParameterName.RETRY.toString(), 3);
InetAddress ipAddr = agent.getAddress();
int nodeID = agent.getNodeId();
// Retrieve the name of the JMX data collector
final String hostAddress = InetAddressUtils.str(ipAddr);
LOG.debug("initialize: InetAddress={}, collectionName={}", hostAddress, collectionName);
JMXNodeInfo nodeInfo = new JMXNodeInfo(nodeID);
LOG.debug("nodeInfo: {} {} {}", hostAddress, nodeID, agent);
/*
* Retrieve list of MBean objects to be collected from the
* remote agent which are to be stored in the node-level RRD file.
* These objects pertain to the node itself not any individual
* interfaces.
*/
Map<String, List<Attrib>> attrMap = JMXDataCollectionConfigDao.getAttributeMap(jmxCollection, serviceName(), hostAddress);
nodeInfo.setAttributeMap(attrMap);
Map<String, JMXDataSource> dsList = buildDataSourceList(collectionName, attrMap);
nodeInfo.setDsMap(dsList);
nodeInfo.setMBeans(JMXDataCollectionConfigDao.getMBeanInfo(jmxCollection));
// Metrics collected from JMX are currently modeled as node level resources,
// but live in a sub-directory set to the service name
final NodeLevelResource nodeResource = new NodeLevelResource(agent.getNodeId(), collDir);
// This parent resource used for generic resource
final NodeLevelResource parentResource = new NodeLevelResource(agent.getNodeId());
// Used to gather the results
final CollectionSetBuilder collectionSetBuilder = new CollectionSetBuilder(agent);
LOG.debug("connecting to {} on node ID {}", InetAddressUtils.str(ipaddr), nodeInfo.getNodeId());
try {
// create config for JmxCollector
final JmxCollectorConfig config = new JmxCollectorConfig();
config.setAgentAddress(InetAddressUtils.str(ipaddr));
config.setConnectionName(getConnectionName());
config.setRetries(retries);
config.setServiceProperties(stringMap);
config.setJmxCollection(jmxCollection);
final DefaultJmxCollector jmxCollector = new DefaultJmxCollector();
jmxCollector.collect(config, mBeanServer, new JmxSampleProcessor() {
@Override
public void process(JmxAttributeSample attributeSample, ObjectName objectName) {
final String mbeanObjectName = attributeSample.getMbean().getObjectname();
final String attributeName = attributeSample.getCollectedAttribute().getName();
final String dsKey = mbeanObjectName + "|" + attributeName;
final JMXDataSource ds = nodeInfo.getDsMap().get(dsKey);
if (ds == null) {
LOG.info("Could not find datasource for {}. Skipping.", dsKey);
return;
}
String resourceType = attributeSample.getMbean().getResourceType();
if (resourceType != null) {
final String parsedObjectName = fixGroupName(objectName.getCanonicalName());
final Resource resource = new DeferredGenericTypeResource(parentResource, resourceType, parsedObjectName);
addNumericAttributeToCollectionSet(ds, attributeSample, resource);
addStringAttributesToCollectionSet(ds, attributeSample, resource, objectName);
} else {
addNumericAttributeToCollectionSet(ds, attributeSample, nodeResource);
}
}
@Override
public void process(JmxCompositeSample compositeSample, ObjectName objectName) {
final String mbeanObjectName = compositeSample.getMbean().getObjectname();
final String attributeName = compositeSample.getCollectedAttribute().getName();
final String dsKey = mbeanObjectName + "|" + attributeName + "|" + compositeSample.getCompositeKey();
final JMXDataSource ds = nodeInfo.getDsMap().get(dsKey);
if (ds == null) {
LOG.info("Could not find datasource for {}. Skipping.", dsKey);
return;
}
String resourceType = compositeSample.getMbean().getResourceType();
if (resourceType != null) {
final String parsedObjectName = fixGroupName(objectName.getCanonicalName());
final Resource resource = new DeferredGenericTypeResource(parentResource, resourceType, parsedObjectName);
addNumericAttributeToCollectionSet(ds, compositeSample, resource);
addStringAttributesToCollectionSet(ds, compositeSample, resource, objectName);
} else {
addNumericAttributeToCollectionSet(ds, compositeSample, nodeResource);
}
}
private void addStringAttributesToCollectionSet(JMXDataSource ds, AbstractJmxSample sample, Resource resource, ObjectName objectName) {
final String groupName = fixGroupName(JmxUtils.getGroupName(stringMap, sample.getMbean()));
final String domain = objectName.getDomain();
final Hashtable<String, String> properties = objectName.getKeyPropertyList();
properties.forEach((key, value) -> collectionSetBuilder.withStringAttribute(resource, groupName, key, value));
if (domain != null) {
collectionSetBuilder.withStringAttribute(resource, groupName, "domain", objectName.getDomain());
}
}
private void addNumericAttributeToCollectionSet(JMXDataSource ds, AbstractJmxSample sample, Resource resource) {
final String groupName = fixGroupName(JmxUtils.getGroupName(stringMap, sample.getMbean()));
// Only numeric data comes back from JMX in data collection
final String valueAsString = sample.getCollectedValueAsString();
final Double value = NumericAttributeUtils.parseNumericValue(valueAsString);
// Construct the metric identifier (used by NRTG)
String metricId = groupName;
metricId = metricId.replace("_type_", ":type=");
metricId = metricId.replace("_", ".");
metricId = metricId.concat(".");
metricId = metricId.concat(ds.getName());
metricId = "JMX_".concat(metricId);
collectionSetBuilder.withIdentifiedNumericAttribute(resource, groupName, ds.getName(), value, ds.getType(), metricId);
}
});
} catch (final Exception e) {
LOG.debug("{} Collector.collect: IOException while collecting address: {}", serviceName, agent.getAddress(), e);
}
return collectionSetBuilder.build();
}
use of org.opennms.netmgt.config.collectd.jmx.JmxCollection in project opennms by OpenNMS.
the class JmxConfigReader method generateReportsByJmxDatacollectionConfig.
public Collection<Report> generateReportsByJmxDatacollectionConfig(JmxDatacollectionConfig inputConfig) {
Collection<Report> reports = new ArrayList<>();
for (JmxCollection jmxCollection : inputConfig.getJmxCollectionList()) {
logger.debug("jmxCollection: '{}'", jmxCollection.getName());
for (Mbean mbean : jmxCollection.getMbeans()) {
reports.addAll(generateMbeanReportsByMBean(mbean));
reports.addAll(generateAttributeReportsByMBean(mbean));
reports.addAll(generateCompositeReportsByMBean(mbean));
reports.addAll(generateCompositeMemberReportsByMBean(mbean));
}
}
return reports;
}
use of org.opennms.netmgt.config.collectd.jmx.JmxCollection in project opennms by OpenNMS.
the class JmxCollectionCloner method clone.
/**
* Clones a whole JmxCollectionConfig. Makes a deep copy!
*
* @param input
* @return
*/
public static JmxDatacollectionConfig clone(JmxDatacollectionConfig input) {
JmxDatacollectionConfig output = new JmxDatacollectionConfig();
output.setRrdRepository(input.getRrdRepository());
for (JmxCollection jmxCollection : input.getJmxCollectionList()) {
output.addJmxCollection(clone(jmxCollection));
}
return output;
}
Aggregations