summaryrefslogtreecommitdiffhomepage
path: root/html
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2023-02-04 12:43:51 +0100
committerRoland Reichwein <mail@reichwein.it>2023-02-04 12:43:51 +0100
commitc4a1f194e79a7834a54fdbf63d73c33e434b4825 (patch)
tree51eae6c701f38e47790b7200b423de8c89b38465 /html
parent1771f788a5b9e844f0a5315faee104648e3b7d88 (diff)
Added stats.html
Diffstat (limited to 'html')
-rw-r--r--html/stats.html35
-rw-r--r--html/stats.js96
2 files changed, 131 insertions, 0 deletions
diff --git a/html/stats.html b/html/stats.html
new file mode 100644
index 0000000..3f7e141
--- /dev/null
+++ b/html/stats.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8"/>
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <meta name="keywords" content="Reichwein, Whiteboard">
+ <title>Reichwein Whiteboard</title>
+ <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
+ <link rel="stylesheet" type="text/css" href="whiteboard.css"/>
+ <script src="stats.js"></script>
+ </head>
+ <body onload="init();">
+ <div class="qrwindow" id="qrwindow" hidden>
+ <img class="qrcode" id="qrcode"></img>
+ </div>
+ <div class="page">
+ <h1><img class="banner" src="banner256.png" alt="Reichwein.IT"/> Whiteboard</h1>
+ <h2>Statistics</h2>
+ <table>
+ <tr><td>Active Connections:</td><td id="numberofconnections" align="right"></td><td></td></tr>
+ <tr><td>Number of Documents:</td><td id="numberofdocuments" align="right"></td><td></td></tr>
+ <tr><td>Database Size (gross):</td><td id="dbsizegross" align="right"></td><td>Bytes</td></tr>
+ <tr><td>Database Size (net):</td><td id="dbsizenet" align="right"></td><td>Bytes</td></tr>
+ </table>
+ <br/>
+ <span id="status">Starting up...</span>
+ <button class="buttonred" id="reconnect" onclick="on_reconnect_click();" hidden>Reconnect</button>
+ <br/>
+ <br/>
+ Reichwein.IT Whiteboard <span id="version"></span> by <a href="https://www.reichwein.it">https://www.reichwein.it</a><br/>
+ </div>
+
+ <a id="download-a" hidden></a>
+ </body>
+</html>
diff --git a/html/stats.js b/html/stats.js
new file mode 100644
index 0000000..89c674a
--- /dev/null
+++ b/html/stats.js
@@ -0,0 +1,96 @@
+// started on main page load
+function init() {
+ init_stats();
+}
+
+function set_status(message)
+{
+ if (message == "") {
+ document.getElementById("status").textContent = message;
+ document.getElementById("status").style.display = 'inline';
+ } else {
+ document.getElementById("status").textContent = "";
+ document.getElementById("status").style.display = 'none';
+ }
+}
+
+var websocket;
+
+//
+// Callbacks for websocket data of different types
+//
+
+function on_stats(numberofdocuments, numberofconnections, dbsizegross, dbsizenet)
+{
+ document.getElementById("numberofdocuments").textContent = numberofdocuments;
+ document.getElementById("numberofconnections").textContent = numberofconnections;
+ document.getElementById("dbsizegross").textContent = dbsizegross;
+ document.getElementById("dbsizenet").textContent = dbsizenet;
+}
+
+function on_version(version)
+{
+ document.getElementById("version").textContent = version;
+}
+
+function on_message(e) {
+ var parser = new DOMParser();
+ var xmlDocument = parser.parseFromString(e.data, "text/xml");
+
+ var type = xmlDocument.getElementsByTagName("type")[0].textContent;
+
+ if (type == "stats") {
+ on_stats(xmlDocument.getElementsByTagName("numberofdocuments")[0].textContent,
+ xmlDocument.getElementsByTagName("numberofconnections")[0].textContent,
+ xmlDocument.getElementsByTagName("dbsizegross")[0].textContent,
+ xmlDocument.getElementsByTagName("dbsizenet")[0].textContent);
+ } else if (type == "version") {
+ on_version(xmlDocument.getElementsByTagName("version")[0].textContent);
+ } else if (type == "error") {
+ alert(xmlDocument.getElementsByTagName("message")[0].textContent);
+ } else {
+ alert("Unhandled message type: " + e.data + "|" + type);
+ }
+}
+
+function connect_websocket() {
+ document.getElementById("reconnect").style.display = 'none';
+ set_status("Connecting...");
+ var newlocation = location.origin + location.pathname;
+ newlocation = newlocation.replace(/^http/, 'ws');
+ newlocation = newlocation.replace(/stats.html$/, '');
+ if (newlocation.slice(-1) != "/")
+ newlocation += "/";
+ newlocation += "websocket";
+
+ websocket = new WebSocket(newlocation);
+
+ websocket.onmessage = function(e) { on_message(e); };
+
+ websocket.onopen = function(e) {
+ websocket.send("<request><command>getversion</command></request>");
+ websocket.send("<request><command>getstats</command></request>");
+ set_status(""); // ok
+ };
+
+ websocket.onclose = function(e) {
+ alert("Server connection closed.");
+ document.getElementById("reconnect").style.display = 'inline';
+ };
+
+ websocket.onerror = function(e) {
+ alert("Error: Server connection closed.");
+ document.getElementById("reconnect").style.display = 'inline';
+ };
+}
+
+// button in html
+function on_reconnect_click() {
+ connect_websocket();
+}
+
+function init_stats() {
+ set_status("Loading...");
+ connect_websocket();
+}
+