Search in sources :

Example 1 with RrdStatisticAttributeVisitor

use of org.opennms.netmgt.dao.support.RrdStatisticAttributeVisitor in project opennms by OpenNMS.

the class StatsdValuesIT method testValue.

@Test
@Transactional
public void testValue() throws Exception {
    final OnmsNode node = new OnmsNode(m_locationDao.getDefaultLocation(), "node1");
    node.setId(1);
    m_nodeDao.save(node);
    m_nodeDao.flush();
    final OnmsResource resource = Iterables.getOnlyElement(m_resourceDao.getResourceForNode(node).getChildResources());
    final OnmsAttribute attribute = resource.getRrdGraphAttributes().get("ifInOctets");
    final double statistic = m_rrdDao.getPrintValue(attribute, "AVERAGE", 1414602000000L, 1417046400000L);
    final TopNAttributeStatisticVisitor result = new TopNAttributeStatisticVisitor();
    result.setCount(1);
    final RrdStatisticAttributeVisitor visitor = new RrdStatisticAttributeVisitor();
    visitor.setFetchStrategy(m_fetchStrategy);
    visitor.setConsolidationFunction("AVERAGE");
    visitor.setStartTime(1414602000000L);
    visitor.setEndTime(1417046400000L);
    visitor.setStatisticVisitor(result);
    visitor.afterPropertiesSet();
    visitor.visit(attribute);
    Assert.assertNotNull(result.getResults());
    Assert.assertEquals(1, result.getResults().size());
    Assert.assertNotNull(result.getResults().first());
    Assert.assertEquals(attribute, result.getResults().first().getAttribute());
    Assert.assertEquals(statistic, result.getResults().first().getStatistic(), 0.5);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsResource(org.opennms.netmgt.model.OnmsResource) TopNAttributeStatisticVisitor(org.opennms.netmgt.dao.support.TopNAttributeStatisticVisitor) RrdStatisticAttributeVisitor(org.opennms.netmgt.dao.support.RrdStatisticAttributeVisitor) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Test (org.junit.Test)1 RrdStatisticAttributeVisitor (org.opennms.netmgt.dao.support.RrdStatisticAttributeVisitor)1 TopNAttributeStatisticVisitor (org.opennms.netmgt.dao.support.TopNAttributeStatisticVisitor)1 OnmsAttribute (org.opennms.netmgt.model.OnmsAttribute)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 OnmsResource (org.opennms.netmgt.model.OnmsResource)1 Transactional (org.springframework.transaction.annotation.Transactional)1