Skip to content

Commit 5c390a8

Browse files
committed
Add human-readable version of stats under /stats.html.
1 parent 3a6ade9 commit 5c390a8

3 files changed

Lines changed: 136 additions & 2 deletions

File tree

README

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ with others, there is no need to go through the landing page.
163163
Recordings can be accessed under `/recordings/groupname`. This is only
164164
available to the administrator of the group.
165165

166-
Some statistics are available under `/stats.json`. This is only available
167-
to the server administrator.
166+
Some statistics are available under `/stats.json`, with a human-readable
167+
version at `/stats.html`. This is only available to the server administrator.
168168

169169
## Side menu
170170

static/stats.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Galène statistics</title>
5+
<meta charset="utf-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<link rel="stylesheet" href="/common.css">
8+
<link rel="author" href="https://www.irif.fr/~jch/"/>
9+
</head>
10+
11+
<body>
12+
13+
<h1 id="title" class="navbar-brand">Galène statistics</h1>
14+
<table id="stats-table"></table>
15+
<script src="/stats.js" defer></script>
16+
</body>
17+
</html>

static/stats.js

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// Copyright (c) 2021 by Juliusz Chroboczek.
2+
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
// THE SOFTWARE.
20+
21+
async function listStats() {
22+
let table = document.getElementById('stats-table');
23+
24+
let l;
25+
try {
26+
l = await (await fetch('/stats.json')).json();
27+
} catch(e) {
28+
console.error(e);
29+
l = [];
30+
}
31+
32+
if(l.length === 0) {
33+
table.textContent = '(No group found.)';
34+
return;
35+
}
36+
37+
for(let i = 0; i < l.length; i++)
38+
table.appendChild(formatGroup(l[i]));
39+
}
40+
41+
function formatGroup(group) {
42+
let tr = document.createElement('tr');
43+
let td = document.createElement('td');
44+
td.textContent = group.name;
45+
tr.appendChild(td);
46+
if(group.clients) {
47+
let td2 = document.createElement('td');
48+
let table = document.createElement('table');
49+
for(let i = 0; i < group.clients.length; i++) {
50+
let client = group.clients[i];
51+
let tr2 = document.createElement('tr');
52+
let td3 = document.createElement('td');
53+
td3.textContent = client.id;
54+
tr2.appendChild(td3);
55+
table.appendChild(tr2);
56+
let td4 = document.createElement('td');
57+
if(client.up)
58+
for(let j = 0; j < client.up.length; j++)
59+
table.appendChild(formatConn('↑', client.up[j]));
60+
if(client.down)
61+
for(let j = 0; j < client.down.length; j++)
62+
table.appendChild(formatConn('↓', client.down[j]));
63+
}
64+
td2.appendChild(table);
65+
tr.appendChild(td2);
66+
}
67+
return tr;
68+
}
69+
70+
function formatConn(direction, conn) {
71+
let tr = document.createElement('tr');
72+
let td = document.createElement('td');
73+
tr.appendChild(td);
74+
let td2 = document.createElement('td');
75+
td2.textContent = conn.id;
76+
tr.appendChild(td2);
77+
let td3 = document.createElement('td');
78+
if(conn.maxBitrate)
79+
td3.textContent = direction + ' ' + conn.maxBitrate;
80+
else
81+
td3.textContent = direction;
82+
tr.appendChild(td3);
83+
let td4 = document.createElement('td');
84+
if(conn.tracks) {
85+
let table = document.createElement('table');
86+
for(let i = 0; i < conn.tracks.length; i++)
87+
table.appendChild(formatTrack(conn.tracks[i]));
88+
td4.appendChild(table);
89+
}
90+
tr.appendChild(td4);
91+
return tr;
92+
}
93+
94+
function formatTrack(track) {
95+
let tr = document.createElement('tr');
96+
let td = document.createElement('td');
97+
if(track.maxBitrate)
98+
td.textContent = `${track.bitrate||0}/${track.maxBitrate}`;
99+
else
100+
td.textContent = `${track.bitrate||0}`;
101+
tr.appendChild(td);
102+
td2 = document.createElement('td');
103+
td2.textContent = `${Math.round(track.loss * 100)}%`;
104+
tr.appendChild(td2);
105+
td3 = document.createElement('td');
106+
let text = '';
107+
if(track.rtt) {
108+
text = text + `${Math.round(track.rtt * 1000) / 1000}ms`;
109+
}
110+
if(track.jitter)
111+
text = text + ${Math.round(track.jitter * 1000) / 1000}ms`;
112+
td3.textContent = text;
113+
tr.appendChild(td3);
114+
return tr;
115+
}
116+
117+
listStats();

0 commit comments

Comments
 (0)