Search in sources :

Example 1 with TimeChunker

use of org.opennms.web.rest.v1.support.TimeChunker 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;
}
Also used : OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) OnmsLocationAvailDefinition(org.opennms.netmgt.model.OnmsLocationAvailDefinition) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) OnmsLocationAvailDataPoint(org.opennms.netmgt.model.OnmsLocationAvailDataPoint) OnmsLocationAvailDataPoint(org.opennms.netmgt.model.OnmsLocationAvailDataPoint) Date(java.util.Date) TimeChunk(org.opennms.web.rest.v1.support.TimeChunker.TimeChunk) OnmsLocationAvailDefinitionList(org.opennms.netmgt.model.OnmsLocationAvailDefinitionList)

Example 2 with TimeChunker

use of org.opennms.web.rest.v1.support.TimeChunker 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);
}
Also used : AvailCalculator(org.opennms.web.rest.v1.AvailCalculator) PollStatus(org.opennms.netmgt.poller.PollStatus) OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) TimeChunker(org.opennms.web.rest.v1.support.TimeChunker) Date(java.util.Date) Test(org.junit.Test)

Example 3 with TimeChunker

use of org.opennms.web.rest.v1.support.TimeChunker 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);
}
Also used : AvailCalculator(org.opennms.web.rest.v1.AvailCalculator) TimeChunker(org.opennms.web.rest.v1.support.TimeChunker) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test)

Example 4 with TimeChunker

use of org.opennms.web.rest.v1.support.TimeChunker in project opennms by OpenNMS.

the class ResolutionTest method testResolution.

@Test
public void testResolution() {
    Date startDate = new Date(new Date().getTime() - 300000);
    long endTime = startDate.getTime() + 300000;
    TimeChunker resolution = new TimeChunker(TimeChunker.MINUTE, startDate, new Date(endTime));
    assertEquals(1, resolution.getSegmentCount());
    Date startDate1 = resolution.getNextSegment().getStartDate();
    while (resolution.hasNext()) {
        System.err.println("startDate segment1: " + startDate1);
        assertEquals(startDate, startDate1);
    }
}
Also used : TimeChunker(org.opennms.web.rest.v1.support.TimeChunker) Date(java.util.Date) Test(org.junit.Test)

Example 5 with TimeChunker

use of org.opennms.web.rest.v1.support.TimeChunker in project opennms by OpenNMS.

the class RemotePollerAvailabilityService method getTimeChunkerFromMidnight.

protected static TimeChunker getTimeChunkerFromMidnight() {
    Calendar calendar = Calendar.getInstance();
    Date startTime = new GregorianCalendar(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), 0, 0, 0).getTime();
    return new TimeChunker(TimeChunker.MINUTE, startTime, new Date(System.currentTimeMillis()));
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) TimeChunker(org.opennms.web.rest.v1.support.TimeChunker) Date(java.util.Date)

Aggregations

Date (java.util.Date)10 TimeChunker (org.opennms.web.rest.v1.support.TimeChunker)9 Test (org.junit.Test)7 AvailCalculator (org.opennms.web.rest.v1.AvailCalculator)4 OnmsLocationSpecificStatus (org.opennms.netmgt.model.OnmsLocationSpecificStatus)3 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)3 DecimalFormat (java.text.DecimalFormat)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Collection (java.util.Collection)1 GregorianCalendar (java.util.GregorianCalendar)1 OnmsApplication (org.opennms.netmgt.model.OnmsApplication)1 OnmsLocationAvailDataPoint (org.opennms.netmgt.model.OnmsLocationAvailDataPoint)1 OnmsLocationAvailDefinition (org.opennms.netmgt.model.OnmsLocationAvailDefinition)1 OnmsLocationAvailDefinitionList (org.opennms.netmgt.model.OnmsLocationAvailDefinitionList)1 PollStatus (org.opennms.netmgt.poller.PollStatus)1 TimeChunk (org.opennms.web.rest.v1.support.TimeChunker.TimeChunk)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)1