start a tally of working, totals, not working, etc
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
7a4bc0b5d6
commit
eddd658b7f
11
http.go
11
http.go
|
@ -59,12 +59,13 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if tmp == "/uptime" {
|
if tmp == "/uptime" {
|
||||||
if clusterHealthy() {
|
b, s := clusterHealthy()
|
||||||
log.Info("Handling URL:", tmp, "1 GOOD=true")
|
if b {
|
||||||
fmt.Fprintln(w, "GOOD=true")
|
log.Info("Handling URL:", tmp, "cluster is ok", s)
|
||||||
|
fmt.Fprintln(w, s)
|
||||||
} else {
|
} else {
|
||||||
log.Info("Handling URL:", tmp, "1 GOOD=false")
|
log.Info("Handling URL:", tmp, "cluster is not right yet", s)
|
||||||
fmt.Fprintln(w, "GOOD=false")
|
fmt.Fprintln(w, s)
|
||||||
}
|
}
|
||||||
for _, h := range me.hypers {
|
for _, h := range me.hypers {
|
||||||
url := "http://" + h.Hostname + ":2520/kill"
|
url := "http://" + h.Hostname + ":2520/kill"
|
||||||
|
|
26
poll.go
26
poll.go
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -68,8 +69,12 @@ func findDroplet(name string) *DropletT {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func clusterHealthy() bool {
|
// check the state of the cluster and return a string
|
||||||
var good = true
|
// that is intended to be sent to an uptime monitor like Kuma
|
||||||
|
func clusterHealthy() (bool, string) {
|
||||||
|
var good bool = true
|
||||||
|
var working int
|
||||||
|
var failed int
|
||||||
for _, d := range me.droplets {
|
for _, d := range me.droplets {
|
||||||
if d.State != "ON" {
|
if d.State != "ON" {
|
||||||
continue
|
continue
|
||||||
|
@ -88,13 +93,28 @@ func clusterHealthy() bool {
|
||||||
log.Info("GOOD STATE MISSING", d.Hostname, d.hname, shell.FormatDuration(dur))
|
log.Info("GOOD STATE MISSING", d.Hostname, d.hname, shell.FormatDuration(dur))
|
||||||
good = false
|
good = false
|
||||||
d.CurrentState = "MISSING"
|
d.CurrentState = "MISSING"
|
||||||
|
failed += 1
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
l := shell.FormatDuration(dur)
|
l := shell.FormatDuration(dur)
|
||||||
if l == "" {
|
if l == "" {
|
||||||
log.Info("DUR IS EMPTY", dur)
|
log.Info("DUR IS EMPTY", dur)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
working += 1
|
||||||
// log.Info("GOOD STATE ON", d.Hostname, d.hname, "dur =", l)
|
// log.Info("GOOD STATE ON", d.Hostname, d.hname, "dur =", l)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return good
|
var summary string = "("
|
||||||
|
if working > 0 {
|
||||||
|
summary += fmt.Sprintf("working = %d", working)
|
||||||
|
}
|
||||||
|
if failed > 0 {
|
||||||
|
summary += fmt.Sprintf("failed = %d", failed)
|
||||||
|
}
|
||||||
|
summary += ")"
|
||||||
|
if good {
|
||||||
|
return good, "GOOD=true " + summary
|
||||||
|
}
|
||||||
|
return good, "GOOD=false " + summary
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue