Search in sources :

Example 1 with AttributeStatistic

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));
}
Also used : AttributeStatistic(org.opennms.netmgt.model.AttributeStatistic)

Example 2 with AttributeStatistic

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++;
    }
}
Also used : HashMap(java.util.HashMap) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) OnmsResource(org.opennms.netmgt.model.OnmsResource) AttributeStatistic(org.opennms.netmgt.model.AttributeStatistic) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Example 3 with AttributeStatistic

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);
    }
}
Also used : StatisticsReport(org.opennms.netmgt.model.StatisticsReport) AttributeStatistic(org.opennms.netmgt.model.AttributeStatistic) StatisticsReportData(org.opennms.netmgt.model.StatisticsReportData) ResourceReference(org.opennms.netmgt.model.ResourceReference) Date(java.util.Date)

Example 4 with AttributeStatistic

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++;
    }
}
Also used : HashMap(java.util.HashMap) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) OnmsResource(org.opennms.netmgt.model.OnmsResource) AttributeStatistic(org.opennms.netmgt.model.AttributeStatistic) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Example 5 with AttributeStatistic

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++;
    }
}
Also used : HashMap(java.util.HashMap) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) OnmsResource(org.opennms.netmgt.model.OnmsResource) AttributeStatistic(org.opennms.netmgt.model.AttributeStatistic) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Aggregations

AttributeStatistic (org.opennms.netmgt.model.AttributeStatistic)7 HashMap (java.util.HashMap)4 MockResourceType (org.opennms.netmgt.mock.MockResourceType)4 OnmsAttribute (org.opennms.netmgt.model.OnmsAttribute)4 OnmsResource (org.opennms.netmgt.model.OnmsResource)4 Date (java.util.Date)2 ResourceReference (org.opennms.netmgt.model.ResourceReference)1 StatisticsReport (org.opennms.netmgt.model.StatisticsReport)1 StatisticsReportData (org.opennms.netmgt.model.StatisticsReportData)1