use of org.opennms.netmgt.model.OnmsLocationSpecificStatus 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<PollStatus>();
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.OnmsLocationSpecificStatus in project opennms by OpenNMS.
the class DefaultDistributedStatusService method calculatePercentageUptime.
/**
* Calculate the percentage of time that all services are up for this
* application on this remote monitor.
*
* @param applicationServices services to report on
* @param statuses status entries to use for report
* @param startDate start date. The report starts on this date.
* @param endDate end date. The report ends the last millisecond prior
* this date.
* @return representation of the percentage uptime out to three decimal
* places. Null is returned if there is no data.
*/
public String calculatePercentageUptime(Collection<OnmsMonitoredService> applicationServices, Collection<OnmsLocationSpecificStatus> statuses, Date startDate, Date endDate) {
/*
* The methodology is as such:
* 1) Sort the status entries by their timestamp;
* 2) Create a Map of each monitored service with a default
* PollStatus of unknown.
* 3) Iterate through the sorted list of status entries until
* we hit a timestamp that is not within our time range or
* run out of entries.
* a) Along the way, update the status Map with the current
* entry's status, and calculate the current status.
* b) If the current timestamp is before the start time, store
* the current status so we can use it once we cross over
* into our time range and then continue.
* c) If the previous status is normal, then count up the number
* of milliseconds since the previous state change entry in
* the time range (or the beginning of the range if this is
* the first entry in within the time range), and add that
* a counter of "normal" millseconds.
* d) Finally, save the current date and status for later use.
* 4) Perform the same computation in 3c, except count the number
* of milliseconds since the last state change entry (or the
* start time if there were no entries) and the end time, and add
* that to the counter of "normal" milliseconds.
* 5) Divide the "normal" milliseconds counter by the total number
* of milliseconds in our time range and compute and return a
* percentage.
*/
List<OnmsLocationSpecificStatus> sortedStatuses = new LinkedList<OnmsLocationSpecificStatus>(statuses);
Collections.sort(sortedStatuses, new Comparator<OnmsLocationSpecificStatus>() {
@Override
public int compare(OnmsLocationSpecificStatus o1, OnmsLocationSpecificStatus o2) {
return o1.getPollResult().getTimestamp().compareTo(o2.getPollResult().getTimestamp());
}
});
HashMap<OnmsMonitoredService, PollStatus> serviceStatus = new HashMap<OnmsMonitoredService, PollStatus>();
for (OnmsMonitoredService service : applicationServices) {
serviceStatus.put(service, PollStatus.unknown("No history for this service from this location"));
}
float normalMilliseconds = 0f;
Date lastDate = startDate;
Severity lastStatus = Severity.CRITICAL;
for (OnmsLocationSpecificStatus status : sortedStatuses) {
Date currentDate = status.getPollResult().getTimestamp();
if (!currentDate.before(endDate)) {
// We're at or past the end date, so we're done processing
break;
}
serviceStatus.put(status.getMonitoredService(), status.getPollResult());
Severity currentStatus = calculateStatus(serviceStatus.values());
if (currentDate.before(startDate)) {
/*
* We're not yet to a date that is inside our time period, so
* we don't need to check the status and adjust the
* normalMilliseconds variable, but we do need to save the
* status so we have an up-to-date status when we cross the
* start date.
*/
lastStatus = currentStatus;
continue;
}
/*
* Because we *just* had a state change, we want to look at the
* value of the *last* status.
*/
if (lastStatus == Severity.NORMAL) {
long milliseconds = currentDate.getTime() - lastDate.getTime();
normalMilliseconds += milliseconds;
}
lastDate = currentDate;
lastStatus = currentStatus;
}
if (lastStatus == Severity.NORMAL) {
long milliseconds = endDate.getTime() - lastDate.getTime();
normalMilliseconds += milliseconds;
}
float percentage = normalMilliseconds / (endDate.getTime() - startDate.getTime()) * 100;
return new DecimalFormat("0.000").format((double) percentage) + "%";
}
use of org.opennms.netmgt.model.OnmsLocationSpecificStatus in project opennms by OpenNMS.
the class DefaultDistributedStatusService method createFacilityStatusTable.
/** {@inheritDoc} */
@Override
public SimpleWebTable createFacilityStatusTable(Date start, Date end) {
Assert.notNull(start, "argument start cannot be null");
Assert.notNull(end, "argument end cannot be null");
if (!start.before(end)) {
throw new IllegalArgumentException("start date (" + start + ") must be older than end date (" + end + ")");
}
SimpleWebTable table = new SimpleWebTable();
List<OnmsMonitoringLocation> locationDefinitions = m_monitoringLocationDao.findAll();
Collection<OnmsApplication> applications = m_applicationDao.findAll();
if (applications.size() == 0) {
throw new IllegalArgumentException("there are no applications");
}
List<OnmsApplication> sortedApplications = new ArrayList<OnmsApplication>(applications);
Collections.sort(sortedApplications);
Collection<OnmsLocationSpecificStatus> mostRecentStatuses = m_locationMonitorDao.getAllMostRecentStatusChanges();
Collection<OnmsLocationSpecificStatus> statusesPeriod = new HashSet<OnmsLocationSpecificStatus>();
statusesPeriod.addAll(m_locationMonitorDao.getAllStatusChangesAt(start));
statusesPeriod.addAll(m_locationMonitorDao.getStatusChangesBetween(start, end));
table.setTitle("Distributed Status Summary");
table.addColumn("Area", "");
table.addColumn("Location", "");
for (OnmsApplication application : sortedApplications) {
table.addColumn(application.getName(), "");
}
for (OnmsMonitoringLocation locationDefinition : locationDefinitions) {
Collection<OnmsLocationMonitor> monitors = m_locationMonitorDao.findByLocationDefinition(locationDefinition);
table.newRow();
table.addCell(locationDefinition.getMonitoringArea(), "");
table.addCell(locationDefinition.getLocationName(), "");
for (OnmsApplication application : sortedApplications) {
Collection<OnmsMonitoredService> memberServices = m_monitoredServiceDao.findByApplication(application);
Severity status = calculateCurrentStatus(monitors, memberServices, mostRecentStatuses);
Set<OnmsLocationSpecificStatus> selectedStatuses = filterStatus(statusesPeriod, monitors, memberServices);
if (selectedStatuses.size() > 0) {
String percentage = calculatePercentageUptime(memberServices, selectedStatuses, start, end);
table.addCell(percentage, status.getStyle(), createHistoryPageUrl(locationDefinition, application));
} else {
table.addCell("No data", status.getStyle());
}
}
}
if (isLayoutApplicationsVertically()) {
SimpleWebTable newTable = new SimpleWebTable();
newTable.setErrors(table.getErrors());
newTable.setTitle(table.getTitle());
newTable.addColumn("Application");
for (List<Cell> row : table.getRows()) {
// The location is in the second row
newTable.addColumn(row.get(1).getContent(), row.get(1).getStyleClass());
}
for (Cell columnHeader : table.getColumnHeaders().subList(2, table.getColumnHeaders().size())) {
// This is the index into collumn list of the old table to get the data for the current application
int rowColumnIndex = newTable.getRows().size() + 2;
newTable.newRow();
newTable.addCell(columnHeader.getContent(), columnHeader.getStyleClass());
for (List<Cell> row : table.getRows()) {
newTable.addCell(row.get(rowColumnIndex).getContent(), row.get(rowColumnIndex).getStyleClass(), row.get(rowColumnIndex).getLink());
}
}
return newTable;
}
return table;
}
use of org.opennms.netmgt.model.OnmsLocationSpecificStatus in project opennms by OpenNMS.
the class DefaultDistributedStatusService method createStatusTable.
/** {@inheritDoc} */
@Override
public SimpleWebTable createStatusTable(DistributedStatusDetailsCommand command, Errors errors) {
SimpleWebTable table = new SimpleWebTable();
table.setErrors(errors);
// Already had some validation errors, so don't bother doing anything
if (table.getErrors().hasErrors()) {
return table;
}
table.setTitle("Distributed status view for " + command.getApplication() + " from " + command.getLocation() + " location");
List<OnmsLocationSpecificStatus> status = findLocationSpecificStatus(command, table.getErrors());
// No data was found, and an error was probably added, so just return
if (status == null) {
return table;
}
table.addColumn("Node", "");
table.addColumn("Monitor", "");
table.addColumn("Service", "");
table.addColumn("Status", "");
table.addColumn("Response", "");
table.addColumn("Last Status Change", "");
table.addColumn("Last Update", "");
SortedSet<OnmsLocationSpecificStatus> sortedStatus = new TreeSet<OnmsLocationSpecificStatus>(LOCATION_STATUS_COMPARATOR);
sortedStatus.addAll(status);
for (OnmsLocationSpecificStatus s : sortedStatus) {
table.newRow();
table.addCell(s.getMonitoredService().getIpInterface().getNode().getLabel(), getStyleForPollResult(s.getPollResult()), "element/node.jsp?node=" + s.getMonitoredService().getIpInterface().getNode().getId());
table.addCell(s.getLocationMonitor().getLocation() + "-" + s.getLocationMonitor().getId(), "", "distributed/locationMonitorDetails.htm?monitorId=" + s.getLocationMonitor().getId());
table.addCell(s.getMonitoredService().getServiceName(), "", "element/service.jsp?ifserviceid=" + s.getMonitoredService().getId());
table.addCell(s.getPollResult().getStatusName(), "bright");
table.addCell(getResponseText(s.getPollResult()), "");
table.addCell(reDateify(s.getPollResult().getTimestamp()), "");
table.addCell(reDateify(s.getLocationMonitor().getLastUpdated()), "");
}
return table;
}
use of org.opennms.netmgt.model.OnmsLocationSpecificStatus in project opennms by OpenNMS.
the class DefaultDistributedStatusService method findLocationSpecificStatus.
/**
* <p>findLocationSpecificStatus</p>
*
* @param command a {@link org.opennms.web.command.DistributedStatusDetailsCommand} object.
* @param errors a {@link org.springframework.validation.Errors} object.
* @return a {@link java.util.List} object or null if no location monitors are registered for the specified location and application tuple
*/
protected List<OnmsLocationSpecificStatus> findLocationSpecificStatus(DistributedStatusDetailsCommand command, Errors errors) throws IllegalArgumentException {
String locationName = command.getLocation();
String applicationName = command.getApplication();
Assert.notNull(locationName, "location cannot be null");
Assert.notNull(applicationName, "application cannot be null");
OnmsMonitoringLocation location = m_monitoringLocationDao.get(locationName);
if (location == null) {
throw new IllegalArgumentException("Could not find location for " + "location name \"" + locationName + "\"");
}
OnmsApplication application = m_applicationDao.findByName(applicationName);
if (application == null) {
throw new IllegalArgumentException("Could not find application " + "for application name \"" + applicationName + "\"");
}
Collection<OnmsLocationMonitor> locationMonitors = m_locationMonitorDao.findByLocationDefinition(location);
if (locationMonitors.size() == 0) {
errors.reject("location.no-monitors", new Object[] { applicationName, locationName }, "No remote pollers have registered for this " + "application and location");
return null;
}
List<OnmsLocationMonitor> sortedLocationMonitors = new ArrayList<OnmsLocationMonitor>(locationMonitors);
Collections.sort(sortedLocationMonitors);
Collection<OnmsMonitoredService> services = m_monitoredServiceDao.findByApplication(application);
List<OnmsMonitoredService> sortedServices = new ArrayList<OnmsMonitoredService>(services);
Collections.sort(sortedServices);
List<OnmsLocationSpecificStatus> status = new LinkedList<OnmsLocationSpecificStatus>();
for (OnmsMonitoredService service : sortedServices) {
for (OnmsLocationMonitor locationMonitor : sortedLocationMonitors) {
OnmsLocationSpecificStatus currentStatus = m_locationMonitorDao.getMostRecentStatusChange(locationMonitor, service);
if (currentStatus == null) {
status.add(new OnmsLocationSpecificStatus(locationMonitor, service, NO_RECORDED_STATUS));
} else {
status.add(currentStatus);
}
}
}
return status;
}
Aggregations