Commit fd7bfe7f authored by Axel Brand's avatar Axel Brand Committed by daeva

Gojara

- display Warnings in overview pages if not a gateway is not configured for admin usage
- show gathered stat information in table on new page gatewayStatistics, (Server -> Server Manager -> Spectrum2 Stats)
- helper for better presentation of gathered data in AdminManager (KB to MB, sec to S/M/H/D)
- also display number of registrations to see online/registered ratio
pretty much finished now, just some minor changes before release needed

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@13702 b35dd754-fafc-0310-a699-88a17e54d16e
parent 9e9493e4
...@@ -24,6 +24,12 @@ ...@@ -24,6 +24,12 @@
description="${rr.summary.title}" /> description="${rr.summary.title}" />
</sidebar> </sidebar>
</tab> </tab>
<tab id="tab-server">
<sidebar id="sidebar-server-manager">
<item id="gojaraGatewayStatistics" name="Spectrum2 Stats"
url="gojara-gatewayStatistics.jsp" description="Click to see Stats of Spectrum2 Components"></item>
</sidebar>
</tab>
<tab id="tab-session"> <tab id="tab-session">
<sidebar id="sidebar-session"> <sidebar id="sidebar-session">
<item id="gojaraSessions" name="Gateway Sessions" url="gojara-activeSessions.jsp" <item id="gojaraSessions" name="Gateway Sessions" url="gojara-activeSessions.jsp"
......
...@@ -40,6 +40,7 @@ public class DatabaseManager { ...@@ -40,6 +40,7 @@ public class DatabaseManager {
private static final String GET_SESSION_ENTRIES_FOR_USERNAME = "SELECT * FROM ofGojaraSessions WHERE username = ? ORDER BY lastActivity DESC"; private static final String GET_SESSION_ENTRIES_FOR_USERNAME = "SELECT * FROM ofGojaraSessions WHERE username = ? ORDER BY lastActivity DESC";
private static final String DELETE_SESSION_ENTRY = "DELETE FROM ofGojaraSessions WHERE username = ? AND transport = ?"; private static final String DELETE_SESSION_ENTRY = "DELETE FROM ofGojaraSessions WHERE username = ? AND transport = ?";
private static final String GET_SESSION_COUNT = "SELECT count(*) FROM ofGojaraSessions"; private static final String GET_SESSION_COUNT = "SELECT count(*) FROM ofGojaraSessions";
private static final String GET_SESSION_COUNT_FOR_TRANSPORT = "SELECT count(*) FROM ofGojaraSessions WHERE transport = ?";
private DatabaseManager() { private DatabaseManager() {
...@@ -409,4 +410,23 @@ public class DatabaseManager { ...@@ -409,4 +410,23 @@ public class DatabaseManager {
} }
return result; return result;
} }
public int getNumberOfRegistrationsForTransport(String transport) {
int result = 0;
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(GET_SESSION_COUNT_FOR_TRANSPORT);
pstmt.setString(1, transport);
ResultSet rs = pstmt.executeQuery();
rs.next();
result = rs.getInt(1);
} catch (SQLException sqle) {
Log.error(sqle);
} finally {
DbConnectionManager.closeConnection(pstmt, con);
}
return result;
}
} }
...@@ -38,12 +38,12 @@ public class GojaraAdminProcessor extends AbstractRemoteRosterProcessor { ...@@ -38,12 +38,12 @@ public class GojaraAdminProcessor extends AbstractRemoteRosterProcessor {
handleStatistic(message, subdomain, "uptime"); handleStatistic(message, subdomain, "uptime");
} else if (command.equals("messages_from_xmpp")) { } else if (command.equals("messages_from_xmpp")) {
handleStatistic(message, subdomain, "messages_from_xmpp"); handleStatistic(message, subdomain, "messages_from_xmpp");
} else if (command.equals("messags_to_xmpp")) { } else if (command.equals("messages_to_xmpp")) {
handleStatistic(message, subdomain, "messages_to_xmpp"); handleStatistic(message, subdomain, "messages_to_xmpp");
} else if (command.equals("used_memory")) { } else if (command.equals("used_memory")) {
handleStatistic(message, subdomain, "used_memory"); handleStatistic(message, subdomain, "used_memory");
} else if (command.equals("used_memory_per_user")) { } else if (command.equals("average_memory_per_user")) {
handleStatistic(message, subdomain, "used_memory_per_user"); handleStatistic(message, subdomain, "average_memory_per_user");
} }
} }
......
package org.jivesoftware.openfire.plugin.gojara.sessions; package org.jivesoftware.openfire.plugin.gojara.sessions;
import java.text.DecimalFormat;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
...@@ -73,6 +74,8 @@ public class GojaraAdminManager { ...@@ -73,6 +74,8 @@ public class GojaraAdminManager {
*/ */
public void testAdminConfiguration(String gateway) { public void testAdminConfiguration(String gateway) {
unconfiguredGateways.add(gateway); unconfiguredGateways.add(gateway);
// we add these here and not in confirmGateway so its more clear that these are not being gathered when viewing
// Spectrum2 Stats jsp
getGatewayStatisticsMap().put(gateway, new HashMap<String, Integer>()); getGatewayStatisticsMap().put(gateway, new HashMap<String, Integer>());
Message message = new Message(); Message message = new Message();
...@@ -183,6 +186,7 @@ public class GojaraAdminManager { ...@@ -183,6 +186,7 @@ public class GojaraAdminManager {
refreshCooldown = System.currentTimeMillis(); refreshCooldown = System.currentTimeMillis();
Log.info("Gathering Gateway-Statistics!");
for (String gateway : configuredGateways) { for (String gateway : configuredGateways) {
uptime(gateway); uptime(gateway);
messagesFrom(gateway); messagesFrom(gateway);
...@@ -191,6 +195,7 @@ public class GojaraAdminManager { ...@@ -191,6 +195,7 @@ public class GojaraAdminManager {
averageMemoryOfUser(gateway); averageMemoryOfUser(gateway);
} }
} }
private void uptime(String transport) { private void uptime(String transport) {
Message message = generateCommand(transport, "uptime"); Message message = generateCommand(transport, "uptime");
router.route(message); router.route(message);
...@@ -216,4 +221,42 @@ public class GojaraAdminManager { ...@@ -216,4 +221,42 @@ public class GojaraAdminManager {
router.route(message); router.route(message);
} }
/**
* Preps the specified stat for nicer output which is used in tables.
* @param gateway
* @param stat
* @return
*/
public String getStatisticsPresentationString(String gateway, String stat) {
if (gatewayStatisticsMap.containsKey(gateway)) {
if (stat.equals("uptime")) {
if (gatewayStatisticsMap.get(gateway).get("uptime") != null) {
int time = gatewayStatisticsMap.get(gateway).get("uptime");
long diffSeconds = time % 60;
long diffMinutes = time / 60 % 60;
long diffHours = time / (60 * 60) % 24;
long diffDays = time / (24 * 60 * 60);
return "" + diffSeconds+ " Sec " + diffMinutes + " Min " + diffHours + " Hours " + diffDays + " Days";
}
} else if (stat.equals("messages_from_xmpp")) {
if (gatewayStatisticsMap.get(gateway).get("messages_from_xmpp") != null)
return "" + gatewayStatisticsMap.get(gateway).get("messages_from_xmpp");
} else if (stat.equals("messages_to_xmpp")) {
if (gatewayStatisticsMap.get(gateway).get("messages_to_xmpp") != null)
return "" + gatewayStatisticsMap.get(gateway).get("messages_to_xmpp");
} else if (stat.equals("used_memory")) {
if (gatewayStatisticsMap.get(gateway).get("used_memory") != null) {
DecimalFormat f = new DecimalFormat("#0.00");
double mb = gatewayStatisticsMap.get(gateway).get("used_memory") / 1024.0;
return "" + f.format(mb) + " MB";
}
} else if (stat.equals("average_memory_per_user")) {
if (gatewayStatisticsMap.get(gateway).get("average_memory_per_user") != null) {
return "" + gatewayStatisticsMap.get(gateway).get("average_memory_per_user") + " KB";
}
}
}
return "-";
}
} }
...@@ -201,6 +201,17 @@ public class TransportSessionManager { ...@@ -201,6 +201,17 @@ public class TransportSessionManager {
return result; return result;
} }
/**
* Returns number of active Sessions for specified transport or 0 if not valid transport.
* @param transport
* @return
*/
public int getNumberOfActiveSessionsFor(String transport) {
if (transportSessions.containsKey(transport))
return transportSessions.get(transport).size();
return 0;
}
/** /**
* Searches for Sessions with given Username and returns them as ArrList * Searches for Sessions with given Username and returns them as ArrList
* *
...@@ -242,4 +253,11 @@ public class TransportSessionManager { ...@@ -242,4 +253,11 @@ public class TransportSessionManager {
public int getNumberOfRegistrations() { public int getNumberOfRegistrations() {
return db.getNumberOfRegistrations(); return db.getNumberOfRegistrations();
} }
public int getNumberOfRegistrationsForTransport(String transport) {
if (transportSessions.containsKey(transport)) {
return db.getNumberOfRegistrationsForTransport(transport);
}
return 0;
}
} }
...@@ -58,6 +58,10 @@ ...@@ -58,6 +58,10 @@
<center> <center>
<% if (!gojaraAdminManager.areGatewaysConfigured()) {%>
<h2 style="color:red">Warning: Not all Gateways are configured for admin usage. This means unregistrations will not be properly executed.<br/>
Please configure admin_jid = gojaraadmin@yourdomain in Spectrum2 transport configuration.</h2>
<% } %>
<h5>Logintime 1970 means User did register but never logged in, <h5>Logintime 1970 means User did register but never logged in,
propably because of invalid credentials.</h5> propably because of invalid credentials.</h5>
</center> </center>
......
<%@ page <%@ page
import="org.jivesoftware.openfire.plugin.gojara.sessions.TransportSessionManager"%> import="org.jivesoftware.openfire.plugin.gojara.sessions.TransportSessionManager"%>
<%@ page
import="org.jivesoftware.openfire.plugin.gojara.sessions.GojaraAdminManager"%>
<%@ page <%@ page
import="org.jivesoftware.openfire.plugin.gojara.sessions.GatewaySession"%> import="org.jivesoftware.openfire.plugin.gojara.sessions.GatewaySession"%>
<%@ page <%@ page
...@@ -12,7 +15,7 @@ ...@@ -12,7 +15,7 @@
<% <%
TransportSessionManager transportManager = TransportSessionManager.getInstance(); TransportSessionManager transportManager = TransportSessionManager.getInstance();
GojaraAdminManager gojaraAdminManager = GojaraAdminManager.getInstance();
//Helper object for generation of sorting links, column restriction is done in DatabaseManager //Helper object for generation of sorting links, column restriction is done in DatabaseManager
Map<String, String> sortParams = new HashMap<String, String>(); Map<String, String> sortParams = new HashMap<String, String>();
if (request.getParameter("sortby") != null && request.getParameter("sortorder") != null) { if (request.getParameter("sortby") != null && request.getParameter("sortorder") != null) {
...@@ -33,6 +36,11 @@ ...@@ -33,6 +36,11 @@
<meta name="pageID" content="gojaraSessions" /> <meta name="pageID" content="gojaraSessions" />
</head> </head>
<body> <body>
<% if (!gojaraAdminManager.areGatewaysConfigured()) {%>
<center><h2 style="color:red">Warning: Not all Gateways are configured for admin usage. This means session details may be inaccurate or not logged at all.<br/>
Please configure admin_jid = gojaraadmin@yourdomain in Spectrum2 transport configuration.</h2></center>
<% } %>
<h4> <h4>
Current number of active Gateway Sessions: &emsp; Current number of active Gateway Sessions: &emsp;
<%=transportManager.getNumberOfActiveSessions()%> <%=transportManager.getNumberOfActiveSessions()%>
......
<%@page
import="org.jivesoftware.openfire.plugin.gojara.sessions.TransportSessionManager"%>
<%@ page
import="org.jivesoftware.openfire.plugin.gojara.sessions.GojaraAdminManager"%>
<%@ page import="java.util.Map"%>
<%@ page import="java.util.Set"%>
<%
TransportSessionManager transportSessionManager = TransportSessionManager.getInstance();
GojaraAdminManager gojaraAdminManager = GojaraAdminManager.getInstance();
gojaraAdminManager.gatherGatewayStatistics();
%>
<html>
<head>
<title>Spectrum2 gateway stats</title>
<meta name="pageID" content="gojaraGatewayStatistics" />
</head>
<body>
<%
if (!gojaraAdminManager.areGatewaysConfigured()) {
%>
<center>
<h2 style="color: red">
Warning: Not all Gateways are configured for admin usage. Affected
gateways will not show any data.<br /> Please configure admin_jid =
gojaraadmin@yourdomain in Spectrum2 transport configuration.
</h2>
</center>
<hr />
<%
}
%>
<br/><br/>
<div class="jive-table">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<thead>
<tr>
<th nowrap>Name</th>
<th nowrap># Online Users</th>
<th nowrap># Registrations</th>
<th nowrap>Uptime</th>
<th nowrap># Messages received</th>
<th nowrap># Messages sent</th>
<th nowrap>Used Memory</th>
<th nowrap>Avg. Memory per User</th>
</tr>
</thead>
<tbody>
<%
Set<String> gateways = gojaraAdminManager.getGatewayStatisticsMap().keySet();
for (String gateway : gateways) {
%>
<tr class="jive-odd">
<td><%=gateway %></td>
<td><%=transportSessionManager.getNumberOfActiveSessionsFor(gateway)%></td>
<td><%=transportSessionManager.getNumberOfRegistrationsForTransport(gateway)%></td>
<td><%=gojaraAdminManager.getStatisticsPresentationString(gateway, "uptime")%></td>
<td><%=gojaraAdminManager.getStatisticsPresentationString(gateway, "messages_from_xmpp")%></td>
<td><%=gojaraAdminManager.getStatisticsPresentationString(gateway, "messages_to_xmpp") %></td>
<td><%=gojaraAdminManager.getStatisticsPresentationString(gateway, "used_memory") %></td>
<td><%=gojaraAdminManager.getStatisticsPresentationString(gateway, "average_memory_per_user") %></td>
</tr>
<% } %>
</tbody>
</table>
</div>
</body>
</html>
\ No newline at end of file
...@@ -33,6 +33,11 @@ ...@@ -33,6 +33,11 @@
</script> </script>
</head> </head>
<body> <body>
<% if (!gojaraAdminManager.areGatewaysConfigured()) {%>
<center><h2 style="color:red">Warning: Not all Gateways are configured for admin usage. This means unregistrations will not be properly executed.<br/>
Please configure admin_jid = gojaraadmin@yourdomain in Spectrum2 transport configuration.</h2></center>
<% } %>
<% <%
if (request.getParameter(username) != null) { if (request.getParameter(username) != null) {
String[] unregister = request.getParameterValues(username); String[] unregister = request.getParameterValues(username);
...@@ -49,6 +54,7 @@ ...@@ -49,6 +54,7 @@
%> %>
<br> <br>
<br> <br>
<% <%
} }
ArrayList<GatewaySession> userconnections = transportManager.getConnectionsFor(username); ArrayList<GatewaySession> userconnections = transportManager.getConnectionsFor(username);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment