aboutsummaryrefslogtreecommitdiff
path: root/juick-xmpp/src/main/java/com/juick
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-11-08 16:11:53 +0300
committerGravatar Vitaly Takmazov2016-11-08 16:11:53 +0300
commit40c1a196d019fbaf3dd8f0d8f6d1bdc8225bb7a0 (patch)
treee1a16a993a3f81a2f326bf6471d16570bf15c238 /juick-xmpp/src/main/java/com/juick
parent4314d834724bbb5c671e7300b7de865fe53c51fb (diff)
juick-xmpp: statsfile -> status
Diffstat (limited to 'juick-xmpp/src/main/java/com/juick')
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/XMPPServer.java2
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/controllers/StatusController.java31
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/s2s/CleaningUp.java106
3 files changed, 60 insertions, 79 deletions
diff --git a/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java b/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java
index b892f207..31aa0bc7 100644
--- a/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java
+++ b/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java
@@ -45,7 +45,6 @@ public class XMPPServer implements DisposableBean, Stream.StreamListener,
JuickBot bot;
public String HOSTNAME, componentName;
- public String STATSFILE = null;
public String keystore;
public String keystorePassword;
public List<String> brokenSSLhosts;
@@ -67,7 +66,6 @@ public class XMPPServer implements DisposableBean, Stream.StreamListener,
int componentPort = NumberUtils.toInt(env.getProperty("component_port"), 5347);
int s2sPort = NumberUtils.toInt(env.getProperty("s2s_port"), 5269);
JID Jid = new JID(env.getProperty("xmppbot_jid"));
- STATSFILE = env.getProperty("statsfile");
keystore = env.getProperty("keystore");
keystorePassword = env.getProperty("keystore_password");
brokenSSLhosts = Arrays.asList(env.getProperty("broken_ssl_hosts", "").split(","));
diff --git a/juick-xmpp/src/main/java/com/juick/components/controllers/StatusController.java b/juick-xmpp/src/main/java/com/juick/components/controllers/StatusController.java
new file mode 100644
index 00000000..9617ab56
--- /dev/null
+++ b/juick-xmpp/src/main/java/com/juick/components/controllers/StatusController.java
@@ -0,0 +1,31 @@
+package com.juick.components.controllers;
+
+import com.juick.components.XMPPServer;
+import com.juick.server.helpers.Status;
+import org.springframework.http.MediaType;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import javax.inject.Inject;
+
+/**
+ * Created by vitalyster on 24.10.2016.
+ */
+@Controller
+@ResponseBody
+public class StatusController {
+ @Inject
+ XMPPServer xmpp;
+
+ @RequestMapping(method = RequestMethod.GET, value = "/", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
+ public Status status() {
+ if (xmpp != null) {
+ String status = String.format("s2s in: %d, s2s out: %d, cached: %d",
+ xmpp.getInConnections().size(), xmpp.getOutConnections().size(), xmpp.getOutCache().size());
+ return new Status(status);
+ }
+ return new Status("Error");
+ }
+}
diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/CleaningUp.java b/juick-xmpp/src/main/java/com/juick/components/s2s/CleaningUp.java
index 031a7b34..52d2f3a6 100644
--- a/juick-xmpp/src/main/java/com/juick/components/s2s/CleaningUp.java
+++ b/juick-xmpp/src/main/java/com/juick/components/s2s/CleaningUp.java
@@ -2,9 +2,6 @@ package com.juick.components.s2s;
import com.juick.components.XMPPServer;
-import java.io.FileNotFoundException;
-import java.io.PrintWriter;
-import java.io.UnsupportedEncodingException;
import java.util.Iterator;
/**
@@ -21,89 +18,44 @@ public class CleaningUp implements Runnable {
@Override
public void run() {
while (true) {
- try {
- PrintWriter statsFile = new PrintWriter(xmpp.STATSFILE, "UTF-8");
- statsFile.write("<html><body><h2>Threads: " + Thread.activeCount() + "</h2>");
- statsFile.write("<h2>Out (" + xmpp.getOutConnections().size() + ")</h2><table border=1><tr><th>to</th><th>sid</th><th>inactive</th><th>out packets</th><th>out bytes</th></tr>");
-
- long now = System.currentTimeMillis();
-
- synchronized (xmpp.getOutConnections()) {
- for (Iterator<ConnectionOut> i = xmpp.getOutConnections().iterator(); i.hasNext();) {
- ConnectionOut c = i.next();
- int inactive = (int) ((double) (now - c.tsLocalData) / 1000.0);
- if (inactive > 900) {
- c.closeConnection();
- i.remove();
- } else {
- statsFile.write(" <tr>");
- statsFile.write(" <td>" + c.to + "</td>\n");
- statsFile.write(" <td>" + c.streamID + "</td>\n");
- statsFile.write(" <td>" + inactive + "</td>\n");
- statsFile.write(" <td>" + c.packetsLocal + "</td>\n");
- statsFile.write(" <td>" + c.bytesLocal + "</td>\n");
- statsFile.write(" <tr>");
- }
+ long now = System.currentTimeMillis();
+
+ synchronized (xmpp.getOutConnections()) {
+ for (Iterator<ConnectionOut> i = xmpp.getOutConnections().iterator(); i.hasNext(); ) {
+ ConnectionOut c = i.next();
+ int inactive = (int) ((double) (now - c.tsLocalData) / 1000.0);
+ if (inactive > 900) {
+ c.closeConnection();
+ i.remove();
}
}
+ }
- statsFile.write("</table><h2>In (" + xmpp.getInConnections().size() + ")</h2><table border=1><tr><th>from</th><th>sid</th><th>inactive</th><th>in packets</th></tr>");
-
- synchronized (xmpp.getInConnections()) {
- for (Iterator<ConnectionIn> i = xmpp.getInConnections().iterator(); i.hasNext();) {
- ConnectionIn c = i.next();
- int inactive = (int) ((double) (now - c.tsRemoteData) / 1000.0);
- if (inactive > 900) {
- c.closeConnection();
- i.remove();
- } else {
- statsFile.write(" <tr>");
- if (c.from.isEmpty()) {
- statsFile.write(" <td>&nbsp;</td>\n");
- } else if (c.from.size() == 1) {
- statsFile.write(" <td>" + c.from.get(0) + "</td>\n");
- } else {
- String out = " <td>";
- for (int n = 0; n < c.from.size(); n++) {
- if (n > 0) {
- out += "<br/>";
- }
- out += c.from.get(n);
- }
- statsFile.write(out + "</td>\n");
- }
- statsFile.write(" <td>" + c.streamID + "</td>\n");
- statsFile.write(" <td>" + inactive + "</td>\n");
- statsFile.write(" <td>" + c.packetsRemote + "</td>\n");
- statsFile.write(" <tr>");
- }
+ synchronized (xmpp.getInConnections()) {
+ for (Iterator<ConnectionIn> i = xmpp.getInConnections().iterator(); i.hasNext(); ) {
+ ConnectionIn c = i.next();
+ int inactive = (int) ((double) (now - c.tsRemoteData) / 1000.0);
+ if (inactive > 900) {
+ c.closeConnection();
+ i.remove();
}
}
+ }
- statsFile.write("</table><h2>Cache (" + xmpp.getOutCache().size() + ")</h2><table border=1><tr><th>host</th><th>live</th><th>size</th></tr>");
-
- synchronized (xmpp.getOutCache()) {
- for (Iterator<CacheEntry> i = xmpp.getOutCache().iterator(); i.hasNext();) {
- CacheEntry c = i.next();
- int inactive = (int) ((double) (now - c.tsCreated) / 1000.0);
- if (inactive > 600) {
- i.remove();
- } else {
- statsFile.write("<tr><td>" + c.hostname + "</td><td>" + inactive + "</td><td>" + c.xml.length() + "</td></tr>");
- }
+ synchronized (xmpp.getOutCache()) {
+ for (Iterator<CacheEntry> i = xmpp.getOutCache().iterator(); i.hasNext(); ) {
+ CacheEntry c = i.next();
+ int inactive = (int) ((double) (now - c.tsCreated) / 1000.0);
+ if (inactive > 600) {
+ i.remove();
}
}
-
- statsFile.write("</table></body></html>");
- statsFile.close();
-
- try {
- Thread.sleep(10000);
- } catch (InterruptedException e) {
- }
- } catch (FileNotFoundException e) {
- } catch (UnsupportedEncodingException e) {
}
+ try {
+ Thread.sleep(10000);
+ } catch (InterruptedException e) {
+ }
+
}
}
}