Skip to content

Commit ab73c46

Browse files
committed
Minor improvements
1 parent 1683756 commit ab73c46

File tree

4 files changed

+48
-37
lines changed

4 files changed

+48
-37
lines changed

config.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
metrics: true
22
services:
3-
- name: twinnation
3+
- name: Twinnation
44
url: https://twinnation.org/actuator/health
5-
interval: 15s
5+
interval: 30s
66
conditions:
77
- "[STATUS] == 200"
8-
- name: github
8+
- name: GitHub API
99
url: https://api.github.com/healthz
10+
interval: 30s
1011
conditions:
1112
- "[STATUS] == 200"

core/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type ServerMessage struct {
2323
type Result struct {
2424
HttpStatus int `json:"status"`
2525
Hostname string `json:"hostname"`
26-
Ip string `json:"ip"`
26+
Ip string `json:"-"`
2727
Duration time.Duration `json:"duration"`
2828
Errors []string `json:"errors"`
2929
ConditionResults []*ConditionResult `json:"condition-results"`
@@ -88,7 +88,7 @@ func (service *Service) EvaluateConditions() *Result {
8888
type ConditionResult struct {
8989
Condition *Condition `json:"condition"`
9090
Success bool `json:"success"`
91-
Explanation string `json:"explanation"`
91+
Explanation string `json:"-"`
9292
}
9393

9494
type Condition string

static/index.html

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,23 @@
44
<title>Status</title>
55
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
66
<style>
7-
td > span.badge {
7+
#results div.container:first-child {
8+
border-top-left-radius: 3px;
9+
border-top-right-radius: 3px;
10+
}
11+
#results div.container:last-child {
12+
border-bottom-left-radius: 3px;
13+
border-bottom-right-radius: 3px;
14+
border-bottom-width: 1px;
15+
border-color: #dee2e6;
16+
border-style: solid;
17+
}
18+
.status-ok {
819
display: inline-block;
9-
width: 20px;
10-
cursor: default;
11-
margin-right: 2px;
20+
width: 1%;
21+
height: 20px;
22+
margin-right: 4px;
23+
background-color: #28a745;
1224
}
1325
</style>
1426
</head>
@@ -17,19 +29,7 @@
1729
<div class="text-center mb-3">
1830
<div class="display-4">Status</div>
1931
</div>
20-
<div class="table-responsive">
21-
<table class="table">
22-
<thead>
23-
<tr>
24-
<th scope="col">Name</th>
25-
<th scope="col">Status</th>
26-
<th scope="col">Hostname</th>
27-
<th scope="col">Response time</th>
28-
</tr>
29-
</thead>
30-
<tbody id="results">
31-
</tbody>
32-
</table>
32+
<div id="results">
3333
</div>
3434
</div>
3535

@@ -38,8 +38,9 @@
3838
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
3939

4040
<script>
41-
const OK = "<span class='badge badge-success' title='__RESPONSE_TIME____CONDITIONS____ERRORS__'>&#10003;</span>";
42-
const NOK = "<span class='badge badge-danger' title='__RESPONSE_TIME____CONDITIONS____ERRORS__'>X</span>";
41+
//const OK = "<div class='status-ok' title='__RESPONSE_TIME____CONDITIONS____ERRORS__'></div>"
42+
const OK = "<span class='badge badge-success ml-1' style='width: 5%' title='__RESPONSE_TIME____CONDITIONS____ERRORS__'>&#10003;</span>";
43+
const NOK = "<span class='badge badge-danger ml-1' style='width: 5%' title='__RESPONSE_TIME____CONDITIONS____ERRORS__'>X</span>";
4344

4445
function generateServiceResultBox(serviceResult) {
4546
let output = (serviceResult.success ? OK : NOK);
@@ -62,9 +63,9 @@
6263
return output;
6364
}
6465

65-
function refreshTable() {
66+
function refreshResults() {
6667
$.getJSON("/api/v1/results", function (data) {
67-
let tableBody = "";
68+
let output = "";
6869
for (let serviceName in data) {
6970
let serviceStatusOverTime = "";
7071
let hostname = data[serviceName][data[serviceName].length-1].hostname
@@ -82,21 +83,30 @@
8283
maxResponseTime = responseTime;
8384
}
8485
}
85-
tableBody += ""
86-
+ "<tr>"
87-
+ " <td>" + serviceName + "</td>"
88-
+ " <td>" + serviceStatusOverTime + "</td>"
89-
+ " <td><a href=\"//" + hostname + "\">" + hostname + "</a></td>"
90-
+ " <td>" + (minResponseTime === maxResponseTime ? minResponseTime : (minResponseTime + "-" + maxResponseTime)) + "ms</td>"
91-
+ "</tr>";
86+
output += ""
87+
+ "<div class='container p-2 border-left border-right border-top border-black'>"
88+
+ " <div class='row mb-2'>"
89+
+ " <div class='col-8'>"
90+
+ " <span class='font-weight-bold'>" + serviceName + "</span> <span class='text-secondary font-weight-lighter'>- " + hostname + "</span>"
91+
+ " </div>"
92+
+ " <div class='col-4 text-right'>"
93+
+ " <span class='font-weight-lighter'>" + (minResponseTime === maxResponseTime ? minResponseTime : (minResponseTime + "-" + maxResponseTime)) + "ms</span>"
94+
+ " </div>"
95+
+ " </div>"
96+
+ " <div class='row'>"
97+
+ " <div class='col-12 d-flex flex-row-reverse'>"
98+
+ " " + serviceStatusOverTime
99+
+ " </div>"
100+
+ " </div>"
101+
+ "</div>";
92102
}
93-
$("#results").html(tableBody);
103+
$("#results").html(output);
94104
});
95105
}
96106

97-
refreshTable();
107+
refreshResults();
98108
setInterval(function() {
99-
refreshTable();
109+
refreshResults();
100110
}, 10000);
101111
</script>
102112
</body>

watchdog/watchdog.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func Monitor(cfg *config.Config) {
2727
metric.PublishMetricsForService(service, result)
2828
rwLock.Lock()
2929
serviceResults[service.Name] = append(serviceResults[service.Name], result)
30-
if len(serviceResults[service.Name]) > 10 {
30+
if len(serviceResults[service.Name]) > 20 {
3131
serviceResults[service.Name] = serviceResults[service.Name][1:]
3232
}
3333
rwLock.Unlock()

0 commit comments

Comments
 (0)