⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 availcalculations.java

📁 opennms得相关源码 请大家看看
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
//// This file is part of the OpenNMS(R) Application.//// OpenNMS(R) is Copyright (C) 2002-2003 The OpenNMS Group, Inc.  All rights reserved.// OpenNMS(R) is a derivative work, containing both original code, included code and modified// code that was published under the GNU General Public License. Copyrights for modified // and included code are below.//// OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.//// Copyright (C) 1999-2001 Oculan Corp.  All rights reserved.//// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//// For more information contact://      OpenNMS Licensing       <license@opennms.org>//      http://www.opennms.org///      http://www.opennms.com///// Tab Size = 8//package org.opennms.report.availability;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Calendar;import java.util.Date;import java.util.GregorianCalendar;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.ListIterator;import java.util.Map;import java.util.Set;import java.util.TreeMap;import org.opennms.core.utils.ThreadCategory;import org.opennms.report.datablock.IfService;import org.opennms.report.datablock.Interface;import org.opennms.report.datablock.Node;import org.opennms.report.datablock.OutageSince;import org.opennms.report.datablock.OutageSvcTimesList;import org.opennms.report.datablock.Service;/** * AvailCalculations does all computations for all reports for a category. The * types include Last 30 days daily availability Last 30 days total availability * Last 30 days daily service availability Last Months Top 20 offenders Last * Months Top 20 Service outages Last N Months Availability Last Months Daily * Availability Last Months Total Availability Last Months Daily Service * Availability Month To Date Daily Availability Month To Date Total * Availability *  * @author <A HREF="mailto:jacinta@oculan.com">Jacinta Remedios </A> * @author <A HREF="http://www.oculan.com">Oculan </A> */public class AvailCalculations extends Object {    /**     * The log4j category used to log debug messsages and statements.     */    private static final String LOG4J_CATEGORY = "OpenNMS.Report";    /**     * Castor object that holds all the information required for the generating     * xml to be translated to the pdf.     */    private static Report m_report = null;    /**     * End time     */    private long m_endTime;    /**     * Services map     */    private Map m_services = null;    /**     * End time of the last month.     */    private long m_endLastMonthTime;    /**     * Number of days in the last month.     */    private int m_daysInLastMonth;    /**     * The time in milliseconds per day.     */    private static final long ROLLING_WINDOW = 86400000l;    /**     * Constant     */    private static final int THIRTY = 30;    /**     * Constant (Number of months)     */    private static final int NMONTHS = 12;    /**     * Nodes that match this category.     */    private List m_nodes;    /**     * Monitored Services for the category     */    private List m_monitoredServices;    /**     * Report Format     */    private String m_format;    /**     * This is used for the PDF Report generation     */    private int m_sectionIndex;    /**     * Constructor     *      * @param nodes     *            List of nodes     * @param endTime     *            End time ( end of yesterday in milliseconds)     * @param lastMonthEndTime     *            Last months end time (end of the last day of last month in     *            milliseconds)     * @param monitoredServices     *            Monitored services belonging to the category.     * @param report     *            Castor Report class.     * @param offenders     *            Map of all offenders -- percent/(list of node) pairs     * @param format     *            Value can be "SVG / all"     */    public AvailCalculations(List nodes, long endTime, long lastMonthEndTime, List monitoredServices, Report report, TreeMap offenders, double warning, double normal, String comments, String name, String format, String monthFormat, int catIndex, int sectionIndex) {        m_sectionIndex = sectionIndex;        org.opennms.report.availability.Category category = new org.opennms.report.availability.Category();        category.setWarning(warning);        category.setNormal(normal);        category.setCatComments(comments);        category.setCatName(name);        category.setCatIndex(catIndex);        category.setNodeCount(nodes.size());        int ipaddrCount = 0;        int serviceCount = 0;        ListIterator lstNode = (ListIterator) nodes.listIterator();        while (lstNode.hasNext()) {            Node tmpNode = (Node) lstNode.next();            if (tmpNode != null) {                ipaddrCount += tmpNode.getInterfaceCount();                serviceCount += tmpNode.getServiceCount();            }        }        category.setIpaddrCount(ipaddrCount);        category.setServiceCount(serviceCount);        org.opennms.report.availability.Categories categories = report.getCategories();        ThreadCategory.setPrefix(LOG4J_CATEGORY);        org.apache.log4j.Category log = ThreadCategory.getInstance(this.getClass());        if (log.isDebugEnabled())            log.debug("Inside AvailCalculations");        m_monitoredServices = monitoredServices;        m_endLastMonthTime = lastMonthEndTime;        m_daysInLastMonth = getDaysForMonth(m_endLastMonthTime);        m_report = report;        m_nodes = nodes;        m_format = format;        m_endTime = endTime;        String label;        String descr;        String period;        // Please node the following 4 formats are displayed on the graphical        // report.        // (i) last12MoAvail        // (ii) LastMonthsDailyAvailability        // (iii) MonthToDateDailyAvailability        // (iv) lastMoTop20offenders        SimpleDateFormat fmt = new SimpleDateFormat("MM/dd/yyyy");        if (log.isDebugEnabled())            log.debug("Now computing last 12 months daily availability ");        //        // N Months Availability        //        label = AvailabilityConstants.NMONTH_TOTAL_LABEL;        descr = AvailabilityConstants.NMONTH_TOTAL_DESCR;        if (label == null || label.length() == 0)            label = "The last 12 Months Availability";        if (descr == null || descr.length() == 0)            descr = "The last 12 Months Availability";        CatSections catSections = new CatSections();        lastNMonthsAvailability(NMONTHS, m_endLastMonthTime, catSections, label, descr);        if (log.isDebugEnabled())            log.debug("Computed lastNMonthsAvailability");        //        // Last Months Daily Availability        //        if (log.isDebugEnabled())            log.debug("Now computing last months daily availability ");        label = AvailabilityConstants.LAST_MONTH_DAILY_LABEL;        descr = AvailabilityConstants.LAST_MONTH_DAILY_DESCR;        if (label == null || label.length() == 0)            label = "The last Months Daily Availability";        if (descr == null || descr.length() == 0)            descr = "Daily Average of svcs monitored and availability of svcs divided by the total svc minutes (last month)";        if (monthFormat.equalsIgnoreCase("calendar")){			lastCalMoDailyAvailability(m_daysInLastMonth, m_endLastMonthTime, catSections, label, descr, "LastMonthsDailyAvailability");        }else {        	lastMoDailyAvailability(m_daysInLastMonth, m_endLastMonthTime, catSections, label, descr, "LastMonthsDailyAvailability");        }		if (log.isDebugEnabled())        log.debug("Computed lastNDaysDailyAvailability");        //        // Month To Date Daily Availability        //        if (log.isDebugEnabled())            log.debug("Now computing  month to date daily availability ");        label = AvailabilityConstants.LAST_MTD_DAILY_LABEL;        descr = AvailabilityConstants.LAST_MTD_DAILY_DESCR;        if (label == null || label.length() == 0)            label = "Month To Date Daily Availability";        if (descr == null || descr.length() == 0)            descr = "Daily Average of svc monitored and availability of svcs div by total svc minutes of month frm 1st till date";        Calendar calendar = new GregorianCalendar();        calendar.setTime(new Date(m_endTime));        int numDaysInMonth = calendar.get(Calendar.DAY_OF_MONTH);		if (monthFormat.equalsIgnoreCase("calendar")){			lastCalMTDDailyAvailability(numDaysInMonth, m_endTime, catSections, label, descr, "MonthToDateDailyAvailability");		}else {			lastMTDDailyAvailability(numDaysInMonth, m_endTime, catSections, label, descr, "MonthToDateDailyAvailability");		}                if (log.isDebugEnabled())            log.debug("Computed lastNDaysDailyAvailability");        //        // Last Months Top Offenders        //        if (log.isDebugEnabled())            log.debug("Now computing Last Months Top Offenders ");        label = AvailabilityConstants.NOFFENDERS_LABEL;        descr = AvailabilityConstants.NOFFENDERS_DESCR;        if (label == null || label.length() == 0)            label = "Last Months Top Offenders";        if (descr == null || descr.length() == 0)            descr = "This is the list of the worst available devices in the category for the last month";        lastMoTopNOffenders(offenders, catSections, label, descr);        if (log.isDebugEnabled())            log.debug("Computed lastMoTopNOffenders ");        //        // Last N days Daily Availability        //        if (!format.equals("SVG")) {            if (log.isDebugEnabled())                log.debug("Now computing LAST_30_DAYS_DAILY_LABEL ");            label = AvailabilityConstants.LAST_30_DAYS_DAILY_LABEL;            descr = AvailabilityConstants.LAST_30_DAYS_DAILY_DESCR;            if (label == null || label.length() == 0)                label = "The last 30 Days Daily Availability";            if (descr == null || descr.length() == 0)                descr = "Daily average of svcs and dvcs monitored and their availability divided by total mins for 30days";            lastNDaysDailyAvailability(THIRTY, m_endTime, catSections, label, descr, "Last30DaysDailyAvailability");            if (log.isDebugEnabled())                log.debug("Computed lastNDaysDailyAvailability");        }        //        // N days total availability        //        if (!format.equals("SVG")) {            if (log.isDebugEnabled())                log.debug("Now computing LAST_30_DAYS_TOTAL_LABEL ");            label = AvailabilityConstants.LAST_30_DAYS_TOTAL_LABEL;            descr = AvailabilityConstants.LAST_30_DAYS_TOTAL_DESCR;            if (label == null || label.length() == 0)                label = "The last 30 Days Total Availability";            if (descr == null || descr.length() == 0)                descr = "Average of svcs monitored and availability of svcs divided by total svc minutes of the last 30 days";            lastNDaysTotalAvailability(THIRTY, m_endTime, catSections, label, descr);            if (log.isDebugEnabled())                log.debug("Computed lastNDaysTotalAvailability");        }        //        // Last Months Total Availability        //        if (!format.equals("SVG")) {            if (log.isDebugEnabled())                log.debug("Now computing LAST_MONTH_TOTAL_LABEL ");            label = AvailabilityConstants.LAST_MONTH_TOTAL_LABEL;            descr = AvailabilityConstants.LAST_MONTH_TOTAL_DESCR;            if (label == null || label.length() == 0)                label = "The last Months Total Availability";            if (descr == null || descr.length() == 0)                descr = "Average of svcs monitored and availability of svcs divided by the total svc minutes of the month";            lastMoTotalAvailability(m_daysInLastMonth, m_endLastMonthTime, catSections, label, descr);            if (log.isDebugEnabled())                log.debug("Computed lastNDaysDailyAvailability");        }        //        // Month To Date Total Availability

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -