Search in sources :

Example 1 with MetricType

use of org.opennms.newts.api.MetricType 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 MetricType

use of org.opennms.newts.api.MetricType in project opennms by OpenNMS.

the class NewtsConverter method toSample.

protected static Sample toSample(AbstractDS ds, Resource resource, Timestamp timestamp, double value) {
    final String metric = ds.getName();
    final MetricType type = ds.isCounter() ? MetricType.COUNTER : MetricType.GAUGE;
    final ValueType<?> valueType = ds.isCounter() ? new Counter(UnsignedLong.valueOf(BigDecimal.valueOf(value).toBigInteger())) : new Gauge(value);
    return new Sample(timestamp, resource, metric, type, valueType);
}
Also used : Counter(org.opennms.newts.api.Counter) Sample(org.opennms.newts.api.Sample) MetricType(org.opennms.newts.api.MetricType) Gauge(org.opennms.newts.api.Gauge)

Aggregations

MetricType (org.opennms.newts.api.MetricType)2 Sample (org.opennms.newts.api.Sample)2 CollectionAttributeType (org.opennms.netmgt.collection.api.CollectionAttributeType)1 ResourcePath (org.opennms.netmgt.model.ResourcePath)1 Counter (org.opennms.newts.api.Counter)1 Gauge (org.opennms.newts.api.Gauge)1 Resource (org.opennms.newts.api.Resource)1 Timestamp (org.opennms.newts.api.Timestamp)1