Search in sources :

Example 31 with RrdGraphAttribute

use of org.opennms.netmgt.model.RrdGraphAttribute in project opennms by OpenNMS.

the class CustomSpringConfiguration method createResourceDao.

@Bean(name = "resourceDao")
public ResourceDao createResourceDao() {
    return new ResourceDao() {

        @Override
        public Collection<OnmsResourceType> getResourceTypes() {
            throw new UnsupportedOperationException();
        }

        @Override
        public List<OnmsResource> findTopLevelResources() {
            throw new UnsupportedOperationException();
        }

        @Override
        public OnmsResource getResourceById(ResourceId id) {
            if (id.toString().startsWith("node[1]")) {
                final OnmsResource onmsResource = new OnmsResource(id.toString(), id.toString(), new InterfaceSnmpResourceType(null), new HashSet<OnmsAttribute>(), new ResourcePath());
                if (id.toString().contains("interfaceSnmp[127.0.0.1]")) {
                    final RrdGraphAttribute attribute = new RrdGraphAttribute();
                    attribute.setName("ifInErrors");
                    attribute.setResource(onmsResource);
                    onmsResource.getAttributes().add(attribute);
                }
                return onmsResource;
            }
            return null;
        }

        @Override
        public OnmsResource getResourceForNode(OnmsNode node) {
            throw new UnsupportedOperationException();
        }

        @Override
        public OnmsResource getResourceForIpInterface(OnmsIpInterface ipInterface, OnmsLocationMonitor locationMonitor) {
            throw new UnsupportedOperationException();
        }

        @Override
        public boolean deleteResourceById(ResourceId resourceId) {
            throw new UnsupportedOperationException();
        }
    };
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) InterfaceSnmpResourceType(org.opennms.netmgt.dao.support.InterfaceSnmpResourceType) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourcePath(org.opennms.netmgt.model.ResourcePath) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsResourceType(org.opennms.netmgt.model.OnmsResourceType) ResourceId(org.opennms.netmgt.model.ResourceId) ResourceDao(org.opennms.netmgt.dao.api.ResourceDao) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) Bean(org.springframework.context.annotation.Bean)

Example 32 with RrdGraphAttribute

use of org.opennms.netmgt.model.RrdGraphAttribute in project opennms by OpenNMS.

the class NrtController method nrtStart.

public ModelAndView nrtStart(ResourceId resourceId, String report, HttpSession httpSession) {
    assert (resourceId != null);
    logger.debug("resourceId: '{}'", resourceId);
    assert (report != null);
    logger.debug("report: '{}'", report);
    OnmsResource reportResource = m_resourceDao.getResourceById(resourceId);
    PrefabGraph prefabGraph = m_graphDao.getPrefabGraph(report);
    String nrtCollectionTaskId = String.format("NrtCollectionTaskId_%d_%d", System.currentTimeMillis(), new Random().nextInt());
    List<CollectionJob> collectionJobs = createCollectionJobs(reportResource, prefabGraph, nrtCollectionTaskId);
    for (CollectionJob collectionJob : collectionJobs) {
        m_nrtBroker.publishCollectionJob(collectionJob);
        getCollectionJobMap(httpSession, true).put(nrtCollectionTaskId, collectionJob);
    }
    ModelAndView modelAndView = new ModelAndView("nrt/realtime.json");
    modelAndView.addObject("nrtCollectionTaskId", nrtCollectionTaskId);
    modelAndView.addObject("graphTitle", prefabGraph.getTitle());
    modelAndView.addObject("graphName", prefabGraph.getName());
    modelAndView.addObject("graphDescription", prefabGraph.getDescription());
    NrtHelper nrtHelper = new NrtHelper();
    modelAndView.addObject("rrdGraphString", nrtHelper.cleanUpRrdGraphStringForWebUi(prefabGraph, getRequiredExternalPropertyAttributes(reportResource, prefabGraph), getRequiredStringPropertyAttributes(reportResource, prefabGraph)));
    Set<RrdGraphAttribute> relevantRrdGraphAttributes = getRequiredRrdGraphAttributes(reportResource, prefabGraph);
    Map<String, String> rrdGraphAttributesMetaData = getMetaDataForReport(relevantRrdGraphAttributes);
    Map<String, String> rrdGraphAttributesToMetricIds = getRrdGraphAttributesToMetricIds(rrdGraphAttributesMetaData);
    modelAndView.addObject("metricsMapping", nrtHelper.generateJsMappingObject(prefabGraph.getCommand(), rrdGraphAttributesToMetricIds));
    return modelAndView;
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) PrefabGraph(org.opennms.netmgt.model.PrefabGraph) Random(java.util.Random) DefaultCollectionJob(org.opennms.nrtg.api.model.DefaultCollectionJob) CollectionJob(org.opennms.nrtg.api.model.CollectionJob) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute)

