/** * Returns percent/node combinations for the last month. This is used to get the last months top * 20 offenders * * @return a {@link java.util.TreeMap} object. */ public Map<Double, List<String>> getPercentNode() { int days = m_daysInLastMonth; long endTime = m_lastMonthEndTime; Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(endTime); cal.add(Calendar.DATE, -1 * days); long rollingWindow = endTime - cal.getTime().getTime(); long startTime = cal.getTime().getTime(); LOG.debug("getPercentNode: Start time {}", new java.util.Date(startTime)); LOG.debug("getPercentNode: End time {}", new java.util.Date(endTime)); TreeMap<Double, List<String>> percentNode = new TreeMap<Double, List<String>>(); for (Node node : m_nodes) { if (node != null) { double percent = node.getPercentAvail(endTime, rollingWindow); String nodeName = node.getName(); LOG.debug("Node {} {} %", nodeName, percent); if (percent < 100.0) { List<String> nodeNames = percentNode.get(new Double(percent)); if (nodeNames == null) { nodeNames = new ArrayList<String>(); } nodeNames.add(nodeName); percentNode.put(new Double(percent), nodeNames); } } } LOG.debug("Percent node {}", percentNode); return percentNode; }
/** * Populates the data structure for this category. This method only computes for monitored * services in this category. * * @param cat Category * @param report Report Castor class * @param format SVG-specific/all reports */ private void populateDataStructures( org.opennms.netmgt.config.categories.Category cat, Report report, String format, String monthFormat, int catIndex) throws Exception { LOG.debug("Inside populate data Structures {}", catIndex); report.setCatCount(catIndex); LOG.debug("Inside populate data Structures"); try { List<String> monitoredServices = new ArrayList<String>(cat.getServiceCollection()); if (m_availabilityDataService == null) { LOG.debug("DATA SERVICE IS NULL"); throw new IllegalStateException("Data service is null"); } m_nodes = m_availabilityDataService.getNodes(cat, m_startTime, m_endTime); LOG.debug("Nodes {}", m_nodes); // remove all the nodes that do not have outages ListIterator<Node> cleanNodes = m_nodes.listIterator(); while (cleanNodes.hasNext()) { Node node = (Node) cleanNodes.next(); if (node != null && !node.hasOutages()) { LOG.debug("Removing node: {}", node); cleanNodes.remove(); } } LOG.debug("Cleaned Nodes {}", m_nodes); Map<Double, List<String>> topOffenders = getPercentNode(); LOG.debug("TOP OFFENDERS {}", topOffenders); if (m_nodes.size() <= 0) { m_nodes = null; } if (m_nodes != null) { AvailCalculations availCalculations = new AvailCalculations( m_nodes, m_endTime, m_lastMonthEndTime, monitoredServices, report, topOffenders, cat.getWarning(), cat.getNormal(), cat.getComment(), cat.getLabel(), format, monthFormat, catIndex, m_sectionIndex); m_sectionIndex = availCalculations.getSectionIndex(); report.setSectionCount(m_sectionIndex - 1); } else { org.opennms.reporting.availability.Category category = new org.opennms.reporting.availability.Category(); category.setCatComments(cat.getComment()); category.setCatName(cat.getLabel()); category.setCatIndex(catIndex); category.setNodeCount(0); category.setIpaddrCount(0); category.setServiceCount(0); Section section = new Section(); section.setSectionIndex(m_sectionIndex); org.opennms.reporting.availability.CatSections catSections = new org.opennms.reporting.availability.CatSections(); catSections.addSection(section); category.addCatSections(catSections); org.opennms.reporting.availability.Categories categories = report.getCategories(); categories.addCategory(category); report.setCategories(categories); report.setSectionCount(m_sectionIndex); m_sectionIndex++; } } catch (Throwable e) { LOG.error("Exception has occurred", e); throw new Exception(e); } }