-
Notifications
You must be signed in to change notification settings - Fork 72
/
pipeline.html
169 lines (155 loc) · 4.25 KB
/
pipeline.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
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>ArchiveBot Pipeline Monitor Station</title>
<link rel="stylesheet" type="text/css" href="/assets/jquery.dataTables.min.css">
<style>
html, body {
background-color: #D4E9E7;
color: black;
}
.cell_warn_higlight {
background-color: #FFC2E3 !important;
font-weight: bold;
}
</style>
</head>
<body>
<noscript>Please enable JavaScript or request this resource
as application/json for raw data.</noscript>
<table id="pipeline_table" class="display">
<thead>
<tr>
<th>Pipeline</th>
<th>Nickname</th>
<th>Version</th>
<th>Memory %</th>
<th>Free Disk Space</th>
<th>Disk %</th>
<th>Load Averages</th>
<th>Last Checkin</th>
<th>Status</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script type="text/javascript" src="/assets/jquery-3.4.1.min.js"></script>
<script type="text/javascript" charset="utf8" src="/assets/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/assets/jquery.timeago.js"></script>
<script>
var table;
var reloadInterval = 60 * 1000;
var memThreshold = 90;
var diskThreshold = 90;
var timestampThreshold = 60 * 5 * 1000;
/**
* Formats a byte quantity in TiB, GiB, or MiB.
*
* If the quantity is >= 1 TiB, we format as TiB.
* If the quantity is >= 1 GiB, we format as GiB.
* Otherwise, we format as MiB.
*
* Returns [quantity, suffix], where quantity is a number and
* suffix is a string.
*/
var formatBytes = (function () {
var tebibyte = Math.pow(2, 40);
var gibibyte = Math.pow(2, 30);
var mebibyte = Math.pow(2, 20);
return function(bytes) {
if (bytes >= tebibyte) {
return [bytes / tebibyte, 'TiB'];
} else if (bytes >= gibibyte) {
return [bytes / gibibyte, 'GiB'];
} else {
return [bytes / mebibyte, 'MiB'];
}
}
})();
/**
* Adaptation of ActiveSupport's #blank?.
*
* Returns true if the object is undefined, null, or is a string whose
* post-trim length is zero. Otherwise, returns false.
*/
var isBlank = function(o) {
return !o || o.trim().length === 0;
}
function initTable() {
table = $('#pipeline_table').DataTable({
"paging" : false,
"ajax" : {
"url" : "/pipelines",
"dataSrc" : "pipelines"
},
"columns" : [ {
"data" : "id"
}, {
"data" : "nickname",
"defaultContent" : "(unknown)"
}, {
"data" : "version"
}, {
"data" : "mem_usage",
"createdCell" : function(td, cellData, rowData, row, col) {
if (cellData > memThreshold) {
$(td).addClass('cell_warn_higlight');
}
}
}, {
"data" : "disk_available",
"createdCell": function(td, cellData, rowData, row, col) {
var result = formatBytes(parseInt(cellData, 10));
return $(td).text(result[0].toFixed(2) + ' ' + result[1]);
}
}, {
"data" : "disk_usage",
"createdCell" : function(td, cellData, rowData, row, col) {
if (cellData > diskThreshold) {
$(td).addClass('cell_warn_higlight');
}
}
}, {
"data": "load_average_1m",
"defaultContent": "(unknown)",
"createdCell": function(td, cellData, rowData, row, col) {
var a1m, a5m, a15m;
a1m = rowData['load_average_1m'];
a5m = rowData['load_average_5m'];
a15m = rowData['load_average_15m'];
if (!(isBlank(a1m) || isBlank(a5m) || isBlank(a15m))) {
$(td).text("" + a1m + ", " + a5m + ", " + a15m);
}
}
}, {
"data" : "ts",
"createdCell" : function(td, cellData, rowData, row, col) {
var timestamp = parseInt(cellData, 10);
var cellDate = new Date(timestamp * 1000);
var dateNow = new Date();
$(td).attr('title', cellDate.toLocaleString());
$(td).text(jQuery.timeago(cellDate));
if (dateNow.getTime() - cellDate.getTime() > timestampThreshold) {
$(td).addClass('cell_warn_higlight');
}
},
"className" : "dateFormatable"
}, {
"data": "status",
"defaultContent": "(unknown)"
}, ]
});
setTimeout(reloadTable, reloadInterval);
$('.dateFormatable').timeago();
}
function reloadTable() {
table.ajax.reload(function() {
setTimeout(reloadTable, reloadInterval);
})
}
$(document).ready(initTable);
</script>
</body>
</html>