Search in sources :

Example 1 with CollectionAttributeType

use of org.opennms.netmgt.collection.api.CollectionAttributeType in project opennms by OpenNMS.

the class NewtsPersistOperationBuilder method getSamplesToInsert.

public List<Sample> getSamplesToInsert() {
    final List<Sample> samples = Lists.newLinkedList();
    ResourcePath path = ResourceTypeUtils.getResourcePathWithRepository(m_repository, ResourcePath.get(m_resource.getPath(), m_name));
    // Add extra attributes that can be used to walk the resource tree.
    NewtsUtils.addIndicesToAttributes(path, m_metaData);
    Resource resource = new Resource(NewtsUtils.toResourceId(path), Optional.of(m_metaData));
    // Convert numeric attributes to samples
    Timestamp timestamp = Timestamp.fromEpochMillis(m_timeKeeper.getCurrentTime());
    for (Entry<CollectionAttributeType, Number> entry : m_declarations.entrySet()) {
        CollectionAttributeType attrType = entry.getKey();
        MetricType type = mapType(attrType.getType());
        if (type == null) {
            // Skip attributes with no type
            continue;
        }
        Number value = entry.getValue();
        if (value == null) {
            // Skip attributes with no value (see NMS-8103)
            continue;
        }
        samples.add(new Sample(timestamp, m_context, resource, attrType.getName(), type, ValueType.compose(entry.getValue(), type)));
    }
    return samples;
}
Also used : ResourcePath(org.opennms.netmgt.model.ResourcePath) Sample(org.opennms.newts.api.Sample) MetricType(org.opennms.newts.api.MetricType) Resource(org.opennms.newts.api.Resource) CollectionAttributeType(org.opennms.netmgt.collection.api.CollectionAttributeType) Timestamp(org.opennms.newts.api.Timestamp)

Example 2 with CollectionAttributeType

use of org.opennms.netmgt.collection.api.CollectionAttributeType in project opennms by OpenNMS.

the class RrdPersistOperationBuilder method getDataSources.

private List<RrdDataSource> getDataSources() {
    List<RrdDataSource> dataSources = new ArrayList<RrdDataSource>(m_declarations.size());
    for (CollectionAttributeType attrDef : m_declarations.keySet()) {
        String minval = "U";
        String maxval = "U";
        if (attrDef instanceof NumericCollectionAttributeType) {
            minval = ((NumericCollectionAttributeType) attrDef).getMinval() != null ? ((NumericCollectionAttributeType) attrDef).getMinval() : "U";
            maxval = ((NumericCollectionAttributeType) attrDef).getMaxval() != null ? ((NumericCollectionAttributeType) attrDef).getMaxval() : "U";
        }
        final RrdAttributeType type = RrdPersistOperationBuilder.mapType(attrDef.getType());
        // If the type is supported by RRD...
        if (type != null) {
            if (attrDef.getName().length() > MAX_DS_NAME_LENGTH) {
                LOG.warn("Mib object name/alias '{}' exceeds 19 char maximum for RRD data source names, truncating.", attrDef.getName());
            }
            RrdDataSource rrdDataSource = new RrdDataSource(StringUtils.truncate(attrDef.getName(), RrdPersistOperationBuilder.MAX_DS_NAME_LENGTH), type, getRepository().getHeartBeat(), minval, maxval);
            dataSources.add(rrdDataSource);
        }
    }
    return dataSources;
}
Also used : RrdAttributeType(org.opennms.netmgt.rrd.RrdAttributeType) ArrayList(java.util.ArrayList) RrdDataSource(org.opennms.netmgt.rrd.RrdDataSource) NumericCollectionAttributeType(org.opennms.netmgt.collection.api.NumericCollectionAttributeType) CollectionAttributeType(org.opennms.netmgt.collection.api.CollectionAttributeType) NumericCollectionAttributeType(org.opennms.netmgt.collection.api.NumericCollectionAttributeType)

Example 3 with CollectionAttributeType

use of org.opennms.netmgt.collection.api.CollectionAttributeType in project opennms by OpenNMS.

the class RrdPersistOperationBuilder method getValues.

private String getValues() {
    boolean first = true;
    final StringBuilder values = new StringBuilder();
    for (Iterator<CollectionAttributeType> iter = m_declarations.keySet().iterator(); iter.hasNext(); ) {
        CollectionAttributeType attrDef = iter.next();
        Number value = m_declarations.get(attrDef);
        if (!first) {
            values.append(':');
        } else {
            first = false;
        }
        values.append(mapValue(value));
    }
    return values.toString();
}
Also used : CollectionAttributeType(org.opennms.netmgt.collection.api.CollectionAttributeType) NumericCollectionAttributeType(org.opennms.netmgt.collection.api.NumericCollectionAttributeType)

Aggregations

CollectionAttributeType (org.opennms.netmgt.collection.api.CollectionAttributeType)3 NumericCollectionAttributeType (org.opennms.netmgt.collection.api.NumericCollectionAttributeType)2 ArrayList (java.util.ArrayList)1 ResourcePath (org.opennms.netmgt.model.ResourcePath)1 RrdAttributeType (org.opennms.netmgt.rrd.RrdAttributeType)1 RrdDataSource (org.opennms.netmgt.rrd.RrdDataSource)1 MetricType (org.opennms.newts.api.MetricType)1 Resource (org.opennms.newts.api.Resource)1 Sample (org.opennms.newts.api.Sample)1 Timestamp (org.opennms.newts.api.Timestamp)1