-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservices.html
162 lines (137 loc) · 5.31 KB
/
services.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
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="Keywords" content="x,y" />
<meta name="Description" content="x,y" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="-1" />
<style type="text/css" media="screen,all">
.service
{
display: inline-block;
padding: 1em;
margin: 0.1em;
}
.service > div
{
display: block;
text-align: center;
}
</style>
<script type="text/javascript">
<!--
function window_load()
{
setInterval( loadServiceStates, 600000 );
loadServiceStates();
}
function loadServiceStates()
{
fetch( (window.location.protocol === "file:" ? "https:" : "") + "//ackspace.nl/spaceAPI/" )
.then( response => response.json() )
.then( response => response.sensors.service )
.then( services =>
{
var serviceOverview = {};
// Compile info
services.forEach( service =>
{
if ( !( service.name in serviceOverview ) )
serviceOverview[ service.name ] = { source: [], score: 0, status: "", latency: null, timestamp: 0, emojiStatus: "" };
let serviceEntry = serviceOverview[ service.name ];
var timestamp = new Date( service.ext_lastchange * 1000 );
serviceEntry.source.push(
{
service : service.source,
status: service.status,
ext_lastchange: service.ext_lastchange,
timestamp: timestamp,
latency: service.latency || null
} );
if ( service.status === null )
serviceEntry.emojiStatus += "~";
else if ( service.status )
serviceEntry.emojiStatus += "+";
else
serviceEntry.emojiStatus += "-";
if ( timestamp > serviceEntry.timestamp )
serviceEntry.timestamp = timestamp;
let delta = new Date() - service.ext_lastchange * 1000;
// After 21 minutes or really high ping the service is considered failing
if ( delta > 1260000 || service.latency > 35000 )
{
console.log( "long delay" );
service.status = false;
}
else if ( delta > 660000 || service.latency > 20000 )
{
console.log( "delay" );
// After 11 minutes or relatively high ping, we lower all values
if ( service.status === null )
service.status = false;
else if ( service.status )
service.status === null;
}
// Assume only 1 latency item
if ( service.latency )
serviceEntry.latency = service.latency;
// Recalculate every time we have a next entry
serviceEntry.score += (service.status ? 10 : ( service.status === null ) ? 3 : 0);
let avgScore = Math.ceil( serviceEntry.score / serviceEntry.source.length );
if ( avgScore < 3 )
{
serviceEntry.status = "error";
serviceEntry.color = "red";
}
else if ( avgScore < 6 )
{
serviceEntry.status = "critical";
serviceEntry.color = "orange";
}
else if ( avgScore < 8 )
{
serviceEntry.status = "warning";
serviceEntry.color = "yellow";
}
else
{
serviceEntry.status = "ok";
serviceEntry.color = "lightgreen";
}
} );
// Empty node
let stateContainer = document.querySelector( ".states" )
stateContainer.innerHTML = "";
Object.keys( serviceOverview ).forEach( service =>
{
let serviceNode = document.createElement( "span" );
let nameNode = serviceNode.appendChild( document.createElement( "div" ) );
let stateNode = serviceNode.appendChild( document.createElement( "div" ) );
let emojiStateNode = serviceNode.appendChild( document.createElement( "div" ) );
let pingNode = serviceNode.appendChild( document.createElement( "div" ) );
serviceNode.title = serviceOverview[ service ].timestamp;
serviceNode.style.backgroundColor = serviceOverview[ service ].color;
serviceNode.className = "service";
nameNode.textContent = service;
stateNode.textContent = serviceOverview[ service ].status;
emojiStateNode.textContent = serviceOverview[ service ].emojiStatus;
if ( serviceOverview[ service ].latency )
pingNode.textContent = (serviceOverview[ service ].latency / 1000 ) + "ms";
else
pingNode.innerHTML = "∞";
stateContainer.appendChild( serviceNode );
} );
} );
}
window.addEventListener( "load", window_load, false );
//-->
</script>
</head>
<body>
Note: this page is written using EcmaScript6 syntax; it might not work in your browser..
<div class="states"></div>
</body>
</html>