use of org.opennms.netmgt.model.RrdGraphAttribute in project opennms by OpenNMS.
the class RrdResourceAttributeUtils method loadRrdAttributes.
private static void loadRrdAttributes(File rrdDirectory, String relativePath, Set<OnmsAttribute> attributes, final String rrdFileSuffix) {
int suffixLength = rrdFileSuffix.length();
File resourceDir = new File(rrdDirectory, relativePath);
FilenameFilter filter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(rrdFileSuffix);
}
};
File[] files = resourceDir.listFiles(filter);
if (files == null) {
return;
}
for (final File file : files) {
String fileName = file.getName();
if (ResourceTypeUtils.isStoreByGroup() && !ResourceTypeUtils.isResponseTime(relativePath)) {
String groupName = fileName.substring(0, fileName.length() - suffixLength);
Properties props = getDsProperties(resourceDir);
for (Object o : props.keySet()) {
String dsName = (String) o;
if (props.getProperty(dsName).equals(groupName)) {
attributes.add(new RrdGraphAttribute(dsName, relativePath, fileName));
}
}
} else {
String dsName = fileName.substring(0, fileName.length() - suffixLength);
attributes.add(new RrdGraphAttribute(dsName, relativePath, fileName));
}
}
}
use of org.opennms.netmgt.model.RrdGraphAttribute in project opennms by OpenNMS.
the class RrdStatisticAttributeVisitor method visit.
/** {@inheritDoc} */
@Override
public void visit(OnmsAttribute attribute) {
if (!RrdGraphAttribute.class.isAssignableFrom(attribute.getClass())) {
// Nothing to do if we can't cast to an RrdGraphAttribute
return;
}
final Source source = new Source();
source.setLabel("result");
source.setResourceId(attribute.getResource().getId().toString());
source.setAttribute(attribute.getName());
source.setAggregation(m_consolidationFunction.toUpperCase());
final FetchResults results;
try {
results = m_fetchStrategy.fetch(m_startTime, m_endTime, 1, 0, null, null, Collections.singletonList(source), false);
} catch (final Exception e) {
LOG.warn("Failed to fetch statistic: {}", source, e);
return;
}
if (results == null) {
LOG.warn("No statistic found: {}", source);
return;
}
final double[] statistics = results.getColumns().get(source.getLabel());
if (statistics == null || statistics.length == 0) {
LOG.warn("Statistic is empty: {}", source);
return;
}
final Aggregator aggregator = Aggregators.valueOf(m_consolidationFunction.toUpperCase()).get();
Arrays.stream(statistics).filter(v -> (!Double.isNaN(v))).forEach(v -> {
LOG.debug("Aggregating: {}", v);
aggregator.aggregate(v);
});
double statistic = aggregator.getValue();
LOG.debug("The value of {} is {}", attribute, statistic);
/*
* We don't want to do anything with NaN data, since
* it means there is no data. We especially want to
* stay away from it, because it will be sorted as
* being higher than any numeric value, which will
* leave our TopN report with most, if not all NaN
* values at the top.
*/
if (Double.isNaN(statistic)) {
return;
}
m_statisticVisitor.visit(attribute, statistic);
}
use of org.opennms.netmgt.model.RrdGraphAttribute in project opennms by OpenNMS.
the class RrdStatisticAttributeVisitorTest method testVisitWithRrdAttribute.
public void testVisitWithRrdAttribute() throws Exception {
RrdStatisticAttributeVisitor attributeVisitor = new RrdStatisticAttributeVisitor();
attributeVisitor.setFetchStrategy(m_fetchStrategy);
attributeVisitor.setConsolidationFunction("AVERAGE");
attributeVisitor.setStartTime(m_startTime);
attributeVisitor.setEndTime(m_endTime);
attributeVisitor.setStatisticVisitor(m_statisticVisitor);
attributeVisitor.afterPropertiesSet();
MockResourceType resourceType = new MockResourceType();
resourceType.setName("interfaceSnmp");
OnmsAttribute attribute = new RrdGraphAttribute("ifInOctets", "something", "something else");
attribute.setResource(new OnmsResource("1", "Node One", resourceType, Collections.singleton(attribute), ResourcePath.get("foo")));
Source source = new Source();
source.setLabel("result");
source.setResourceId(attribute.getResource().getId().toString());
source.setAttribute(attribute.getName());
source.setAggregation(attributeVisitor.getConsolidationFunction().toUpperCase());
FetchResults results = new FetchResults(new long[] { m_startTime }, Collections.singletonMap("result", new double[] { 1.0 }), m_endTime - m_startTime, Collections.emptyMap());
expect(m_fetchStrategy.fetch(m_startTime, m_endTime, 1, 0, null, null, Collections.singletonList(source), false)).andReturn(results);
m_statisticVisitor.visit(attribute, 1.0);
m_mocks.replayAll();
attributeVisitor.visit(attribute);
m_mocks.verifyAll();
}
use of org.opennms.netmgt.model.RrdGraphAttribute in project opennms by OpenNMS.
the class RrdStatisticAttributeVisitorTest method testVisitWithNotANumberRrdAttribute.
public void testVisitWithNotANumberRrdAttribute() throws Exception {
RrdStatisticAttributeVisitor attributeVisitor = new RrdStatisticAttributeVisitor();
attributeVisitor.setFetchStrategy(m_fetchStrategy);
attributeVisitor.setConsolidationFunction("AVERAGE");
attributeVisitor.setStartTime(m_startTime);
attributeVisitor.setEndTime(m_endTime);
attributeVisitor.setStatisticVisitor(m_statisticVisitor);
attributeVisitor.afterPropertiesSet();
MockResourceType resourceType = new MockResourceType();
resourceType.setName("somethingOtherThanInterfaceSnmp");
OnmsAttribute attribute = new RrdGraphAttribute("ifInOctets", "something", "something else");
attribute.setResource(new OnmsResource("1", "Node One", resourceType, Collections.singleton(attribute), ResourcePath.get("foo")));
Source source = new Source();
source.setLabel("result");
source.setResourceId(attribute.getResource().getId().toString());
source.setAttribute(attribute.getName());
source.setAggregation(attributeVisitor.getConsolidationFunction().toUpperCase());
FetchResults results = new FetchResults(new long[] {}, Collections.singletonMap("result", new double[] {}), m_endTime - m_startTime, Collections.emptyMap());
expect(m_fetchStrategy.fetch(m_startTime, m_endTime, 1, 0, null, null, Collections.singletonList(source), false)).andReturn(results);
m_mocks.replayAll();
attributeVisitor.visit(attribute);
m_mocks.verifyAll();
}
use of org.opennms.netmgt.model.RrdGraphAttribute in project opennms by OpenNMS.
the class RrdStatisticAttributeVisitorTest method testVisitTwice.
public void testVisitTwice() throws Exception {
final RrdStatisticAttributeVisitor attributeVisitor1 = new RrdStatisticAttributeVisitor();
attributeVisitor1.setFetchStrategy(m_fetchStrategy);
attributeVisitor1.setConsolidationFunction("AVERAGE");
attributeVisitor1.setStartTime(m_startTime);
attributeVisitor1.setEndTime(m_endTime);
attributeVisitor1.setStatisticVisitor(m_statisticVisitor);
attributeVisitor1.afterPropertiesSet();
final RrdStatisticAttributeVisitor attributeVisitor2 = new RrdStatisticAttributeVisitor();
attributeVisitor2.setFetchStrategy(m_fetchStrategy);
attributeVisitor2.setConsolidationFunction("AVERAGE");
attributeVisitor2.setStartTime(m_startTime);
attributeVisitor2.setEndTime(m_endTime);
attributeVisitor2.setStatisticVisitor(m_statisticVisitor);
attributeVisitor2.afterPropertiesSet();
MockResourceType resourceType = new MockResourceType();
resourceType.setName("interfaceSnmp");
OnmsAttribute attribute = new RrdGraphAttribute("ifInOctets", "something", "something else");
attribute.setResource(new OnmsResource("1", "Node One", resourceType, Collections.singleton(attribute), ResourcePath.get("foo")));
Source source = new Source();
source.setLabel("result");
source.setResourceId(attribute.getResource().getId().toString());
source.setAttribute(attribute.getName());
source.setAggregation(attributeVisitor1.getConsolidationFunction().toUpperCase());
expect(m_fetchStrategy.fetch(m_startTime, m_endTime, 1, 0, null, null, Collections.singletonList(source), false)).andReturn(new FetchResults(new long[] { m_startTime }, Collections.singletonMap("result", new double[] { 1.0 }), m_endTime - m_startTime, Collections.emptyMap()));
m_statisticVisitor.visit(attribute, 1.0);
expect(m_fetchStrategy.fetch(m_startTime, m_endTime, 1, 0, null, null, Collections.singletonList(source), false)).andReturn(new FetchResults(new long[] { m_startTime }, Collections.singletonMap("result", new double[] { 2.0 }), m_endTime - m_startTime, Collections.emptyMap()));
m_statisticVisitor.visit(attribute, 2.0);
m_mocks.replayAll();
attributeVisitor1.visit(attribute);
attributeVisitor2.visit(attribute);
m_mocks.verifyAll();
}
Aggregations