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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
|
<!DOCTYPE html>
<html>
<head>
<title>Journal</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style type="text/css">
div#divlogs, div#diventry {
font-family: monospace;
font-size: 8pt;
background-color: #ffffff;
padding: 1em;
margin: 2em 0em;
border-radius: 10px 10px 10px 10px;
border: 1px solid threedshadow;
white-space: nowrap;
overflow-x: scroll;
}
div#diventry {
display: none;
}
div#divlogs {
display: block;
}
body {
background-color: #ededed;
color: #313739;
font: message-box;
margin: 5em;
}
td.timestamp {
text-align: right;
border-right: 1px dotted lightgrey;
padding-right: 5px;
}
td.process {
border-right: 1px dotted lightgrey;
padding-left: 5px;
padding-right: 5px;
}
td.message {
padding-left: 5px;
}
td.message > a:link, td.message > a:visited {
text-decoration: none;
color: #313739;
}
td.message-error {
padding-left: 5px;
color: red;
font-weight: bold;
}
td.message-error > a:link, td.message-error > a:visited {
text-decoration: none;
color: red;
}
td.message-highlight {
padding-left: 5px;
font-weight: bold;
}
td.message-highlight > a:link, td.message-highlight > a:visited {
text-decoration: none;
color: #313739;
}
td > a:hover, td > a:active {
text-decoration: underline;
color: #c13739;
}
table#tablelogs, table#tableentry {
border-collapse: collapse;
}
td.field {
text-align: right;
border-right: 1px dotted lightgrey;
padding-right: 5px;
}
td.data {
padding-left: 5px;
}
</style>
</head>
<body>
<!-- TODO:
- show red lines for reboots
- show contents of entries -->
<h1 id="title"></h1>
<div id="os"></div>
<div id="virtualization"></div>
<div id="cutoff"></div>
<div id="machine"></div>
<div id="usage"></div>
<div id="showing"></div>
<div id="divlogs"><table id="tablelogs"></table></div>
<a name="entry"></a>
<div id="diventry"><table id="tableentry"></table></div>
<form>
<input id="head" type="button" value="|<" onclick="entriesLoadHead();"/>
<input id="previous" type="button" value="<<" onclick="entriesLoadPrevious();"/>
<input id="next" type="button" value=">>" onclick="entriesLoadNext();"/>
<input id="tail" type="button" value=">|" onclick="entriesLoadTail();"/>
<input id="more" type="button" value="More" onclick="entriesMore();"/>
<input id="less" type="button" value="Less" onclick="entriesLess();"/>
</form>
<script type="text/javascript">
var first_cursor = null;
var last_cursor = null;
function setCookie(name, value, msec) {
var d = new Date();
d.setMilliseconds(d.getMilliseconds() + msec);
var v = escape(value) + "; expires=" + d.toUTCString();
document.cookie = name + "=" + value;
}
function getCookie(name) {
var i, l;
l = document.cookie.split(";");
for (i in l) {
var x, y, j;
j = l[i].indexOf("=");
x = l[i].substr(0, j);
y = l[i].substr(j+1);
if (x == name)
return unescape(y);
}
return null;
}
function getNEntries() {
var n;
n = getCookie("n_entries");
if (n == null)
return 50;
return parseInt(n);
}
function showNEntries(n) {
var showing = document.getElementById("showing");
showing.innerHTML = "Showing <b>" + n.toString() + "</b> entries.";
}
function setNEntries(n) {
if (n < 10)
n = 10;
else if (n > 1000)
n = 1000;
setCookie("n_entries", n.toString(), 30*24*60*60*1000);
showNEntries(n);
}
function machineLoad() {
var request = new XMLHttpRequest();
request.open("GET", "/machine");
request.onreadystatechange = machineOnResult;
request.setRequestHeader("Accept", "application/json");
request.send(null);
}
function formatBytes(u) {
if (u >= 1024*1024*1024*1024)
return (u/1024/1024/1024/1024).toFixed(1) + " TiB";
else if (u >= 1024*1024*1024)
return (u/1024/1024/1024).toFixed(1) + " GiB";
else if (u >= 1024*1024)
return (u/1024/1024).toFixed(1) + " MiB";
else if (u >= 1024)
return (u/1024).toFixed(1) + " KiB";
else
return u.toString() + " B";
}
function escapeHTML(s) {
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
}
function machineOnResult(event) {
if ((event.currentTarget.readyState != 4) ||
(event.currentTarget.status != 200 && event.currentTarget.status != 0))
return;
var d = JSON.parse(event.currentTarget.responseText);
var title = document.getElementById("title");
title.innerHTML = 'Journal of ' + d.hostname;
document.title = 'Journal of ' + d.hostname;
var machine = document.getElementById("machine");
machine.innerHTML = 'Machine ID is <b>' + d.machine_id + '</b>, current boot ID is <b>' + d.boot_id + '</b>.';
var cutoff = document.getElementById("cutoff");
var from = new Date(parseInt(d.cutoff_from_realtime) / 1000);
var to = new Date(parseInt(d.cutoff_to_realtime) / 1000);
cutoff.innerHTML = 'Journal begins at <b>' + from.toLocaleString() + '</b> and ends at <b>' + to.toLocaleString() + '</b>.';
var usage = document.getElementById("usage");
usage.innerHTML = 'Disk usage is <b>' + formatBytes(parseInt(d.usage)) + '</b>.';
var os = document.getElementById("os");
os.innerHTML = 'Operating system is <b>' + d.os_pretty_name + '</b>.';
var virtualization = document.getElementById("virtualization");
virtualization.innerHTML = d.virtualization == "bare" ? "Running on <b>bare metal</b>." : "Running on virtualization <b>" + d.virtualization + "</b>.";
}
function entriesLoad(range) {
var request = new XMLHttpRequest();
request.open("GET", "/entries");
request.onreadystatechange = entriesOnResult;
request.setRequestHeader("Accept", "application/json");
request.setRequestHeader("Range", "entries=" + range + ":" + getNEntries().toString());
request.send(null);
}
function entriesLoadNext() {
if (last_cursor == null)
entriesLoad("");
else
entriesLoad(last_cursor + ":1");
}
function entriesLoadPrevious() {
if (first_cursor == null)
entriesLoad("");
else
entriesLoad(first_cursor + ":-" + getNEntries().toString());
}
function entriesLoadHead() {
entriesLoad("");
}
function entriesLoadTail() {
entriesLoad(":-" + getNEntries().toString());
}
function entriesOnResult(event) {
if ((event.currentTarget.readyState != 4) ||
(event.currentTarget.status != 200 && event.currentTarget.status != 0))
return;
var logs = document.getElementById("tablelogs");
var lc = null;
var fc = null;
var i;
var l = event.currentTarget.responseText.split('\n');
if (l.length <= 1) {
logs.innerHTML = '<tbody><tr><td colspan="3"><i>No further entries...</i></td></tr></tbody>';
return;
}
var buf = '';
for (i in l) {
if (l[i] == '')
continue;
var d = JSON.parse(l[i]);
if (d.MESSAGE == undefined || d.__CURSOR == undefined)
continue;
if (fc == null)
fc = d.__CURSOR;
lc = d.__CURSOR;
var priority;
if (d.PRIORITY != undefined)
priority = parseInt(d.PRIORITY);
else
priority = 6;
if (priority <= 3)
clazz = "message-error";
else if (priority <= 5)
clazz = "message-highlight";
else
clazz = "message";
buf += '<tr><td class="timestamp">';
if (d.__REALTIME_TIMESTAMP != undefined) {
var timestamp = new Date(parseInt(d.__REALTIME_TIMESTAMP) / 1000);
buf += timestamp.toLocaleString();
}
buf += '</td><td class="process">';
if (d.SYSLOG_IDENTIFIER != undefined)
buf += d.SYSLOG_IDENTIFIER;
else if (d._COMM != undefined)
buf += d._COMM;
if (d._PID != undefined)
buf += "[" + d._PID + "]";
else if (d.SYSLOG_PID != undefined)
buf += "[" + d.SYSLOG_PID + "]";
buf += '</td><td class="' + clazz + '"><a href="#entry" onclick="onMessageClick(\'' + lc + '\');">';
if (d.MESSAGE == null)
buf += "[blob data]";
else if (d.MESSAGE instanceof Array)
buf += "[" + formatBytes(d.MESSAGE.length) + " blob data]";
else
buf += escapeHTML(d.MESSAGE);
buf += '</a></td></tr>';
}
logs.innerHTML = '<tbody>' + buf + '</tbody>';
if (fc != null)
first_cursor = fc;
if (lc != null)
last_cursor = lc;
}
function entriesMore() {
setNEntries(getNEntries() + 10);
entriesLoad(first_cursor);
}
function entriesLess() {
setNEntries(getNEntries() - 10);
entriesLoad(first_cursor);
}
function onResultMessageClick(event) {
if ((event.currentTarget.readyState != 4) ||
(event.currentTarget.status != 200 && event.currentTarget.status != 0))
return;
var d = JSON.parse(event.currentTarget.responseText);
document.getElementById("diventry").style.display = "block";
entry = document.getElementById("tableentry");
var buf = "";
for (var key in d){
buf += '<tr><td class="field">' + key + '</td><td class="data">' + d[key] + '</td></tr>';
}
entry.innerHTML = '<tbody>' + buf + '</tbody>';
}
function onMessageClick(t) {
var request = new XMLHttpRequest();
request.open("GET", "/entries?discrete");
request.onreadystatechange = onResultMessageClick;
request.setRequestHeader("Accept", "application/json");
request.setRequestHeader("Range", "entries=" + t + ":0:1");
request.send(null);
}
machineLoad();
entriesLoad("");
showNEntries(getNEntries());
</script>
</body>
</html>
|