Search in sources :

Example 16 with NodeLevelResource

use of org.opennms.netmgt.collection.support.builder.NodeLevelResource in project opennms by OpenNMS.

the class XmpCollector method handleTableQuery.

/* handleScalarQuery */
// handle a tabular query, save each row in its own
// collection resource
private boolean handleTableQuery(String groupName, String resourceType, CollectionAgent agent, CollectionSetBuilder collectionSetBuilder, String[] tableInfo, XmpSession session, NodeLevelResource nodeLevelResource, XmpVar[] queryVars) throws CollectionException {
    int numColumns, numRows;
    XmpMessage reply;
    int i, j;
    XmpVar[] vars;
    String targetInstance;
    numColumns = queryVars.length;
    // make sure we have an instance or * for all rows; preserve
    // passed in value as targetInstance so we know if we are
    // are going to use targetInstance for saving results or
    // use returned instance for saving values
    // if resourceType is present, we use it as a subDir in
    // our RRD dir
    targetInstance = tableInfo[2];
    if ((tableInfo[2] == null) || (tableInfo[2].length() == 0)) {
        tableInfo[2] = new String("*");
        targetInstance = null;
    }
    LOG.debug("sending table query {},{},{} target: {}", tableInfo[0], tableInfo[1], tableInfo[2], targetInstance);
    reply = session.queryTableVars(tableInfo, 0, queryVars);
    if (reply == null) {
        LOG.warn("collect: query to {} failed, {}", agent, Xmp.errorStatusToString(session.getErrorStatus()));
        return false;
    }
    vars = reply.getMIBVars();
    // we have to go through the reply and find out how
    // many rows we have
    // for each row: create a CollectionResource of
    // appropriate type, instance, etc.
    // create AttributeGroup to put
    // the values in
    numRows = vars.length / numColumns;
    LOG.info("query returned valid table data for {} numRows={} numColumns={}", groupName, numRows, numColumns);
    for (i = 0; i < numRows; i++) {
        String rowInstance;
        // determine instance for this row
        // we use either the rowInstance or targetInstance for
        // naming the instance for saving RRD file; if user
        // wanted all rows (blank instance), then we will use
        // the returned instance; if user specified an instance
        // we use that instance for specifying the RRD file
        // and collection resource
        rowInstance = vars[i * numColumns].getKey();
        // instead of using '*' for the nodeTypeName, use the
        // table name so that the proper rrd file is spec'd
        final String instanceName;
        if (targetInstance != null) {
            instanceName = targetInstance;
        } else {
            instanceName = rowInstance;
        }
        // node type can be "node" for scalars or
        // "if" for network interface resources and
        // "*" for all other resource types
        final String nodeTypeName = tableInfo[1];
        final Resource resource = getResource(nodeLevelResource, nodeTypeName, resourceType, instanceName);
        LOG.debug("queryTable instance={}", rowInstance);
        for (j = 0; j < numColumns; j++) {
            final XmpVar var = vars[i * numColumns + j];
            collectionSetBuilder.withAttribute(resource, groupName, var.getObjName(), var.getValue(), getType(var));
        }
    /* for each column */
    }
    return true;
}
Also used : XmpVar(org.krupczak.xmp.XmpVar) XmpMessage(org.krupczak.xmp.XmpMessage) InterfaceLevelResource(org.opennms.netmgt.collection.support.builder.InterfaceLevelResource) CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) Resource(org.opennms.netmgt.collection.support.builder.Resource) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource)

Example 17 with NodeLevelResource

use of org.opennms.netmgt.collection.support.builder.NodeLevelResource in project opennms by OpenNMS.

the class WmiCollector method collect.

/**
 * {@inheritDoc}
 */
