-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.html
235 lines (198 loc) · 5.53 KB
/
index.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
235
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/timeago.js/2.0.2/timeago.min.js" integrity="sha512-sl01o/gVwybF1FNzqO4NDRDNPJDupfN0o2+tMm4K2/nr35FjGlxlvXZ6kK6faa9zhXbnfLIXioHnExuwJdlTMA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<meta http-equiv="refresh" content="60" >
<title>Uptime</title>
</head>
<body>
<style>
body {
font-family: "Inter", "Helvetica Neue", "Helvetica", sans-serif;
}
#monitor, .monitor-part {
display: inline-block;
width: 100%;
}
#status-bars { }
#underline {
color: #555;
}
#before { float: left; }
#now { float: right; }
.bar {
font-weight: 720;
display: inline-block;
float: left;
font-size: 3rem;
}
.up {
color: #21c834 /* USWDS green-cool-30v */
}
#status .up {
color: #00a91c; /* USWDS green-cool-40v */
text-decoration: underline;
}
#status .dn {
color: #d83933; /* USWDS red-50 */
text-decoration: underline;
}
#status .missing {
color: #757575; /* USWDS gray-50 */
text-decoration: underline;
}
#status p, #details p {
font-size: 1rem;
}
#details p {
margin: 1rem 0;
}
#status h3 {
margin-bottom: 20px;
}
#details {
margin-top: 40px;
}
#refresh {
display: inline-block;
float: right;
margin-right: 5%;
}
.dn {
color: #e9695f; /* USWDS red-40 */
}
.missing {
color: #919191 /* USWDS gray-40 */
}
*[data-tooltip] {
position: relative;
}
*[data-tooltip]::after {
content: attr(data-tooltip);
position: absolute;
top: -20px;
right: -150px;
width: 300px;
pointer-events: none;
opacity: 0;
-webkit-transition: opacity .05s ease-in-out;
-moz-transition: opacity .05s ease-in-out;
-ms-transition: opacity .05s ease-in-out;
-o-transition: opacity .05s ease-in-out;
transition: opacity .05s ease-in-out;
display: block;
font-size: 1rem;
font-weight: 400;
line-height: 1.5rem;
color: #000;
background: #FFF;
padding: 2px 2px;
border: 1px solid #c0c0c0;
box-shadow: 2px 4px 5px rgba(0, 0, 0, 0.4);
}
*[data-tooltip]:hover::after {
opacity: 1;
}
</style>
<div id="status">
<h3>The 18F website is <span id="last-check-status" class="missing">unknown</span></h3>
<p>
<span id="last-check-timestamp"></span>
<span id="last-check-time-ago"></span>
<span id="refresh"><a href=".">Refresh</a></span>
</p>
</div>
<div id="monitor">
<div id="status-bars" class="monitor-part">
</div>
<div id="underline" class="monitor-part">
<div id="before" class="time">
~ 4 hours ago
</div>
<div id="now" class="time">
now
</div>
</div>
</div>
<div id="details">
<p>
<span id="monitored-url">
<a href="https://18f.gsa.gov">https://18f.gsa.gov</a>
</span>
•
<span id="last-check-http-status"></span>
</p>
</div>
<script>
const addBars = (lines) => {
const statusBars = document.getElementById("status-bars")
const linesLeft = 65 - lines.length
Array
.from(Array(linesLeft))
.map(x => createBar("missing", "missing", "no record"))
.map(element => statusBars.appendChild(element))
lines
.map(line => addBar(line))
.map(element => statusBars.appendChild(element))
return lines
}
const addBar = (line) => {
const lineObject = parseLine(line)
return createBar(lineObject.upOrDn, lineObject.upOrDown, lineObject.timestamp)
}
const parseLine = (line) => {
const [timeString, httpStatusCode, upOrDn] = line.split(" | ")
const datetime = new Date(timeString)
const timestamp = datetime.toLocaleString('en-US', {
weekday: 'long',
month: 'short',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
hour12: true
})
return {
datetime: new Date(timeString),
timestamp: timestamp,
httpCode: httpStatusCode,
upOrDn: upOrDn,
upOrDown: upOrDn == "up" ? "up" : "down"
}
}
Object.defineProperty(String.prototype, 'capitalize', {
value: function() {
return this.charAt(0).toUpperCase() + this.slice(1);
},
enumerable: false
});
const createBar = (upDnClass, upDown, timestamp) => {
const barDiv = document.createElement("div")
barDiv.classList.add('bar')
barDiv.classList.add(upDnClass)
barDiv.setAttribute('data-tooltip', `${upDown.capitalize()} • ${timestamp.capitalize()}`)
content = document.createTextNode("|")
barDiv.appendChild(content)
return barDiv
}
const updateStatus = (lines) => {
const lastCheck = parseLine(lines.at(-1))
const lastCheckStatus = document.getElementById("last-check-status")
lastCheckStatus.classList.toggle("missing")
lastCheckStatus.classList.toggle(lastCheck.upOrDn)
lastCheckStatus.innerText = lastCheck.upOrDown
document.getElementById("last-check-timestamp").innerText = `Last check: ${lastCheck.timestamp}`
document.getElementById("last-check-time-ago").innerText = `(${timeago().format(lastCheck.datetime)})`
document.getElementById("last-check-http-status").innerText = `Last HTTP status code: ${lastCheck.httpCode}`
}
fetch('readlog.txt')
.then(response => response.text())
.then(text => text.split('\n'))
.then(lines => lines.filter(line => line.length > 0))
.then(lines => addBars(lines))
.then(lines => updateStatus(lines))
</script>
</body>
</html>