use of org.opennms.web.rest.v1.AvailCalculator in project opennms by OpenNMS.
the class RemotePollerAvailabilityService method getAvailabilityList.
/**
*
* @param timeChunker
* @param sortedApplications
* @param selectedMonitors
* @param selectedNodes
* @return
*/
private OnmsLocationAvailDefinitionList getAvailabilityList(TimeChunker timeChunker, List<OnmsApplication> sortedApplications, Collection<OnmsLocationMonitor> selectedMonitors, Collection<OnmsNode> selectedNodes) {
OnmsLocationAvailDefinitionList availList = new OnmsLocationAvailDefinitionList();
List<String> names = new ArrayList<String>(sortedApplications.size());
for (OnmsApplication app : sortedApplications) {
names.add(app.getName());
}
Collection<OnmsLocationSpecificStatus> statusesPeriod = m_locationMonitorDao.getStatusChangesBetweenForApplications(timeChunker.getStartDate(), timeChunker.getEndDate(), names);
AvailCalculator availCalc = new AvailCalculator(timeChunker);
removeUnneededMonitors(statusesPeriod, selectedMonitors);
removeUnneededServices(statusesPeriod, selectedNodes);
for (OnmsLocationSpecificStatus statusChange : statusesPeriod) {
availCalc.onStatusChange(statusChange);
}
int counter = 0;
for (int i = 0; i < timeChunker.getSegmentCount(); i++) {
counter++;
TimeChunk timeChunk = timeChunker.getAt(i);
OnmsLocationAvailDataPoint point = new OnmsLocationAvailDataPoint();
point.setTime(timeChunk.getEndDate());
for (OnmsApplication application : sortedApplications) {
double percentage = availCalc.getAvailabilityFor(m_monitoredServiceDao.findByApplication(application), i);
String strPercent = new DecimalFormat("0.0").format(percentage * 100);
point.addAvailDefinition(new OnmsLocationAvailDefinition(application.getName(), strPercent));
}
availList.add(point);
}
System.err.println(new Date() + "After Calculations total loops: " + counter);
return availList;
}
use of org.opennms.web.rest.v1.AvailCalculator in project opennms by OpenNMS.
the class AvailCalculatorTest method testGetAvailabilityOneStatus.
@Test
public void testGetAvailabilityOneStatus() {
Date endTime = new Date(System.currentTimeMillis());
Date startTime = new Date(endTime.getTime() - 100);
PollStatus pollStatus = PollStatus.unavailable();
Date timestamp = new Date(endTime.getTime() - 50);
OnmsLocationSpecificStatus statusChange = createStatusChange(pollStatus, timestamp);
TimeChunker chunker = new TimeChunker((int) (endTime.getTime() - startTime.getTime()), startTime, endTime);
AvailCalculator calculator = new AvailCalculator(chunker);
calculator.onStatusChange(statusChange);
chunker.getNextSegment();
double uptimePercent = calculator.getAvailabilityFor(getServices(), 0);
assertEquals(0.5, uptimePercent, 0.00);
}
use of org.opennms.web.rest.v1.AvailCalculator in project opennms by OpenNMS.
the class AvailCalculatorTest method testGetAvailabilityStatusFlipFlop.
@Test
public void testGetAvailabilityStatusFlipFlop() {
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() - 90)));
calculator.onStatusChange(createStatusChange(PollStatus.available(), new Date(endTime.getTime() - 70)));
calculator.onStatusChange(createStatusChange(PollStatus.unavailable(), new Date(endTime.getTime() - 50)));
calculator.onStatusChange(createStatusChange(PollStatus.available(), new Date(endTime.getTime() - 20)));
Collection<OnmsMonitoredService> svcs = getServices();
double uptimePercent = calculator.getAvailabilityFor(svcs, 0);
assertEquals(0.5, uptimePercent, 0.00);
}
use of org.opennms.web.rest.v1.AvailCalculator 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);
}
use of org.opennms.web.rest.v1.AvailCalculator in project opennms by OpenNMS.
the class AvailCalculatorTest method testGetAvailabilityUnavailableBefore.
@Test
public void testGetAvailabilityUnavailableBefore() {
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.5, uptimePercent, 0.00);
}
Aggregations