@Override
public CollectionSet collect(final CollectionAgent agent, final Map<String, Object> parameters) {
    // Find attributes to collect - check groups in configuration. For each,
    // check scheduled nodes to see if that group should be collected
    final WmiCollection collection = (WmiCollection) parameters.get(WMI_COLLECTION_KEY);
    final WmiAgentConfig agentConfig = (WmiAgentConfig) parameters.get(WMI_AGENT_CONFIG_KEY);
    final WmiAgentState agentState = new WmiAgentState(agent.getAddress(), agentConfig, parameters);
    // Create a new collection set.
    CollectionSetBuilder builder = new CollectionSetBuilder(agent).withStatus(CollectionStatus.FAILED);
    if (collection.getWpms().size() < 1) {
        LOG.info("No groups to collect.");
        return builder.withStatus(CollectionStatus.SUCCEEDED).build();
    }
    final NodeLevelResource nodeResource = new NodeLevelResource(agent.getNodeId());
    // Iterate through the WMI collection groups.
    for (final Wpm wpm : collection.getWpms()) {
        // A wpm consists of a list of attributes, identified by name
        if (agentState.shouldCheckAvailability(wpm.getName(), wpm.getRecheckInterval())) {
            if (!isGroupAvailable(agentState, wpm)) {
                continue;
            }
        }
        if (agentState.groupIsAvailable(wpm.getName())) {
            WmiClient client = null;
            // Collect the data
            try {
                // Tell the agent to connect
                agentState.connect(wpm.getWmiNamespace());
                // And retrieve the client object for working.
                client = (WmiClient) agentState.getWmiClient();
                // Retrieve the WbemObjectSet from the class defined on the group.
                final OnmsWbemObjectSet wOS = client.performInstanceOf(wpm.getWmiClass());
                // If we received a WbemObjectSet result, lets go through it and collect it.
                if (wOS != null) {
                    // Go through each object (class instance) in the object set.
                    for (int i = 0; i < wOS.count(); i++) {
                        // Create a new collection resource.
                        Resource resource = null;
                        // Fetch our WBEM Object
                        final OnmsWbemObject obj = wOS.get(i);
                        // If this is multi-instance, fetch the instance name and store it.
                        if (wOS.count() > 1) {
                            // Fetch the value of the key value. e.g. Name.
                            final OnmsWbemProperty prop = obj.getWmiProperties().getByName(wpm.getKeyvalue());
                            final Object propVal = prop.getWmiValue();
                            String instance = null;
                            if (propVal instanceof String) {
                                instance = (String) propVal;
                            } else {
                                instance = propVal.toString();
                            }
                            resource = getWmiResource(agent, wpm.getResourceType(), nodeResource, instance);
                        } else {
                            resource = nodeResource;
                        }
                        for (final Attrib attrib : wpm.getAttribs()) {
                            final OnmsWbemProperty prop = obj.getWmiProperties().getByName(attrib.getWmiObject());
                            final AttributeType type = attrib.getType();
                            final String stringValue = prop.getWmiValue().toString();
                            if (type.isNumeric()) {
                                Double numericValue = Double.NaN;
                                try {
                                    numericValue = Double.parseDouble(stringValue);
                                } catch (NumberFormatException e) {
                                    LOG.warn("Value '{}' for attribute named '{}' cannot be converted to a number. Skipping.", prop.getWmiValue(), attrib.getName());
                                    continue;
                                }
                                builder.withNumericAttribute(resource, wpm.getName(), attrib.getAlias(), numericValue, type);
                            } else {
                                builder.withStringAttribute(resource, wpm.getName(), attrib.getAlias(), stringValue);
                            }
                        }
                    }
                }
                builder.withStatus(CollectionStatus.SUCCEEDED);
            } catch (final WmiException e) {
                LOG.info("unable to collect params for wpm '{}'", wpm.getName(), e);
            } finally {
                if (client != null) {
                    try {
                        client.disconnect();
                    } catch (final WmiException e) {
                        LOG.warn("An error occurred disconnecting while collecting from WMI.", e);
                    }
                }
            }
        }
    }
    return builder.build();
}
Also used : CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) WmiAgentConfig(org.opennms.netmgt.config.wmi.WmiAgentConfig) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) Resource(org.opennms.netmgt.collection.support.builder.Resource) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) OnmsWbemProperty(org.opennms.protocols.wmi.wbem.OnmsWbemProperty) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) WmiCollection(org.opennms.netmgt.config.wmi.WmiCollection) Attrib(org.opennms.netmgt.config.wmi.Attrib) Wpm(org.opennms.netmgt.config.wmi.Wpm) WmiClient(org.opennms.protocols.wmi.WmiClient) AttributeType(org.opennms.netmgt.collection.api.AttributeType) OnmsWbemObject(org.opennms.protocols.wmi.wbem.OnmsWbemObject) WmiAgentState(org.opennms.netmgt.collectd.wmi.WmiAgentState) OnmsWbemObjectSet(org.opennms.protocols.wmi.wbem.OnmsWbemObjectSet) WmiException(org.opennms.protocols.wmi.WmiException) OnmsWbemObject(org.opennms.protocols.wmi.wbem.OnmsWbemObject)

