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

📄 reportdetailsbean.java

📁 report trafiic for java bean
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* The file defines a class for netflow front-end for Application Traffic
   Copyright 2004-2005, IEI Technology(China) Co.Ltd.
   Coding By IEI Netflow Analysis Development Team */


package com.idmsoft.netflow.beans;

import com.idmsoft.netflow.flow.util.NetFlowUtil;
import com.idmsoft.netflow.flow.util.RouterFilter;
import com.idmsoft.netflow.flow.util.RelayFilter;
import com.idmsoft.netflow.utils.DBQueryUtil;
import com.idmsoft.netflow.utils.NetFlowClientException;
import com.lowagie.text.*;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.*;
import java.awt.*;
import java.awt.Font;
import java.awt.geom.Rectangle2D;
import java.io.*;
import java.text.*;
import java.util.*;
import java.util.logging.Logger;
import javax.servlet.http.HttpSession;
import org.jfree.chart.*;
import org.jfree.chart.annotations.XYPointerAnnotation;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.labels.StandardPieItemLabelGenerator;
import org.jfree.chart.labels.StandardXYItemLabelGenerator;
import org.jfree.chart.plot.*;
import org.jfree.chart.renderer.*;
import org.jfree.chart.servlet.ChartDeleter;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.DefaultPieDataset;
import org.jfree.data.TableXYDataset;
import org.jfree.data.time.Millisecond;
import org.jfree.data.time.TimeTableXYDataset;
import org.jfree.ui.HorizontalAlignment;

public class ReportDetailsBean
{

    private ReportDetailsUtil getUtil()
    {
        return ReportDetailsUtil.getInstance();
    }

    private GenerateQuery getQuery()
    {
        return GenerateQuery.getInstance();
    }

    public ReportDetailsBean()
    {
        pieDataMap = null;
        inColor = new Color(50, 80, 183);
        outColor = new Color(254, 160, 70);
        if(pieDataMap == null)
            pieDataMap = new PieChartDataMap();
    }
    
    // get all interfaces of the routerid
    
    public Hashtable getRouterInterface(int routerID)
    {
        String intQuery = "";
        if(routerID != -1)
            intQuery = "select NetFlow_Interface.INTERFACE_ID, NetFlow_Interface.INTERFACE_INDEX, NetFlow_Interface.LINK_NAME from NetFlow_Interface where NetFlow_Interface.ROUTER_ID = routerID";
        else
            return null;
        nfLogger.finer("query in getRouterInterface is " + intQuery);
        return DBQueryUtil.getInstance().getRouterInterfaces(intQuery);    
    }    

    // get Graphics Page Result - timeframe, index, starttime, endtime
    public Hashtable getGraphPageResults(String timeFrame, String index, HttpSession session, String graphOption, long speed, String stH,
            String edH)
    {
        String graphLoc = "";
        long endTime = System.currentTimeMillis();
        long startTime = getUtil().getStartTimeForPeriod(timeFrame);
        TimeTableXYDataset dataset = new TimeTableXYDataset();
        Hashtable result = getQuery().populateDataset(timeFrame, index, dataset, graphOption, speed, Integer.parseInt(stH), Integer.parseInt(edH));
        String yAxis = (String)result.get("yaxis");
        if(dataset != null)
        {
            DateAxis xAxis = new DateAxis("Time");
            graphLoc = generateGraphTimeSeries(dataset, xAxis, yAxis, session, graphOption, startTime, endTime);
        }
        result.put("fileLoc", graphLoc);
        return result;
    }

    // get Graphics Page Result - timeframe, index, starttime, endtime
    public Hashtable getGraphPageResults(long stTime, long edTime, String index, HttpSession session, String graphOption,
            long speed, String stH, String edH)
    {
        String graphLoc = "";
        TimeTableXYDataset dataset = new TimeTableXYDataset();
        Hashtable result = getQuery().populateDatasetCReport(stTime, edTime, index, dataset, graphOption, speed, Integer.parseInt(stH), Integer.parseInt(edH));
        String yAxis = (String)result.get("yaxis");
        if(dataset != null)
        {
            DateAxis xAxis = new DateAxis("Time");
            graphLoc = generateGraphTimeSeries(dataset, xAxis, yAxis, session, graphOption, stTime, edTime);
        }
        result.put("fileLoc", graphLoc);
        return result;
    }

    // get application graphics - app In/Out,  starttime, endtime
    public String getApplicationGraph(String appINOUT, Vector appNameList, long stTime, long edTime, String index,
            HttpSession session, String graphOption, long speed)
    {
        String appGraph = "";
        TimeTableXYDataset dataset = new TimeTableXYDataset();
        String yAxis = getQuery().populateApplicationDataset(appINOUT, appNameList, stTime, edTime, index, dataset, graphOption, speed);
        if(dataset != null)
        {
            DateAxis xAxis = new DateAxis("Time");
            appGraph = generateApplicationGraphTimeSeries(dataset, xAxis, yAxis, session, graphOption, stTime, edTime);
        }
        return appGraph;
    }

