Search in sources :

Example 1 with Statistic

use of org.jivesoftware.openfire.stats.Statistic in project Openfire by igniterealtime.

the class StatisticsModule method addServerToServerStatistic.

/**
     * Tracks the number of Server To Server connections taking place in the server at anyone time.
     * This includes both incoming and outgoing connections.
     */
private void addServerToServerStatistic() {
    // Register a statistic.
    Statistic serverToServerStatistic = new i18nStatistic(SERVER_2_SERVER_SESSIONS_KEY, MonitoringConstants.NAME, Statistic.Type.count) {

        public double sample() {
            return (SessionManager.getInstance().getIncomingServers().size() + SessionManager.getInstance().getOutgoingServers().size());
        }

        public boolean isPartialSample() {
            return false;
        }
    };
    // Add to StatisticsManager
    statisticsManager.addStatistic(SERVER_2_SERVER_SESSIONS_KEY, serverToServerStatistic);
}
Also used : Statistic(org.jivesoftware.openfire.stats.Statistic) org.jivesoftware.openfire.stats.i18nStatistic(org.jivesoftware.openfire.stats.i18nStatistic) org.jivesoftware.openfire.stats.i18nStatistic(org.jivesoftware.openfire.stats.i18nStatistic)

Example 2 with Statistic

use of org.jivesoftware.openfire.stats.Statistic in project Openfire by igniterealtime.

the class StatisticsModule method addActiveSessionsStatistic.

/**
     * Tracks the number of Active Sessions with the server at any point in time.
     * Active Sessions are defined as one client connection.
     */
private void addActiveSessionsStatistic() {
    // Register a statistic.
    Statistic activeSessionStatistic = new i18nStatistic(SESSIONS_KEY, MonitoringConstants.NAME, Statistic.Type.count) {

        public double sample() {
            return SessionManager.getInstance().getUserSessionsCount(false);
        }

        public boolean isPartialSample() {
            return false;
        }
    };
    statisticsManager.addStatistic(SESSIONS_KEY, activeSessionStatistic);
}
Also used : Statistic(org.jivesoftware.openfire.stats.Statistic) org.jivesoftware.openfire.stats.i18nStatistic(org.jivesoftware.openfire.stats.i18nStatistic) org.jivesoftware.openfire.stats.i18nStatistic(org.jivesoftware.openfire.stats.i18nStatistic)

Example 3 with Statistic

use of org.jivesoftware.openfire.stats.Statistic in project Openfire by igniterealtime.

the class StatsAction method getLowAndHigh.

/**
     * Given a statistic key and a start date, end date and number of datapoints, returns
     * a String[] containing the low and high values (in that order) for the given time period.
     * 
     * @param key the name of the statistic to return high and low values for.
     * @param timePeriod start date, end date and number of data points.
     * @return low and high values for the given time period / number of datapoints
     */
public static String[] getLowAndHigh(String key, long[] timePeriod) {
    MonitoringPlugin plugin = (MonitoringPlugin) XMPPServer.getInstance().getPluginManager().getPlugin(MonitoringConstants.NAME);
    StatsViewer viewer = (StatsViewer) plugin.getModule(StatsViewer.class);
    Statistic.Type type = viewer.getStatistic(key)[0].getStatType();
    double[] lows = viewer.getMin(key, timePeriod[0], timePeriod[1], (int) timePeriod[2]);
    double[] highs = viewer.getMax(key, timePeriod[0], timePeriod[1], (int) timePeriod[2]);
    String low;
    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMaximumFractionDigits(0);
    if (lows.length > 0) {
        if (type == Statistic.Type.count) {
            double result = 0;
            for (int i = 0; i < lows.length; i++) {
                result += lows[i];
            }
            low = String.valueOf((int) result);
        } else {
            double l = 0;
            for (int i = 0; i < lows.length; i++) {
                if (Double.isNaN(lows[i])) {
                    lows[i] = 0;
                }
                l += lows[i];
            }
            low = format.format(l);
        }
    } else {
        low = String.valueOf(0);
    }
    String high;
    if (highs.length > 0) {
        if (type == Statistic.Type.count) {
            double result = 0;
            for (int i = 0; i < highs.length; i++) {
                result += highs[i];
            }
            high = String.valueOf((int) result);
        } else {
            double h = 0;
            for (int i = 0; i < highs.length; i++) {
                if (Double.isNaN(highs[i])) {
                    highs[i] = 0;
                }
                h += highs[i];
            }
            high = format.format(h);
        }
    } else {
        high = String.valueOf(0);
    }
    return new String[] { low, high };
}
Also used : MonitoringPlugin(org.jivesoftware.openfire.plugin.MonitoringPlugin) Statistic(org.jivesoftware.openfire.stats.Statistic) NumberFormat(java.text.NumberFormat)