Example 18 with NodeLevelResource

use of org.opennms.netmgt.collection.support.builder.NodeLevelResource in project opennms by OpenNMS.

the class EvaluateStatsIT method testPersister.

/**
 * Test persister.
 *
 * @throws Exception the exception
 */
@Test
public void testPersister() throws Exception {
    RrdRepository repo = new RrdRepository();
    repo.setRrdBaseDir(new File("/tmp"));
    EvaluateGroupPersister persister = new EvaluateGroupPersister(stats, new ServiceParameters(new HashMap<String, Object>()), repo);
    MockCollectionAgent agent = new MockCollectionAgent(1, "node.local", "Test", "001", InetAddressUtils.addr("127.0.0.1"));
    CollectionSetBuilder builder = new CollectionSetBuilder(agent);
    NodeLevelResource node = new NodeLevelResource(agent.getNodeId());
    InterfaceLevelResource eth0 = new InterfaceLevelResource(node, "eth0");
    builder.withNumericAttribute(eth0, "mib2-interfaces", "ifInErrors", 0.0, AttributeType.COUNTER);
    builder.withNumericAttribute(eth0, "mib2-interfaces", "ifOutErrors", 0.0, AttributeType.COUNTER);
    builder.withNumericAttribute(eth0, "mib2-X-interfaces", "ifHCInOctets", 100.0, AttributeType.COUNTER);
    builder.withNumericAttribute(eth0, "mib2-X-interfaces", "ifHCOutOctets", 100.0, AttributeType.COUNTER);
    builder.withStringAttribute(eth0, "mib2-X-interfaces", "ifHighSpeed", "1000");
    InterfaceLevelResource eth1 = new InterfaceLevelResource(node, "eth1");
    builder.withNumericAttribute(eth1, "mib2-interfaces", "ifInErrors", 0.0, AttributeType.COUNTER);
    builder.withNumericAttribute(eth1, "mib2-interfaces", "ifOutErrors", 0.0, AttributeType.COUNTER);
    builder.withNumericAttribute(eth1, "mib2-X-interfaces", "ifHCInOctets", 100.0, AttributeType.COUNTER);
    builder.withNumericAttribute(eth1, "mib2-X-interfaces", "ifHCOutOctets", 100.0, AttributeType.COUNTER);
    builder.withStringAttribute(eth1, "mib2-X-interfaces", "ifHighSpeed", "1000");
    builder.build().visit(persister);
    stats.dumpCache();
    Assert.assertEquals(1, registry.getGauges().get("evaluate.nodes").getValue());
    Assert.assertEquals(2, registry.getGauges().get("evaluate.resources").getValue());
    Assert.assertEquals(4, registry.getGauges().get("evaluate.groups").getValue());
    Assert.assertEquals(8, registry.getGauges().get("evaluate.numeric-attributes").getValue());
    Assert.assertEquals(2, registry.getGauges().get("evaluate.string-attributes").getValue());
    Assert.assertEquals(8, registry.getMeters().get("evaluate.samples").getCount());
}
Also used : CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) HashMap(java.util.HashMap) MockCollectionAgent(org.opennms.core.collection.test.MockCollectionAgent) InterfaceLevelResource(org.opennms.netmgt.collection.support.builder.InterfaceLevelResource) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) File(java.io.File) Test(org.junit.Test)

Example 19 with NodeLevelResource

