/
_checks.ejs
86 lines (86 loc) · 3.8 KB
/
_checks.ejs
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
<table class="table" id="checks">
<thead>
<tr>
<th>Name</th>
<th>Status</th>
<th title="Percentage of all pings up in the last 24h">Availability</th>
<th title="Percentage of all pings below slow threshold in the last 24h">Responsiveness</th>
<th title="Total downtime in the last 24h">Downtime</th>
<th title="Average response time of all pings in the last 24h">Avg. Response time</th>
</tr>
</thead>
<tbody></tbody>
</table>
<script src="<%= route %>/javascripts/jquery.tablesorter.min.js"></script>
<script src="<%= route %>/javascripts/ejs.min.js"></script>
<script id="check_template" type="text/template">
<tr>
<td data-sort="{{= check.name }}">
<a href="{{= route + '/checks/' + check._id }}">{{= check.name }}</a>
<a href="{{= check.url }}" target="_blank"><img src="{{= route }}/images/external-link-ltr-icon.png"></a>
</td>
{{ if (check.lastTested) { }}
{{ if (check.isPaused) { }}
<td data-sort="{{= check.isUp ? check.uptime : -check.downtime }}"><span class="label label-info">paused</span> <span class="blue"> for <span title="{{= new Date(check.lastTested) }}">{{= moment(check.lastChanged).fromNow(true) }}</span></span></td>
{{ } else if (check.isUp) { }}
<td data-sort="{{= check.uptime }}"><span class="label label-success">Up</span> <span class="green"> for <span title="{{= new Date(check.lastChanged) }}">{{= moment(check.lastChanged).fromNow(true) }}</span></span></td>
{{ } else { }}
<td data-sort="{{= -check.downtime }}"><span class="label label-important">Down</span> <span class="red"> for <span title="{{= new Date(check.lastChanged) }}">{{= moment(check.lastChanged).fromNow(true) }}</span></span></td>
{{ } }}
{{ } else { }}
<td data-sort="0"><span class="label label-important">down</span> <span class="label label-warning">new</span></td>
{{ } }}
{{ if (check.qos) { }}
<td data-sort="{{= check.qos.ups / check.qos.count }}">{{= ((check.qos.ups / check.qos.count) * 100).toFixed(3).replace('.000', '') }}%</td>
<td data-sort="{{= check.qos.responsives / check.qos.count }}">{{= ((check.qos.responsives / check.qos.count) * 100).toFixed(3).replace('.000', '') }}%</td>
<td data-sort="{{= check.qos.downtime }}">{{= (check.qos.downtime / 1000).toFixed() }}s</td>
<td data-sort="{{= check.qos.time / check.qos.count }}">{{= Math.round(check.qos.time / check.qos.count) }}ms</td>
{{ } else { }}
<td data-sort="0">-</td>
<td data-sort="0">-</td>
<td data-sort="0">-</td>
<td data-sort="0">-</td>
{{ } }}
</tr>
</script>
<script>
jQuery(document).ready(function($) {
var init = function() {
$('#checks').tablesorter({
textExtraction: function(node) {
return $(node).data('sort');
},
sortList: [[1,0]]
});
var check_template = document.getElementById('check_template').innerHTML;
var ejs = require('ejs');
ejs.open = '{{';
ejs.close = '}}';
var updateChecks = function() {
$.getJSON('<%= url %>', function(checks) {
var lines = [];
var lastTest = 0;
$.each(checks, function(key, check) {
if (new Date(check.lastTested) > lastTest) {
lastTest = new Date(check.lastTested);
}
lines.push(ejs.render(check_template, { check: check, route: '<%= route %>' }));
});
$('#checks tbody').html(lines.join(''));
$('#checks').trigger('update');
if (lastTest) {
$('#last_update').text('Last updated on ' + moment(lastTest).format('LLLL'));
}
});
}
updateChecks();
socket.on('CheckEvent', updateChecks);
window.setInterval(updateChecks, 5 * 60 * 1000); // refresh every 5 minutes to update the qos scores
};
if ($('a[data-toggle="tab"]').length) {
$('a[data-toggle="tab"][href="#tagchecks"]').one('shown', init);
} else {
init();
}
});
</script>