status page with some MW internals

This commit is contained in:
Zlatin Balevsky
2020-03-19 18:12:52 +00:00
parent a9539c5999
commit e542a50260
8 changed files with 163 additions and 4 deletions

View File

@ -113,11 +113,11 @@ public class Core {
final TrustSubscriber trustSubscriber
private final PersisterService persisterService
private final PersisterFolderService persisterFolderService
private final HostCache hostCache
private final ConnectionManager connectionManager
final HostCache hostCache
final ConnectionManager connectionManager
private final CacheClient cacheClient
private final UpdateClient updateClient
private final ConnectionAcceptor connectionAcceptor
final ConnectionAcceptor connectionAcceptor
private final ConnectionEstablisher connectionEstablisher
private final HasherService hasherService
final DownloadManager downloadManager

View File

@ -60,7 +60,7 @@ class ConnectionAcceptor {
private volatile shutdown
private volatile int browsed
volatile int browsed
ConnectionAcceptor(EventBus eventBus, UltrapeerConnectionManager manager,
MuWireSettings settings, I2PAcceptor acceptor, HostCache hostCache,

View File

@ -0,0 +1,53 @@
package com.muwire.webui;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.muwire.core.Core;
public class StatusServlet extends HttpServlet {
private Core core;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
StringBuilder sb = new StringBuilder();
sb.append("<?xml version='1.0' encoding='UTF-8'?>");
int incoming = (int)core.getConnectionManager().getConnections().stream().filter(c -> c.isIncoming()).count();
int outgoing = (int)core.getConnectionManager().getConnections().stream().filter(c -> !c.isIncoming()).count();
int knownHosts = core.getHostCache().getHosts().size();
int failingHosts = core.getHostCache().countFailingHosts();
int hopelessHosts = core.getHostCache().countHopelessHosts();
int timesBrowsed = core.getConnectionAcceptor().getBrowsed();
sb.append("<Status>");
sb.append("<IncomingConnections>").append(incoming).append("</IncomingConnections>");
sb.append("<OutgoingConnections>").append(outgoing).append("</OutgoingConnections>");
sb.append("<KnownHosts>").append(knownHosts).append("</KnownHosts>");
sb.append("<FailingHosts>").append(failingHosts).append("</FailingHosts>");
sb.append("<HopelessHosts>").append(hopelessHosts).append("</HopelessHosts>");
sb.append("<TimesBrowsed>").append(timesBrowsed).append("</TimesBrowsed>");
sb.append("</Status>");
resp.setContentType("text/xml");
resp.setCharacterEncoding("UTF-8");
resp.setDateHeader("Expires", 0);
resp.setHeader("Pragma", "no-cache");
resp.setHeader("Cache-Control", "no-store, max-age=0, no-cache, must-revalidate");
byte[] out = sb.toString().getBytes("UTF-8");
resp.setContentLength(out.length);
resp.getOutputStream().write(out);
}
@Override
public void init(ServletConfig config) throws ServletException {
core = (Core) config.getServletContext().getAttribute("core");
}
}

View File

@ -57,6 +57,7 @@ public class Util {
_x("Enter a full MuWire id"),
_x("Enter Reason (Optional)"),
_x("ETA"),
_x("Failing Hosts"),
_x("Feed configuration for {0}"),
_x("Feed update frequency (minutes)"),
_x("Feeds"),
@ -67,16 +68,21 @@ public class Util {
_x("Hashing"),
_x("Hide Certificates"),
_x("Hide Comment"),
_x("Hopeless Hosts"),
_x("Host"),
_x("Import"),
_x("Imported"),
_x("Incoming Connections"),
_x("Known Hosts"),
_x("Known Sources"),
_x("Last Updated"),
_x("Mark Distrusted"),
_x("Mark Neutral"),
_x("Mark Trusted"),
_x("MuWire Status"),
_x("Name"),
_x("Number of items to keep on disk (-1 means unlimited)"),
_x("Outgoing Connections"),
// verb
_x("Pause"),
_x("Piece Size"),
@ -111,6 +117,7 @@ public class Util {
_x("Submit"),
_x("Subscribe"),
_x("Subscribed"),
_x("Times Browsed"),
_x("Total Pieces"),
_x("Trust"),
_x("Trusted"),

View File

@ -0,0 +1,27 @@
function refreshStatus() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var incomingConnections = this.responseXML.getElementsByTagName("IncomingConnections")[0].childNodes[0].nodeValue
var outgoingConnections = this.responseXML.getElementsByTagName("OutgoingConnections")[0].childNodes[0].nodeValue
var knownHosts = this.responseXML.getElementsByTagName("KnownHosts")[0].childNodes[0].nodeValue
var failingHosts = this.responseXML.getElementsByTagName("FailingHosts")[0].childNodes[0].nodeValue
var hopelessHosts = this.responseXML.getElementsByTagName("HopelessHosts")[0].childNodes[0].nodeValue
var timesBrowsed = this.responseXML.getElementsByTagName("TimesBrowsed")[0].childNodes[0].nodeValue
document.getElementById("incoming-connections").innerHTML = incomingConnections
document.getElementById("outgoing-connections").innerHTML = outgoingConnections
document.getElementById("known-hosts").innerHTML = knownHosts
document.getElementById("failing-hosts").innerHTML = failingHosts
document.getElementById("hopeless-hosts").innerHTML = hopelessHosts
document.getElementById("times-browsed").innerHTML = timesBrowsed
}
}
xmlhttp.open("GET", "/MuWire/Status", true);
xmlhttp.send();
}
function initStatus() {
setInterval(refreshStatus, 3000);
setTimeout(refreshStatus, 1);
}

View File

@ -0,0 +1,53 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="com.muwire.webui.*" %>
<%@include file="initcode.jsi"%>
<%
String pagetitle=Util._t("MuWire Status");
%>
<html>
<head>
<%@ include file="css.jsi"%>
<script src="js/status.js?<%=version%>" type="text/javascript"></script>
</head>
<body onload="initConnectionsCount(); initStatus();">
<%@ include file="header.jsi"%>
<aside>
<div class="menubox-divider"></div>
<%@include file="sidebar.jsi"%>
</aside>
<section class="main foldermain">
<table>
<tr>
<td><%=Util._t("Incoming Connections")%></td>
<td><span id="incoming-connections"></span></td>
</tr>
<tr>
<td><%=Util._t("Outgoing Connections")%></td>
<td><span id="outgoing-connections"></span></td>
</tr>
<tr>
<td><%=Util._t("Known Hosts")%></td>
<td><span id="known-hosts"></span></td>
</tr>
<tr>
<td><%=Util._t("Failing Hosts")%></td>
<td><span id="failing-hosts"></span></td>
</tr>
<tr>
<td><%=Util._t("Hopeless Hosts")%></td>
<td><span id="hopeless-hosts"></span></td>
</tr>
<tr>
<td><%=Util._t("Times Browsed")%></td>
<td><span id="times-browsed"></span></td>
</tr>
</table>
</section>
</body>
</html>

View File

@ -81,6 +81,10 @@
<div class="menu-icon"></div>
<div class="menu-text"><%=Util._t("About Me")%></div>
</a>
<a class="menuitem settings" href="MuStatus">
<div class="menu-icon"></div>
<div class="menu-text"><%=Util._t("MuWire")%></div>
</a>
</div>
<!--
<div class="menubox-divider"></div>

View File

@ -71,6 +71,11 @@
<servlet-class>com.muwire.webui.FeedServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>com.muwire.webui.StatusServlet</servlet-name>
<servlet-class>com.muwire.webui.StatusServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>com.muwire.webui.MuWireServlet</servlet-name>
<url-pattern>/index.jsp</url-pattern>
@ -131,6 +136,11 @@
<url-pattern>/Feed</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>com.muwire.webui.StatusServlet</servlet-name>
<url-pattern>/Status</url-pattern>
</servlet-mapping>
__JASPER__
<!--
@ -203,4 +213,9 @@ Mappings without the .jsp suffix
<url-pattern>/AboutMe</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>com.muwire.webui.MuStatus_jsp</servlet-name>
<url-pattern>/MuStatus</url-pattern>
</servlet-mapping>
</web-app>