use of org.opennms.netmgt.collection.support.builder.NodeLevelResource 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();
}
Also used : CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) AlphaNumeric(org.opennms.core.utils.AlphaNumeric) JmxCollection(org.opennms.netmgt.config.collectd.jmx.JmxCollection) AbstractJmxSample(org.opennms.netmgt.jmx.samples.AbstractJmxSample) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) DeferredGenericTypeResource(org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource) NumericAttributeUtils(org.opennms.netmgt.collection.support.NumericAttributeUtils) InetAddress(java.net.InetAddress) DefaultJmxCollector(org.opennms.netmgt.jmx.impl.DefaultJmxCollector) MBeanServer(org.opennms.netmgt.config.jmx.MBeanServer) Map(java.util.Map) JmxUtils(org.opennms.netmgt.jmx.JmxUtils) JMXDataCollectionConfigDao(org.opennms.netmgt.config.JMXDataCollectionConfigDao) SimpleEntry(java.util.AbstractMap.SimpleEntry) Hashtable(java.util.Hashtable) ParameterMap(org.opennms.core.utils.ParameterMap) JmxCollectorConfig(org.opennms.netmgt.jmx.JmxCollectorConfig) JmxCompositeSample(org.opennms.netmgt.jmx.samples.JmxCompositeSample) Resource(org.opennms.netmgt.collection.support.builder.Resource) JmxAttributeSample(org.opennms.netmgt.jmx.samples.JmxAttributeSample) Logger(org.slf4j.Logger) InetAddressUtils(org.opennms.core.utils.InetAddressUtils) AbstractRemoteServiceCollector(org.opennms.netmgt.collection.api.AbstractRemoteServiceCollector) ObjectName(javax.management.ObjectName) JmxConfigDao(org.opennms.netmgt.dao.jmx.JmxConfigDao) Collectors(java.util.stream.Collectors) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) BeanUtils(org.opennms.core.spring.BeanUtils) Objects(java.util.Objects) List(java.util.List) JmxSampleProcessor(org.opennms.netmgt.jmx.JmxSampleProcessor) Stream(java.util.stream.Stream) ParameterName(org.opennms.netmgt.collection.api.ServiceParameters.ParameterName) Attrib(org.opennms.netmgt.config.collectd.jmx.Attrib) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) JmxConnectors(org.opennms.netmgt.jmx.connection.JmxConnectors) Collections(java.util.Collections) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) JmxCollection(org.opennms.netmgt.config.collectd.jmx.JmxCollection) AbstractJmxSample(org.opennms.netmgt.jmx.samples.AbstractJmxSample) List(java.util.List) MBeanServer(org.opennms.netmgt.config.jmx.MBeanServer) DefaultJmxCollector(org.opennms.netmgt.jmx.impl.DefaultJmxCollector) JmxCollectorConfig(org.opennms.netmgt.jmx.JmxCollectorConfig) Hashtable(java.util.Hashtable) JmxSampleProcessor(org.opennms.netmgt.jmx.JmxSampleProcessor) JmxCompositeSample(org.opennms.netmgt.jmx.samples.JmxCompositeSample) DeferredGenericTypeResource(org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource) Resource(org.opennms.netmgt.collection.support.builder.Resource) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) ObjectName(javax.management.ObjectName) DeferredGenericTypeResource(org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource) JmxAttributeSample(org.opennms.netmgt.jmx.samples.JmxAttributeSample) InetAddress(java.net.InetAddress)

Example 20 with NodeLevelResource

use of org.opennms.netmgt.collection.support.builder.NodeLevelResource in project opennms by OpenNMS.

the class TcaCollectionHandler method process.

/**
 * Process.
 *
 * <p>A sample TCA Data looks like the following:</p>
 * <ul>
 * <li>OID=.1.3.6.1.4.1.27091.3.1.6.1.1.172.19.37.60.1, Type=OctetString, Value=172.19.37.60 </li>
 * <li>OID=.1.3.6.1.4.1.27091.3.1.6.1.2.172.19.37.60.1, Type=OctetString, Value=
 * |25|1327451762,11,0,11,0,1|1327451763,11,0,11,0,1|1327451764,11,0,11,0,1|1327451765,11,0,11,0,1|1327451766,11,0,11,0,1|
 * 1327451767,11,0,11,0,1|1327451768,11,0,11,0,1|1327451769,11,0,11,0,1|1327451770,11,0,11,0,1|1327451771,11,0,11,0,1|
 * 1327451772,11,0,11,0,1|1327451773,11,0,11,0,1|1327451774,11,0,11,0,1|1327451775,11,0,11,0,1|1327451776,11,0,11,0,1|
 * 1327451777,11,0,11,0,1|1327451778,11,0,11,0,1|1327451779,11,0,11,0,1|1327451780,11,0,11,0,1|1327451781,11,0,11,0,1|
 * 1327451782,11,0,11,0,1|1327451783,11,0,11,0,1|1327451784,11,0,11,0,1|1327451785,11,0,11,0,1|1327451786,11,0,11,0,1|</li>
 * </ul>
 *
 * <ul>
 * <li>timestamp (epoch)</li>
 * <li>delay local-remote ~ current inbound-delay</li>
 * <li>jitter local-remote ~ current inbound-jitter</li>
 * <li>delay remote-local ~ current outbound-delay</li>
 * <li>jitter remote-local ~ current outbound-jitter-</li>
 * <li>timesync status (1 = good, time is synced, 0 = bad, out-of sync)</li>
 * </ul>
 *
 * @param tracker the tracker
 * @throws Exception the exception
 */
