-
Notifications
You must be signed in to change notification settings - Fork 8
/
status.html
234 lines (224 loc) · 6.96 KB
/
status.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="application-name" content="TVHadmin">
<link rel="manifest" href="manifest.webmanifest" crossorigin="use-credentials">
<title>TVHadmin - Status</title>
<script src="include.js"></script>
<script>
function set_table_layouts() {
var tableArr = document.getElementsByClassName('list');
var cellWidth = 0;
// get widest
for(i = 0; i < tableArr.length; i++) {
if(cellWidth < tableArr[i].rows[1].cells[0].clientWidth
&& tableArr[i].rows[1].cells.length > 1)
cellWidth = tableArr[i].rows[1].cells[0].clientWidth;
}
// set all columns to the widest width found
for(i = 0; i < tableArr.length; i++) {
tableArr[i].rows[1].cells[0].style.width = cellWidth+'px';
}
}
async function get_input_status() {
const response = await fetch("/api/status/inputs");
const ret = await response.json();
return ret.entries;
}
async function get_server_info() {
const response = await fetch("/api/serverinfo");
const ret = await response.json();
return ret;
}
function clear_input_stats(uuid) {
fetch(`/api/status/inputclrstats?uuid=${uuid}`).then(() => {
location.reload();
});
}
async function get_status_xml() {
const response = await fetch("/status.xml");
const ret = await response.text();
return ret;
}
async function get_comet_poll() {
const response = await fetch("/comet/poll");
const ret = await response.json();
return ret;
}
</script>
</head>
<body>
<div id="container">
<div id="navigation">
<div class="logo">
<img src="images/logo.png" alt="TVHeadend Logo" width="150">
</div>
<div class="nav_bar">
</div>
</div>
<div id='layout'>
<div id='banner'>
<table>
<tr>
<td class='col_title'><div id='mobmenu'>☰</div> <h1>Status</h1></td>
</tr>
</table>
</div>
<div id='wrapper'>
<div id='content'>
<table class='list' id='systable'>
<tr class='heading'>
<td class='col_name' colspan=2><h2>System Information</h2></td>
</tr>
<tr class='row_alt'>
<td class='col_channel'>Software Version</td><td class='col_name'></td>
</tr>
<tr class='row_alt'>
<td class='col_channel'>System Load</td><td class='col_name'></td>
</tr>
<tr class='row_alt'>
<td class='col_channel'>Free Disk Space</td><td class='col_name'></td>
</tr>
<tr class='row_alt'>
<td class='col_channel'>Recording</td><td class='col_name'></td>
</tr>
<tr class='row_alt'>
<td class='col_channel'>Subscriptions</td><td class='col_name'></td>
</tr>
</table>
<table class='list' id='devtable'>
<tr class='heading' id='devhead'>
<td class='col_name'><h2>Devices</h2></td>
</tr>
<tr id='dev2'>
<td></td>
</tr>
</table>
</div>
</div>
</div>
</div>
<script>
const items = {
subs: 'Subscribers',
weight: 'Weight',
bps: 'Bandwidth',
ber: 'Bit Error Rate',
unc: 'Uncorrected Blocks',
te: 'Transport Errors',
cc: 'Continuity Errors',
signal: 'Signal Strength',
snr: 'Signal / Noise Ratio',
stream: 'Stream',
ec_block: 'Block Error Count',
tc_bit: 'Total Bit Error Count',
tc_block: 'Total Block Error Count',
ec_bit: 'Bit Error Count',
};
async function update(stats) {
var systable = document.getElementById("systable");
var xml = await get_status_xml();
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(xml,"text/xml");
var load = xmlDoc.getElementsByTagName("systemload")[0].childNodes[0].nodeValue;
load = load.replace(/(\d{2})\d*/g, '$1');
load = load.replace(/,/g, ', ');
systable.rows[2].cells[1].innerHTML = load;
var poll = await get_comet_poll();
var free = poll.messages[0].freediskspace / 1073741824;
var total = poll.messages[0].totaldiskspace / 1073741824;
var pc = free*100/total;
var text = free.toFixed(1) + " GB (" + pc.toFixed(1) + "%)";
systable.rows[3].cells[1].innerHTML = text;
var x = xmlDoc.getElementsByTagName("next")[0];
if (x) {
let t = x.childNodes[0].nodeValue;
text = "Next: " + strftime('%F %H:%M', Date.now()/1000 + 60*t);
}
else {
x = xmlDoc.getElementsByTagName("title");
if (x.length) {
text = "Recording:";
for (let i=0; i<x.length; i++) {
text += ` "${x[i].childNodes[0].nodeValue}"`;
}
}
else text = "";
}
systable.rows[4].cells[1].innerHTML = text;
var subs = xmlDoc.getElementsByTagName("subscriptions")[0].childNodes[0].nodeValue;
systable.rows[5].cells[1].innerHTML = subs;
var devtable = document.getElementById("devtable");
if (!stats) stats = await get_input_status();
for (let i=0; i<stats.length; i++) {
switch(stats[i].signal_scale) {
case 1:
stats[i].signal = Math.round(stats[i].signal * 100 / 65535) + ' %';
break;
case 2:
stats[i].signal = Math.round(stats[i].signal / 1000, 1) + ' dBm';
break;
default:
stats[i].signal = 0;
}
switch(stats[i].snr_scale) {
case 1:
stats[i].snr = Math.round(stats[i].snr * 100 / 65535) + ' %';
break;
case 2:
stats[i].snr = Math.round(stats[i].snr / 1000, 1) + ' dB';
break;
default:
stats[i].snr = 0;
}
}
var i = 2;
for (var k in items) {
var j = 1;
for (var s of stats) {
let x = devtable.rows[i].cells;
if (k in s) x[j].innerHTML = s[k];
else x[j].innerHTML = '';
j++;
}
i++;
}
}
async function main() {
var cookies = get_cookies();
var systable = document.getElementById("systable");
var info = await get_server_info();
systable.rows[1].cells[1].innerHTML = info.sw_version;
var stats = await get_input_status();
var devtable = document.getElementById("devtable");
var devhead = document.getElementById("devhead");
var dev2 = document.getElementById("dev2");
for (var s of stats) {
var title = devhead.insertCell();
title.className = 'col_name';
title.innerHTML = `<h2>${s.input}</h2>`;
var button = dev2.insertCell();
button.className = 'col_name';
button.innerHTML = `<button type='button' onclick='clear_input_stats("${s.uuid}")'>Clear Counters</button>`;
}
for (var k in items) {
var row = devtable.insertRow(-1);
row.className = 'row_alt';
title = row.insertCell();
title.classname = 'col_channel';
title.innerHTML = `${items[k]}`;
for (var s of stats) {
const c = row.insertCell();
c.classname = 'col_name';
}
}
update(stats);
if (cookies.REFS) setInterval(update, 5000, 0);
set_table_layouts();
}
main();
</script>
</body>
</html>