start a tally of working, totals, not working, etc

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-13 01:13:19 -05:00
parent 7a4bc0b5d6
commit eddd658b7f
2 changed files with 30 additions and 9 deletions

13
http.go
View File

@ -59,17 +59,18 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
return
}
if tmp == "/uptime" {
if clusterHealthy() {
log.Info("Handling URL:", tmp, "1 GOOD=true")
fmt.Fprintln(w, "GOOD=true")
b, s := clusterHealthy()
if b {
log.Info("Handling URL:", tmp, "cluster is ok", s)
fmt.Fprintln(w, s)
} else {
log.Info("Handling URL:", tmp, "1 GOOD=false")
fmt.Fprintln(w, "GOOD=false")
log.Info("Handling URL:", tmp, "cluster is not right yet", s)
fmt.Fprintln(w, s)
}
for _, h := range me.hypers {
url := "http://" + h.Hostname + ":2520/kill"
dur := time.Since(h.lastpoll) // Calculate the elapsed time
if dur > 90 * time.Second {
if dur > 90*time.Second {
log.Info("KILL DAEMON ON", h.Hostname, shell.FormatDuration(dur), "curl", url)
// s := shell.Wget(url)
// log.Info("curl got:", s)

26
poll.go
View File

@ -1,6 +1,7 @@
package main
import (
"fmt"
"strings"
"time"
@ -68,8 +69,12 @@ func findDroplet(name string) *DropletT {
return nil
}
func clusterHealthy() bool {
var good = true
// check the state of the cluster and return a string
// 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 {
if d.State != "ON" {
continue
@ -88,13 +93,28 @@ func clusterHealthy() bool {
log.Info("GOOD STATE MISSING", d.Hostname, d.hname, shell.FormatDuration(dur))
good = false
d.CurrentState = "MISSING"
failed += 1
continue
}
l := shell.FormatDuration(dur)
if l == "" {
log.Info("DUR IS EMPTY", dur)
continue
}
working += 1
// 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
}