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