use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.
the class DefaultDistributedStatusService method calculateCurrentStatus.
/**
* <p>calculateCurrentStatus</p>
*
* @param monitor a {@link org.opennms.netmgt.model.OnmsLocationMonitor} object.
* @param applicationServices a {@link java.util.Collection} object.
* @param statuses a {@link java.util.Collection} object.
* @return a {@link org.opennms.web.svclayer.support.DefaultDistributedStatusService.Severity} object.
*/
public Severity calculateCurrentStatus(OnmsLocationMonitor monitor, Collection<OnmsMonitoredService> applicationServices, Collection<OnmsLocationSpecificStatus> statuses) {
Set<PollStatus> pollStatuses = new HashSet<>();
for (OnmsMonitoredService service : applicationServices) {
boolean foundIt = false;
for (OnmsLocationSpecificStatus status : statuses) {
if (status.getMonitoredService().equals(service) && status.getLocationMonitor().equals(monitor)) {
pollStatuses.add(status.getPollResult());
foundIt = true;
break;
}
}
if (!foundIt) {
pollStatuses.add(PollStatus.unknown("No status found for this service"));
LOG.debug("Did not find status for service {} in application. Setting status for it to unknown.", service);
}
}
return calculateStatus(pollStatuses);
}
use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.
the class DefaultRtcService method getNodeListForCriteria.
/**
* {@inheritDoc}
*/
@Override
public RtcNodeModel getNodeListForCriteria(OnmsCriteria serviceCriteria, OnmsCriteria outageCriteria) {
serviceCriteria.addOrder(Order.asc("node.label"));
serviceCriteria.addOrder(Order.asc("node.id"));
serviceCriteria.addOrder(Order.asc("ipInterface.ipAddress"));
serviceCriteria.addOrder(Order.asc("serviceType.name"));
Date periodEnd = new Date(System.currentTimeMillis());
Date periodStart = new Date(periodEnd.getTime() - (24 * 60 * 60 * 1000));
Disjunction disjunction = Restrictions.disjunction();
disjunction.add(Restrictions.isNull("ifRegainedService"));
disjunction.add(Restrictions.ge("ifLostService", periodStart));
disjunction.add(Restrictions.ge("ifRegainedService", periodStart));
outageCriteria.add(disjunction);
outageCriteria.addOrder(Order.asc("monitoredService"));
outageCriteria.addOrder(Order.asc("ifLostService"));
List<OnmsMonitoredService> services = m_monitoredServiceDao.findMatching(serviceCriteria);
List<OnmsOutage> outages = m_outageDao.findMatching(outageCriteria);
Map<OnmsMonitoredService, Long> serviceDownTime = calculateServiceDownTime(periodEnd, periodStart, outages);
RtcNodeModel model = new RtcNodeModel();
OnmsNode lastNode = null;
int serviceCount = 0;
int serviceDownCount = 0;
long downMillisCount = 0;
for (OnmsMonitoredService service : services) {
if (!service.getIpInterface().getNode().equals(lastNode) && lastNode != null) {
Double availability = calculateAvailability(serviceCount, downMillisCount, periodEnd.getTime() - periodStart.getTime());
model.addNode(new RtcNode(lastNode, serviceCount, serviceDownCount, availability));
serviceCount = 0;
serviceDownCount = 0;
downMillisCount = 0;
}
serviceCount++;
if (service.isDown()) {
serviceDownCount++;
}
Long downMillis = serviceDownTime.get(service);
if (downMillis == null) {
// This service had 100% availability over the period, no downtime
} else {
downMillisCount += downMillis;
}
lastNode = service.getIpInterface().getNode();
}
if (lastNode != null) {
Double availability = calculateAvailability(serviceCount, downMillisCount, periodEnd.getTime() - periodStart.getTime());
model.addNode(new RtcNode(lastNode, serviceCount, serviceDownCount, availability));
}
return model;
}
use of org.opennms.netmgt.model.OnmsMonitoredService 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.model.OnmsMonitoredService in project opennms by OpenNMS.
the class DefaultRtcService method calculateServiceDownTime.
private static Map<OnmsMonitoredService, Long> calculateServiceDownTime(Date periodEnd, Date periodStart, List<OnmsOutage> outages) {
Map<OnmsMonitoredService, Long> map = new HashMap<OnmsMonitoredService, Long>();
for (OnmsOutage outage : outages) {
if (map.get(outage.getMonitoredService()) == null) {
map.put(outage.getMonitoredService(), 0L);
}
Date begin;
if (outage.getIfLostService().before(periodStart)) {
begin = periodStart;
} else if (outage.getIfLostService().after(periodEnd)) {
LoggerFactory.getLogger(DefaultRtcService.class).warn("Outage beginning is after period end {}, discarding outage: {}", periodEnd, outage.toString());
continue;
} else {
begin = outage.getIfLostService();
}
Date end;
if (outage.getIfRegainedService() == null) {
// If the outage hasn't ended yet, use the end of the period as the end time
end = periodEnd;
} else if (outage.getIfRegainedService().after(periodEnd)) {
// If the outage ended after the end of the period, use the end of the period as the end time
end = periodEnd;
} else {
end = outage.getIfRegainedService();
}
if (begin.after(end)) {
LoggerFactory.getLogger(DefaultRtcService.class).warn("Outage beginning is after outage end inside period {} to {}, discarding outage: {}", periodStart, periodEnd, outage.toString());
continue;
} else {
Long count = map.get(outage.getMonitoredService());
count += (end.getTime() - begin.getTime());
map.put(outage.getMonitoredService(), count);
}
}
return map;
}
use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.
the class AvailCalculatorTest method testNotAvailabileDuringTimeChunk.
@Test
public void testNotAvailabileDuringTimeChunk() {
Date endTime = new Date(System.currentTimeMillis());
Date startTime = new Date(endTime.getTime() - 100);
TimeChunker chunker = new TimeChunker((int) (endTime.getTime() - startTime.getTime()), startTime, endTime);
AvailCalculator calculator = new AvailCalculator(chunker);
calculator.onStatusChange(createStatusChange(PollStatus.unavailable(), new Date(endTime.getTime() - 150)));
calculator.onStatusChange(createStatusChange(PollStatus.available(), new Date(endTime.getTime() + 50)));
Collection<OnmsMonitoredService> svcs = getServices();
double uptimePercent = calculator.getAvailabilityFor(svcs, 0);
assertEquals(0.0, uptimePercent, 0.00);
}
Aggregations