Example 33 with RrdGraphAttribute

use of org.opennms.netmgt.model.RrdGraphAttribute in project opennms by OpenNMS.

the class DefaultRrdDaoIntegrationTest method testPrintValue.

public void testPrintValue() throws Exception {
    long start = System.currentTimeMillis();
    long end = start + (24 * 60 * 60 * 1000);
    OnmsResource topResource = new OnmsResource("1", "Node One", new MockResourceType(), new HashSet<OnmsAttribute>(0), new ResourcePath("foo"));
    OnmsAttribute attribute = new RrdGraphAttribute("ifInOctets", "snmp/1/eth0", "ifInOctets.jrb");
    HashSet<OnmsAttribute> attributeSet = new HashSet<OnmsAttribute>(1);
    attributeSet.add(attribute);
    MockResourceType childResourceType = new MockResourceType();
    OnmsResource childResource = new OnmsResource("eth0", "Interface One: eth0", childResourceType, attributeSet, new ResourcePath("foo"));
    childResource.setParent(topResource);
    File snmp = m_fileAnticipator.tempDir(ResourceTypeUtils.SNMP_DIRECTORY);
    File node = m_fileAnticipator.tempDir(snmp, topResource.getName());
    File intf = m_fileAnticipator.tempDir(node, childResource.getName());
    RrdDataSource rrdDataSource = new RrdDataSource(attribute.getName(), RrdAttributeType.GAUGE, 600, "U", "U");
    RrdDef def = m_rrdStrategy.createDefinition("test", intf.getAbsolutePath(), attribute.getName(), 600, Collections.singletonList(rrdDataSource), Collections.singletonList("RRA:AVERAGE:0.5:1:100"));
    m_rrdStrategy.createFile(def);
    File rrdFile = m_fileAnticipator.expecting(intf, attribute.getName() + m_rrdStrategy.getDefaultFileExtension());
    RrdDb rrdFileObject = m_rrdStrategy.openFile(rrdFile.getAbsolutePath());
    for (int i = 0; i < 10; i++) {
        m_rrdStrategy.updateFile(rrdFileObject, "test", (start / 1000 + 300 * i) + ":1");
    }
    m_rrdStrategy.closeFile(rrdFileObject);
    Double value = m_dao.getPrintValue(childResource.getAttributes().iterator().next(), "AVERAGE", start, end);
    assertNotNull("value should not be null", value);
    assertEquals("value", 1.0, value);
}
Also used : RrdDef(org.jrobin.core.RrdDef) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourcePath(org.opennms.netmgt.model.ResourcePath) RrdDataSource(org.opennms.netmgt.rrd.RrdDataSource) RrdDb(org.jrobin.core.RrdDb) File(java.io.File) MockResourceType(org.opennms.netmgt.mock.MockResourceType) HashSet(java.util.HashSet)

Example 34 with RrdGraphAttribute

use of org.opennms.netmgt.model.RrdGraphAttribute in project opennms by OpenNMS.

the class DefaultRrdDaoTest method testFetchLastValue.