private void process(TcaData tracker, CollectionSetBuilder builder) {
    LOG.debug("process: processing raw TCA data for {} peers.", tracker.size());
    final NodeLevelResource nodeResource = new NodeLevelResource(m_agent.getNodeId());
    long timestamp = 0;
    for (TcaDataEntry entry : tracker.getEntries()) {
        GenericTypeResource resource = new GenericTypeResource(nodeResource, m_resourceType, entry.getPeerAddress());
        CollectionResource collectionResource = CollectionSetBuilder.toCollectionResource(resource, m_agent);
        long lastTimestamp = getLastTimestamp(collectionResource);
        String[] rawData = entry.getRawData().split("\\|");
        int samples = Integer.parseInt(rawData[1]);
        SnmpObjId entryObjId = SnmpObjId.get(".1.3.6.1.4.1.27091.3.1.6.1.2", entry.getInstance().toString());
        String identifierPrefix = String.format("TCA_%s_", entryObjId);
        for (int i = 0; i < samples; i++) {
            LOG.debug("process: processing row {}: {}", i, rawData[2 + i]);
            String[] rawEntry = rawData[2 + i].split(",");
            timestamp = Long.parseLong(rawEntry[0]);
            if (timestamp > lastTimestamp) {
                resource = new GenericTypeResource(nodeResource, m_resourceType, entry.getPeerAddress());
                resource.setTimestamp(new Date(timestamp * 1000));
                builder.withIdentifiedNumericAttribute(resource, RESOURCE_TYPE_NAME, INBOUND_DELAY, Double.parseDouble(rawEntry[1]), AttributeType.GAUGE, identifierPrefix + INBOUND_DELAY);
                builder.withIdentifiedNumericAttribute(resource, RESOURCE_TYPE_NAME, INBOUND_JITTER, Double.parseDouble(rawEntry[2]), AttributeType.GAUGE, identifierPrefix + INBOUND_JITTER);
                builder.withIdentifiedNumericAttribute(resource, RESOURCE_TYPE_NAME, OUTBOUND_DELAY, Double.parseDouble(rawEntry[3]), AttributeType.GAUGE, identifierPrefix + OUTBOUND_DELAY);
                builder.withIdentifiedNumericAttribute(resource, RESOURCE_TYPE_NAME, OUTBOUND_JITTER, Double.parseDouble(rawEntry[4]), AttributeType.GAUGE, identifierPrefix + OUTBOUND_JITTER);
                builder.withIdentifiedNumericAttribute(resource, RESOURCE_TYPE_NAME, TIMESYNC_STATUS, Double.parseDouble(rawEntry[5]), AttributeType.GAUGE, identifierPrefix + TIMESYNC_STATUS);
            } else {
                LOG.debug("process: skipping row {} {} because it was already processed.", i, rawData[2 + i]);
            }
        }
        setLastTimestamp(collectionResource, timestamp);
    }
}
Also used : CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) Date(java.util.Date)

Aggregations

NodeLevelResource (org.opennms.netmgt.collection.support.builder.NodeLevelResource)28 CollectionSetBuilder (org.opennms.netmgt.collection.support.builder.CollectionSetBuilder)18 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)10 GenericTypeResource (org.opennms.netmgt.collection.support.builder.GenericTypeResource)10 Test (org.junit.Test)8 CollectionAgent (org.opennms.netmgt.collection.api.CollectionAgent)8 DeferredGenericTypeResource (org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource)8 Resource (org.opennms.netmgt.collection.support.builder.Resource)8 InterfaceLevelResource (org.opennms.netmgt.collection.support.builder.InterfaceLevelResource)7 Date (java.util.Date)5 AttributeType (org.opennms.netmgt.collection.api.AttributeType)5 ResourcePath (org.opennms.netmgt.model.ResourcePath)5 HashMap (java.util.HashMap)4 List (java.util.List)3 ResourceType (org.opennms.netmgt.collection.api.ResourceType)3 File (java.io.File)2 MalformedURLException (java.net.MalformedURLException)2 RemoteException (java.rmi.RemoteException)2 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2