    // Create Application Graphics
    public String generateApplicationGraphTimeSeries(TableXYDataset dataset, DateAxis xAxis, String yAUnit, HttpSession session, String graphOption, long stTime,
            long edTime)
    {
        String yAxisUnit = "Traffic (" + yAUnit + ")";
        NumberAxis yAxis = new NumberAxis(yAxisUnit);
        yAxis.setAutoRangeIncludesZero(true);
        yAxis.setLabelAngle(50.25D);
        if(graphOption.equalsIgnoreCase("percentage"))
        {
            yAxis.setMinimumAxisValue(0.0D);
            yAxis.setMaximumAxisValue(100D);
        }
        StandardXYItemLabelGenerator labelGenerator = new StandardXYItemLabelGenerator(new SimpleDateFormat("dd-MMM-yyyy", Locale.UK));
        StackedXYAreaRenderer renderer = new StackedXYAreaRenderer(4, labelGenerator, null);
        int cols[][] = {
            {
                0, 255, 0
            }, {
                0, 0, 255
            }, {
                255, 0, 0
            }, {
                255, 255, 0
            }, {
                255, 0, 204
            }, {
                0, 51, 51
            }, {
                102, 0, 102
            }, {
                0, 102, 255
            }, {
                102, 51, 0
            }, {
                255, 153, 0
            }
        };
        int seriesCount = dataset.getSeriesCount();
        int k = 0;
        if(seriesCount <= 10)
            k = seriesCount;
        for(int i = 0; i < k; i++)
            renderer.setSeriesPaint(i, new Color(cols[i][0], cols[i][1], cols[i][2]));

        renderer.setShapePaint(Color.gray);
        XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
        DateAxis dateAxis = (DateAxis)plot.getDomainAxis();
        dateAxis.setRange(new Date(stTime), new Date(edTime));
        dateAxis.setTickUnit(getUtil().setAppropriateTickUnit(edTime - stTime));
        plot.setInsets(new Insets(25, 25, 10, 25));
        if(dataset == null)
            plot.setNoDataMessage("No data for this selection");
        JFreeChart chart = new JFreeChart(null, JFreeChartConstants.DEFAULT_TITLE_FONT, plot, true);
        chart.setBackgroundPaint(new Color(255, 255, 255));
        String filenamePrefix = "appChart" + System.currentTimeMillis();
        ServletUtilities.setTempFilePrefix(filenamePrefix);
        String appPNGName = null;
        try
        {
            appPNGName = ServletUtilities.saveChartAsPNG(chart, 617, 210, null, session);
        }
        catch(Exception ee)
        {
            nfLogger.severe("Exception in generateApplicationGraphTimeSeries " + ee.getMessage());
            ee.printStackTrace();
        }
        nfLogger.finer("ApplicationPNG File Name in generateApplicationGraphTimeSeries() :" + appPNGName);
        return appPNGName;
    }

    // fetch Top10 result
    public float getTopTenResult(String type, long fromTime, long toTime, String index, Vector resVect,
            int rows, String getWhat, boolean getTotal, boolean isIPGroup, int pageCount, boolean isTShoot, ArrayList crit)
    {
        float myValue = getQuery().getTopTenCrunch(type, fromTime, toTime, index, rows, resVect, getTotal, isIPGroup, pageCount, isTShoot, crit);
        if(getWhat != null && getWhat.equalsIgnoreCase("dnsname"))
        {
            int colNos[] = {
                1
            };
            resVect = getUtil().replaceIpWithDns(resVect, colNos);
        }
        return myValue;
    }

    //fetch conversation connection
    public Hashtable getConversation(String type, String entity, long startTime, long endTime, String index,
            String getWhat, String pieTitle, HttpSession session, int rows, String grp, boolean isIPGroup, int pageCount)
    {
        long ttime = System.currentTimeMillis();
        Hashtable retHash = new Hashtable();
        if(grp == null || grp.equals(""))
            grp = null;
        Vector vect = new Vector();
        Vector vector = getQuery().getConversationCrunch(type, entity, startTime, endTime, index, rows, grp, vect, isIPGroup, pageCount);
        Double total = new Double(0.0D);
        if(entity != null && vector != null && vector.size() > 0 && vector.get(0) != null)
            total = (Double)vector.get(0);
        if(getWhat != null && getWhat.equalsIgnoreCase("dnsname"))
        {
            int colNos[] = {
                0, 1
            };
            vect = getUtil().replaceIpWithDns(vect, colNos);
        }
        String sTitle = "Top Source IP - " + pieTitle;
        String dTitle = "Top Destination IP - " + pieTitle;
        String aTitle = "Top Application - " + pieTitle;
        if(getWhat != null && getWhat.equalsIgnoreCase("dnsname"))
        {
            sTitle = "Top Source DNS - " + pieTitle;
            dTitle = "Top Destination DNS - " + pieTitle;
            aTitle = "Top Application DNS - " + pieTitle;
        }
        Vector allVector = createPieCharts(vect, getWhat, pieTitle, session);
        Vector sVector = (Vector)allVector.elementAt(0);
        Vector dVector = (Vector)allVector.elementAt(1);
        Vector aVector = (Vector)allVector.elementAt(2);
        String inOut = "IN";
        if(type.equalsIgnoreCase("ApplicationOUT") || type.equalsIgnoreCase("DestinationOUT") || type.equalsIgnoreCase("SourceOUT") || type.equalsIgnoreCase("ConversationOUT"))
            inOut = "OUT";
        pieDataMap.put(index + inOut + "ConSource", getPieDataFromVector(sVector));
        pieDataMap.put(index + inOut + "ConDest", getPieDataFromVector(dVector));
        pieDataMap.put(index + inOut + "ConAppl", getPieDataFromVector(aVector));
        retHash.put("resultVector", vect);
        if(entity != null)
            retHash.put("totalOctets", total);
        return retHash;
    }

    // Fetch Pie Graphics Datasets
    private DefaultPieDataset getPieDataFromVector(Vector vect)
    {
        DefaultPieDataset dp = new DefaultPieDataset();
        vect = getUtil().getPieVector(vect);
        for(int i = 0; i < vect.size(); i++)
        {
            Vector temp = (Vector)vect.get(i);
            dp.setValue((String)temp.get(1), ((Double)temp.get(0)).doubleValue());
        }

⌨️ 快捷键说明

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