use of org.opennms.netmgt.model.AttributeStatistic in project opennms by OpenNMS.
the class BottomNAttributeStatisticVisitor method visit.
/** {@inheritDoc} */
@Override
public void visit(OnmsAttribute attribute, double statistic) {
Assert.notNull(attribute, "attribute argument must not be null");
m_results.add(new AttributeStatistic(attribute, statistic));
}
use of org.opennms.netmgt.model.AttributeStatistic in project opennms by OpenNMS.
the class TopNAttributeStatisticVisitorTest method testVisitGetResultsLimitedByCount.
public void testVisitGetResultsLimitedByCount() throws Exception {
BottomNAttributeStatisticVisitor visitor = new TopNAttributeStatisticVisitor();
visitor.setCount(20);
visitor.afterPropertiesSet();
Map<OnmsAttribute, Double> attributes = new HashMap<OnmsAttribute, Double>();
for (int i = 0; i < 100; i++) {
attributes.put(new MockAttribute("foo"), 0.0 + i);
}
OnmsResource resource = new OnmsResource("1", "Node One", new MockResourceType(), attributes.keySet(), ResourcePath.get("foo"));
resource.getAttributes();
for (Entry<OnmsAttribute, Double> entry : attributes.entrySet()) {
visitor.visit(entry.getKey(), entry.getValue());
}
SortedSet<AttributeStatistic> top = visitor.getResults();
assertNotNull("topN list should not be null", top);
assertEquals("topN list size", 20, top.size());
int i = 0;
for (AttributeStatistic stat : top) {
assertEquals("topN[" + i + "] value", 99.0 - i, stat.getStatistic());
i++;
}
}
use of org.opennms.netmgt.model.AttributeStatistic in project opennms by OpenNMS.
the class DatabaseReportPersister method persist.
/** {@inheritDoc} */
@Override
public void persist(ReportInstance report) {
StatisticsReport dbReport = new StatisticsReport();
dbReport.setName(report.getName());
dbReport.setDescription(report.getDescription());
dbReport.setStartDate(new Date(report.getStartTime()));
dbReport.setEndDate(new Date(report.getEndTime()));
dbReport.setJobStartedDate(report.getJobStartedDate());
dbReport.setJobCompletedDate(report.getJobCompletedDate());
dbReport.setPurgeDate(new Date(report.getJobCompletedDate().getTime() + report.getRetainInterval()));
for (AttributeStatistic stat : report.getResults()) {
ResourceReference resource = getResourceReference(stat.getAttribute().getResource().getId().toString());
StatisticsReportData data = new StatisticsReportData();
data.setResource(resource);
data.setReport(dbReport);
data.setValue(stat.getStatistic());
dbReport.addData(data);
LOG.debug("Adding {}", data);
}
if (dbReport.getData().isEmpty()) {
LOG.warn("Cannot store {} because it doesn't contain data. Probably all the metrics are NaN for the report period.", report);
} else {
m_statisticsReportDao.save(dbReport);
}
}
use of org.opennms.netmgt.model.AttributeStatistic in project opennms by OpenNMS.
the class TopNAttributeStatisticVisitorTest method testVisitGetResultsSameValue.
public void testVisitGetResultsSameValue() throws Exception {
BottomNAttributeStatisticVisitor visitor = new TopNAttributeStatisticVisitor();
visitor.setCount(20);
visitor.afterPropertiesSet();
Map<OnmsAttribute, Double> attributes = new HashMap<OnmsAttribute, Double>();
for (int i = 0; i < 5; i++) {
attributes.put(new MockAttribute("foo"), 0.0);
}
OnmsResource resource = new OnmsResource("1", "Node One", new MockResourceType(), attributes.keySet(), ResourcePath.get("foo"));
resource.getAttributes();
for (Entry<OnmsAttribute, Double> entry : attributes.entrySet()) {
visitor.visit(entry.getKey(), entry.getValue());
}
SortedSet<AttributeStatistic> top = visitor.getResults();
assertNotNull("topN list should not be null", top);
assertEquals("topN list size", 5, top.size());
int i = 0;
for (AttributeStatistic stat : top) {
assertEquals("topN[" + i + "] value", 0.0, stat.getStatistic());
i++;
}
}
use of org.opennms.netmgt.model.AttributeStatistic in project opennms by OpenNMS.
the class TopNAttributeStatisticVisitorTest method testVisitGetResultsDifferentValues.
public void testVisitGetResultsDifferentValues() throws Exception {
BottomNAttributeStatisticVisitor visitor = new TopNAttributeStatisticVisitor();
visitor.setCount(20);
visitor.afterPropertiesSet();
Map<OnmsAttribute, Double> attributes = new HashMap<OnmsAttribute, Double>();
for (int i = 0; i < 5; i++) {
attributes.put(new MockAttribute("foo"), 0.0 + i);
}
OnmsResource resource = new OnmsResource("1", "Node One", new MockResourceType(), attributes.keySet(), ResourcePath.get("foo"));
resource.getAttributes();
for (Entry<OnmsAttribute, Double> entry : attributes.entrySet()) {
visitor.visit(entry.getKey(), entry.getValue());
}
SortedSet<AttributeStatistic> top = visitor.getResults();
assertNotNull("topN list should not be null", top);
assertEquals("topN list size", 5, top.size());
int i = 0;
for (AttributeStatistic stat : top) {
assertEquals("topN[" + i + "] value", 4.0 - i, stat.getStatistic());
i++;
}
}
Aggregations