-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatus.html
216 lines (193 loc) · 8.09 KB
/
status.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
<!DOCTYPE html>
<html lang="en-US">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/angular-chart.js/0.10.2/angular-chart.min.css" rel="stylesheet" type="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular-resource.js"></script>
<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.1.1/Chart.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-chart.js/0.10.2/angular-chart.min.js"></script>
<style>
.body-bg {
background-color: #f2f2f2;
font-family: 'sans-serif'
}
.title {
color: white
}
.navbar-default {
background-color: #205081;
border-color: #205081;
}
.panel-success>.panel-heading {
background-color: #14892c;
color: white;
}
</style>
<body class="body-bg">
<div ng-app="myApp" ng-controller="myCtrl">
<nav class="navbar navbar-static-top navbar-default">
<div class="container-fluid">
<h2 class="title">
</i>Web Hawk</h2>
</div>
</nav>
<div class="container">
<div class="panel panel-default">
<div class="panel-body">
<div class="row clearfix">
<div class="col-md-12 column">
<div class="panel panel-success">
<div class="panel-heading clearfix">
<span class="pull-left">
<h3 class="panel-title" ng-if="good">
All Systems Operational
</h3>
<h3 class="panel-title" ng-if="!good">
Not All Systems Operational
</h3>
</span>
<span class="pull-right">
<p>@ {{ updated.substring(11) }}</p>
</span>
</div>
</div>
<div class="row">
<div class="col-md-12 column">
<div class="list-group">
<div class="list-group-item clearfix" ng-repeat="eachData in services">
<span class="pull-left clearfix">
<h4>
{{ eachData.Name }}
</h4>
<h6><i>{{ eachData.URL }}</i></h6>
</span>
<span class="pull-right clearfix">
<span class="label label-danger" ng-if="!eachData.Alive">Not Operational</span>
<span class="label label-success" ng-if="eachData.Alive">Operational</span>
<br/><i>{{ eachData.Msec.toFixed(2) }} ms </i>
</span>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="clearfix">
<canvas id="line" class="chart chart-line" chart-data="data" chart-labels="labels" chart-series="series" </canvas>
</div>
<div class="row clearfix" ng-if="news.length > 0">
<div class="col-md-12 column">
<H3>Recent Events</H3>
<div class="list-group">
<div class="list-group-item clearfix" ng-repeat="eachNews in news">
<span class="pull-left clearfix">
<h4>
{{ eachNews.Timestamp.substring(0, 16) }}
</h4>
</span>
<span class="pull-right clearfix">
{{ eachNews.Content }}
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
var app = angular.module("myApp", ["ngResource", "chart.js"])
app.factory('statusService', ['$resource', function($resource) {
return $resource("http://localhost:3001/up")
}])
app.factory('historyService', ['$resource', function($resource) {
return $resource("http://localhost:3001/history")
}])
app.factory('newsService', ['$resource', function($resource) {
return $resource("http://localhost:3001/news")
}])
app.controller("myCtrl", function(statusService, historyService, newsService, $scope, $http) {
$scope.services = []
$scope.good = true
$scope.updated = ""
$scope.news = []
statusService.get(function(res) {
setStatus(res)
}, function(error) {
// Error handler code
});
function setStatus(data){
$scope.updated = data.Timestamp
$scope.services = data.Services
data.Services.forEach(function(eachSvc){
$scope.good = $scope.good & eachSvc.Alive
})
// console.debug("status updated: " + JSON.stringify(data))
}
// Socket updates
var socket = io('http://localhost:3001/socket.io');
socket.on('updateEvent', function (data) {
// console.debug(data);
$scope.$apply(setStatus(JSON.parse(data)))
$scope.$apply(pushSvcData(JSON.parse(data)))
// socket.emit('my other event', { my: 'data' });
});
// Charts
$scope.labels = []; // X axis labels
$scope.series = []; // Each line description
$scope.data = []; // An array of array (one for each series)
var setProps = false
function pushSvcData(data){
// Early terminate
if (data.Timestamp == undefined || data.Timestamp.length < 16) {
return
}
// Pop anything over most recent limit
if ($scope.labels.length > 48) {
$scope.labels.shift()
$scope.data.forEach(function(eachDataSet){eachDataSet.shift()})
}
// Really push data
$scope.labels.push(data.Timestamp.substring(11,16))
svcArr = data.Services
for (var i in svcArr){
if (!setProps) {
$scope.series.push(svcArr[i].Name)
$scope.data.push([svcArr[i].Msec])
} else {
var nameIdx = $scope.series.indexOf(svcArr[i].Name)
if (nameIdx != -1) {
$scope.data[nameIdx].push(svcArr[i].Msec.toFixed(2))
}
}
}
if (!setProps) {
setProps = true
}
}
historyService.query(function(res) {
sortedData = res.sort(function(item1, item2){
return item1.Timestamp.localeCompare(item2.Timestamp);
})
sortedData.forEach(function(data){pushSvcData(data)})
// console.debug("HISTORY ===> " + JSON.stringify(sortedData))
}, function(error) {
// Error handler code
});
// News
function setNews(data){
$scope.news = data.News
console.debug("News updated: " + JSON.stringify(data.News))
}
newsService.get(function(res) {
setNews(res)
}, function(error) {
// Error handler code
});
})
</script>
</body>
</html>