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);
}
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);
}
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 };
}
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;
}
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));
}
Aggregations