Example 4 with Statistic

use of org.jivesoftware.openfire.stats.Statistic in project Openfire by igniterealtime.

the class GraphEngine method generateChart.

/**
     * Creates a chart.
     *
     * @param key
     * @param width
     * @param height
     * @param startTime
     * @param endTime
     * @param dataPoints
     * @return
     * @throws IOException
     */
public JFreeChart generateChart(String key, int width, int height, String color, long startTime, long endTime, int dataPoints) throws IOException {
    Statistic[] def = statsViewer.getStatistic(key);
    if (def == null) {
        return null;
    }
    XYDataset data = populateData(key, def, startTime, endTime, dataPoints);
    if (data == null) {
        return null;
    }
    JFreeChart chart;
    switch(def[0].getStatType()) {
        case count:
            chart = createTimeBarChart(null, color, def[0].getUnits(), data);
            break;
        default:
            chart = createTimeAreaChart(null, color, def[0].getUnits(), data);
    }
    return chart;
}
Also used : Statistic(org.jivesoftware.openfire.stats.Statistic) IntervalXYDataset(org.jfree.data.xy.IntervalXYDataset) XYDataset(org.jfree.data.xy.XYDataset) JFreeChart(org.jfree.chart.JFreeChart)

Example 5 with Statistic

use of org.jivesoftware.openfire.stats.Statistic in project Openfire by igniterealtime.

the class GraphEngine method generateSparklinesGraph.

/**
     * Generates a Sparkline type graph. Sparkline graphs
     * are "intense, simple, wordlike graphics" so named by Edward Tufte. The big
     * difference between the graph produced by this method compared to the
     * graph produced by the <code>generateGraph</code> method is that this one
     * produces graphs with no x-axis and no y-axis and is usually smaller in size.
     * @param key
     * @param width
     * @param height
     * @param startTime
     * @param endTime
     * @param dataPoints
     * @return
     * @throws IOException
     */
public byte[] generateSparklinesGraph(String key, int width, int height, String color, long startTime, long endTime, int dataPoints) throws IOException {
    Statistic[] def = statsViewer.getStatistic(key);
    if (def == null) {
        return null;
    }
    JFreeChart chart;
    switch(def[0].getStatType()) {
        case count:
            chart = generateSparklineBarGraph(key, color, def, startTime, endTime, dataPoints);
            break;
        default:
            chart = generateSparklineAreaChart(key, color, def, startTime, endTime, dataPoints);
    }
    KeypointPNGEncoderAdapter encoder = new KeypointPNGEncoderAdapter();
    encoder.setEncodingAlpha(true);
    return encoder.encode(chart.createBufferedImage(width, height, BufferedImage.BITMASK, null));
}
Also used : KeypointPNGEncoderAdapter(org.jfree.chart.encoders.KeypointPNGEncoderAdapter) Statistic(org.jivesoftware.openfire.stats.Statistic) JFreeChart(org.jfree.chart.JFreeChart)

Aggregations

Statistic (org.jivesoftware.openfire.stats.Statistic)17 org.jivesoftware.openfire.stats.i18nStatistic (org.jivesoftware.openfire.stats.i18nStatistic)3 Date (java.util.Date)2 JFreeChart (org.jfree.chart.JFreeChart)2 MonitoringPlugin (org.jivesoftware.openfire.plugin.MonitoringPlugin)2 Document (com.lowagie.text.Document)1 DocumentException (com.lowagie.text.DocumentException)1 Paragraph (com.lowagie.text.Paragraph)1 DefaultFontMapper (com.lowagie.text.pdf.DefaultFontMapper)1 PdfContentByte (com.lowagie.text.pdf.PdfContentByte)1 PdfTemplate (com.lowagie.text.pdf.PdfTemplate)1 PdfWriter (com.lowagie.text.pdf.PdfWriter)1 Graphics2D (java.awt.Graphics2D)1 Rectangle2D (java.awt.geom.Rectangle2D)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 NumberFormat (java.text.NumberFormat)1