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();
}
};
}
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;
}
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);
}
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);
}
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());
}
}
}
Aggregations