public void testFetchLastValue() throws Exception {
    String rrdDir = "snmp" + File.separator + "1" + File.separator + "eth0";
    String rrdFile = "ifInOctets.jrb";
    OnmsResource topResource = new OnmsResource("1", "Node One", new MockResourceType(), new HashSet<OnmsAttribute>(0), new ResourcePath("foo"));
    OnmsAttribute attribute = new RrdGraphAttribute("ifInOctets", rrdDir, rrdFile);
    HashSet<OnmsAttribute> attributeSet = new HashSet<OnmsAttribute>(1);
    attributeSet.add(attribute);
    MockResourceType childResourceType = new MockResourceType();
    OnmsResource childResource = new OnmsResource("eth0", "Interface One: eth0", childResourceType, attributeSet, new ResourcePath("foo"));
    childResource.setParent(topResource);
    int interval = 300000;
    Double expectedValue = new Double(1.0);
    String fullRrdFilePath = m_dao.getRrdBaseDirectory().getAbsolutePath() + File.separator + rrdDir + File.separator + rrdFile;
    expect(m_rrdStrategy.fetchLastValue(fullRrdFilePath, attribute.getName(), interval)).andReturn(expectedValue);
    m_mocks.replayAll();
    Double value = m_dao.getLastFetchValue(attribute, interval);
    m_mocks.verifyAll();
    assertNotNull("last fetched value must not be null, but was null", value);
    assertEquals("last fetched value", expectedValue, value);
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourcePath(org.opennms.netmgt.model.ResourcePath) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) MockResourceType(org.opennms.netmgt.mock.MockResourceType) HashSet(java.util.HashSet)

Example 35 with RrdGraphAttribute

use of org.opennms.netmgt.model.RrdGraphAttribute in project opennms by OpenNMS.

the class DefaultGraphResultsService method getAttributeFiles.

private void getAttributeFiles(Graph graph, List<String> filesToPromote) {
    Collection<RrdGraphAttribute> attrs = graph.getRequiredRrGraphdAttributes();
    final String rrdBaseDir = System.getProperty("rrd.base.dir");
    for (RrdGraphAttribute rrdAttr : attrs) {
        LOG.debug("getAttributeFiles: ResourceType, ParentResourceType = {}, {}", rrdAttr.getResource().getResourceType().getLabel(), rrdAttr.getResource().getParent().getResourceType().getLabel());
        if (rrdAttr.getResource().getParent().getResourceType().getLabel().equals("nodeSource")) {
            filesToPromote.add(rrdBaseDir + File.separator + ResourceTypeUtils.FOREIGN_SOURCE_DIRECTORY + File.separator + rrdAttr.getRrdRelativePath());
        } else {
            filesToPromote.add(rrdBaseDir + File.separator + rrdAttr.getRrdRelativePath());
        }
    }
}
Also used : RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute)

Aggregations

RrdGraphAttribute (org.opennms.netmgt.model.RrdGraphAttribute)36 OnmsResource (org.opennms.netmgt.model.OnmsResource)23 OnmsAttribute (org.opennms.netmgt.model.OnmsAttribute)21 MockResourceType (org.opennms.netmgt.mock.MockResourceType)16 HashSet (java.util.HashSet)11 Source (org.opennms.netmgt.measurements.model.Source)9 FetchResults (org.opennms.netmgt.measurements.api.FetchResults)8 ResourcePath (org.opennms.netmgt.model.ResourcePath)8 Map (java.util.Map)5 ExternalValueAttribute (org.opennms.netmgt.model.ExternalValueAttribute)5 OnmsNode (org.opennms.netmgt.model.OnmsNode)5 File (java.io.File)4 List (java.util.List)4 Test (org.junit.Test)4 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)4 ResourceId (org.opennms.netmgt.model.ResourceId)4 LinkedHashSet (java.util.LinkedHashSet)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Optional (com.google.common.base.Optional)2 Throwables (com.google.common.base.Throwables)2