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;
}
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);
}
Aggregations