Skip to content

Commit b1bb427

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

File tree

3 files changed

+137
-2
lines changed

3 files changed

+137
-2
lines changed

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: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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+
'use strict';
22+
23+
async function listStats() {
24+
let table = document.getElementById('stats-table');
25+
26+
let l;
27+
try {
28+
l = await (await fetch('/stats.json')).json();
29+
} catch(e) {
30+
console.error(e);
31+
l = [];
32+
}
33+
34+
if(l.length === 0) {
35+
table.textContent = '(No group found.)';
36+
return;
37+
}
38+
39+
for(let i = 0; i < l.length; i++)
40+
table.appendChild(formatGroup(l[i]));
41+
}
42+
43+
function formatGroup(group) {
44+
let tr = document.createElement('tr');
45+
let td = document.createElement('td');
46+
td.textContent = group.name;
47+
tr.appendChild(td);
48+
if(group.clients) {
49+
let td2 = document.createElement('td');
50+
let table = document.createElement('table');
51+
for(let i = 0; i < group.clients.length; i++) {
52+
let client = group.clients[i];
53+
let tr2 = document.createElement('tr');
54+
let td3 = document.createElement('td');
55+
td3.textContent = client.id;
56+
tr2.appendChild(td3);
57+
table.appendChild(tr2);
58+
if(client.up)
59+
for(let j = 0; j < client.up.length; j++)
60+
table.appendChild(formatConn('↑', client.up[j]));
61+
if(client.down)
62+
for(let j = 0; j < client.down.length; j++)
63+
table.appendChild(formatConn('↓', client.down[j]));
64+
}
65+
td2.appendChild(table);
66+
tr.appendChild(td2);
67+
}
68+
return tr;
69+
}
70+
71+
function formatConn(direction, conn) {
72+
let tr = document.createElement('tr');
73+
let td = document.createElement('td');
74+
tr.appendChild(td);
75+
let td2 = document.createElement('td');
76+
td2.textContent = conn.id;
77+
tr.appendChild(td2);
78+
let td3 = document.createElement('td');
79+
if(conn.maxBitrate)
80+
td3.textContent = direction + ' ' + conn.maxBitrate;
81+
else
82+
td3.textContent = direction;
83+
tr.appendChild(td3);
84+
let td4 = document.createElement('td');
85+
if(conn.tracks) {
86+
let table = document.createElement('table');
87+
for(let i = 0; i < conn.tracks.length; i++)
88+
table.appendChild(formatTrack(conn.tracks[i]));
89+
td4.appendChild(table);
90+
}
91+
tr.appendChild(td4);
92+
return tr;
93+
}
94+
95+
function formatTrack(track) {
96+
let tr = document.createElement('tr');
97+
let td = document.createElement('td');
98+
if(track.maxBitrate)
99+
td.textContent = `${track.bitrate||0}/${track.maxBitrate}`;
100+
else
101+
td.textContent = `${track.bitrate||0}`;
102+
tr.appendChild(td);
103+
let td2 = document.createElement('td');
104+
td2.textContent = `${Math.round(track.loss * 100)}%`;
105+
tr.appendChild(td2);
106+
let td3 = document.createElement('td');
107+
let text = '';
108+
if(track.rtt) {
109+
text = text + `${Math.round(track.rtt * 1000) / 1000}ms`;
110+
}
111+
if(track.jitter)
112+
text = text + ${Math.round(track.jitter * 1000) / 1000}ms`;
113+
td3.textContent = text;
114+
tr.appendChild(td3);
115+
return tr;
116+
}
117+
118+
listStats();

0 commit comments

Comments
 (0)