use of org.opennms.netmgt.xml.rtc.Category in project opennms by OpenNMS.
the class AvailabilityServiceIT method categoryIsFullyAvailableWhenNoServicesArePresent.
@Test
public void categoryIsFullyAvailableWhenNoServicesArePresent() throws Exception {
final RTCCategory rtcCat = EasyMock.createNiceMock(RTCCategory.class);
EasyMock.expect(rtcCat.getLabel()).andReturn("Routers");
// This nodeid should not exist in the database
EasyMock.expect(rtcCat.getNodes()).andReturn(Lists.newArrayList(99999));
EasyMock.replay(rtcCat);
final EuiLevel euiLevel = m_availabilityService.getEuiLevel(rtcCat);
assertEquals(1, euiLevel.getCategory().size());
final Category category = euiLevel.getCategory().get(0);
assertEquals(100.0, category.getCatvalue(), 0.001);
assertEquals(1, category.getNode().size());
final Node node = category.getNode().get(0);
assertEquals(100.0, node.getNodevalue(), 0.001);
assertEquals(0, node.getNodesvccount());
assertEquals(0, node.getNodesvcdowncount());
}
use of org.opennms.netmgt.xml.rtc.Category in project opennms by OpenNMS.
the class AvailabilityServiceIT method canCalculateAvailability.
@Test
public void canCalculateAvailability() throws Exception {
final MockNetwork mockNetwork = new MockNetwork();
// This test depends on the specifics in the standard network definition
mockNetwork.createStandardNetwork();
m_mockDatabase.populate(mockNetwork);
final RTCCategory rtcCat = EasyMock.createNiceMock(RTCCategory.class);
EasyMock.expect(rtcCat.getLabel()).andReturn("NOC").anyTimes();
EasyMock.expect(rtcCat.getNodes()).andReturn(Lists.newArrayList(1, 2)).anyTimes();
EasyMock.replay(rtcCat);
// Verify the availability when no outages are present
EuiLevel euiLevel = m_availabilityService.getEuiLevel(rtcCat);
assertEquals(1, euiLevel.getCategory().size());
Category category = euiLevel.getCategory().get(0);
assertEquals(100.0, category.getCatvalue(), 0.001);
assertEquals(2, category.getNode().size());
// Assumes the nodes are sorted
assertEquals(4, category.getNode().get(0).getNodesvccount());
assertEquals(2, category.getNode().get(1).getNodesvccount());
// Create an outage that is both open and closed within the window
final Date now = new Date();
final Date oneHourAgo = new Date(now.getTime() - (60 * 60 * 1000));
final Date thirtyMinutesAgo = new Date(now.getTime() - (30 * 60 * 1000));
final OnmsMonitoredService icmpService = toMonitoredService(mockNetwork.getService(1, "192.168.1.1", "ICMP"));
OnmsOutage outage = new OnmsOutage();
outage.setMonitoredService(icmpService);
outage.setIfLostService(oneHourAgo);
outage.setIfRegainedService(thirtyMinutesAgo);
m_outageDao.save(outage);
m_outageDao.flush();
// Verify the availability when outages are present
euiLevel = m_availabilityService.getEuiLevel(rtcCat);
assertEquals(1, euiLevel.getCategory().size());
category = euiLevel.getCategory().get(0);
// This number should only need to be adjusted if the duration of the outage
// or the number of services in the category changes
assertEquals(RTCUtils.getOutagePercentage(1800000, 86400000, 6), category.getCatvalue(), 0.0001);
assertEquals(2, category.getNode().size());
}
use of org.opennms.netmgt.xml.rtc.Category in project opennms by OpenNMS.
the class AvailabilityServiceHibernateImpl method getEuiLevel.
/**
* Optimized method for calculating the category statistics.
*
* We start off by retrieving outages affecting the nodes and services
* in the given category, and group these by node id.
*
* Using the outages, we calculate node-level statistics
* and tally the values to calculate the category statistics.
*/
@Override
@Transactional(readOnly = true)
public synchronized EuiLevel getEuiLevel(RTCCategory category) {
final Header header = new Header();
header.setVer("1.9a");
header.setMstation("");
// current time
final Date curDate = new Date();
final long curTime = curDate.getTime();
// get the rolling window
final long rWindow = 24L * 60L * 60L * 1000L;
LOG.debug("Retrieving availability statistics for {} with current date: {} and rolling window: {}", category.getLabel(), curDate, rWindow);
// create the data
final EuiLevel level = new EuiLevel();
// set created in m_header and add to level
header.setCreated(EventConstants.formatToString(curDate));
level.setHeader(header);
final Category levelCat = new Category();
// category label
levelCat.setCatlabel(category.getLabel());
double outageTimeInCategory = 0.0;
int numServicesInCategory = 0;
// window bounds
final Date windowStart = new Date(curTime - rWindow);
final Date windowEnd = new Date(curTime);
// category specifics
final List<Integer> nodeIds = getNodes(category);
final List<String> serviceNames = category.getServices();
// retrieve the outages associated with the given nodes, only retrieving those that affect our window
final Map<Integer, List<OnmsOutage>> outagesByNode = getOutages(nodeIds, serviceNames, windowStart, windowEnd);
// calculate the node level statistics
for (final int nodeId : nodeIds) {
List<OnmsOutage> outages = outagesByNode.get(nodeId);
if (outages == null) {
outages = Lists.newArrayList();
}
// sum the outage time
final double outageTime = getOutageTimeInWindow(outages, windowStart, windowEnd);
// determine the number of services
final int numServices = getNumServices(nodeId, serviceNames);
// count the number of outstanding outages
final long numServicesDown = outages.stream().filter(outage -> outage.getIfRegainedService() == null).count();
final Node levelNode = new Node();
levelNode.setNodeid(nodeId);
// value for this node for this category
levelNode.setNodevalue(RTCUtils.getOutagePercentage(outageTime, rWindow, numServices));
// node service count
levelNode.setNodesvccount(numServices);
// node service down count
levelNode.setNodesvcdowncount(numServicesDown);
// add the node
levelCat.getNode().add(levelNode);
// update the category statistics
numServicesInCategory += numServices;
outageTimeInCategory += outageTime;
}
// calculate the outage percentage using tallied values
levelCat.setCatvalue(RTCUtils.getOutagePercentage(outageTimeInCategory, rWindow, numServicesInCategory));
// add category
level.getCategory().add(levelCat);
LOG.debug("Done retrieving availability statistics for {} with {} services.", category.getLabel(), numServicesInCategory);
return level;
}
Aggregations