cleanup STDOUT debugging

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-13 00:40:22 -05:00
parent ba61b78631
commit 62e9d8cfb1
4 changed files with 33 additions and 27 deletions

35
http.go
View File

@ -20,18 +20,9 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
var tmp string
tmp = cleanURL(r.URL.Path)
log.Info("Handling URL:", tmp)
if tmp == "/" {
fmt.Fprintln(w, "OK")
return
}
if tmp == "/me" {
fmt.Fprintln(w, "OK")
return
}
// list all the droplets
if tmp == "/droplets" {
log.Info("Handling URL:", tmp)
for _, d := range me.droplets {
dur := time.Since(d.lastpoll) // Calculate the elapsed time
fmt.Fprintln(w, d.Hostname, d.hname, shell.FormatDuration(dur))
@ -56,9 +47,9 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
}
}
if good {
fmt.Fprintln(w, "GOOD=true")
fmt.Fprintln(w, "Handling URL:", tmp, "GOOD=true")
} else {
fmt.Fprintln(w, "GOOD=false")
fmt.Fprintln(w, "Handling URL:", tmp, "GOOD=false")
}
return
}
@ -69,18 +60,28 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
}
if tmp == "/uptime" {
if clusterHealthy() {
log.Info("Handling URL:", tmp, "1 GOOD=true")
fmt.Fprintln(w, "GOOD=true")
} else {
log.Info("Handling URL:", tmp, "1 GOOD=false")
fmt.Fprintln(w, "GOOD=false")
}
for _, h := range me.hypers {
dur := time.Since(h.lastpoll) // Calculate the elapsed time
if dur > 2 * time.Minute {
url := "http://" + h.Hostname + ":2520/kill"
log.Info("KILL DAEMON ON", h.Hostname, shell.FormatDuration(dur), "curl", url)
}
// l := shell.FormatDuration(dur)
// log.Warn("HOST =", h.Hostname, "Last poll =", l)
//if d.State != "ON" {
// continue
//}
// dur := time.Since(d.lastpoll) // Calculate the elapsed time
}
return
}
// used for uptime monitor checking (like Kuma)
if tmp == "/uptime" {
writeFile(w, "uptime.html")
return
}
log.Warn("BAD URL =", tmp)
fmt.Fprintln(w, "BAD ZOOT")
// badurl(w, r.URL.String())

View File

@ -35,10 +35,11 @@ func main() {
me.names = append(me.names, s)
log.Info("Making a hypervisor struct for", s)
var h HyperT
h := new(HyperT)
h.Hostname = s
h.Autoscan = true
h.Delay = 5 * time.Second
h.lastpoll = time.Now()
h.Scan = func() {
h.pollHypervisor()
}

19
poll.go
View File

@ -8,7 +8,7 @@ import (
"go.wit.com/log"
)
func (h HyperT) pollHypervisor() {
func (h *HyperT) pollHypervisor() {
url := "http://" + h.Hostname + ":2520/vms"
log.Log(POLL, "wget url =", url)
s := shell.Wget(url)
@ -55,7 +55,7 @@ func (h HyperT) pollHypervisor() {
log.Log(EVENT, name, "IS NEW. ADDED ON", h.Hostname)
}
}
// log.Info("i, s =", hostname, i, s)
h.lastpoll = time.Now()
}
func findDroplet(name string) *DropletT {
@ -74,6 +74,10 @@ func clusterHealthy() bool {
continue
}
dur := time.Since(d.lastpoll) // Calculate the elapsed time
if d.CurrentState == "" {
// log.Info("SKIP. hostname has not been polled yet", d.Hostname, d.hname)
continue
}
if d.CurrentState != "ON" {
log.Info("BAD STATE", d.State, d.Hostname, d.hname, "CurrentState =", d.CurrentState, shell.FormatDuration(dur))
good = false
@ -84,13 +88,12 @@ func clusterHealthy() bool {
good = false
d.CurrentState = "MISSING"
}
log.Info("GOOD STATE ON", d.Hostname, d.hname, shell.FormatDuration(dur))
l := shell.FormatDuration(dur)
if l == "" {
log.Info("DUR IS EMPTY", dur)
}
// log.Info("GOOD STATE ON", d.Hostname, d.hname, "dur =", l)
}
}
if good {
log.Info("GOOD=true")
} else {
log.Info("GOOD=false")
}
return good
}

View File

@ -17,7 +17,7 @@ func (b *virtigoT) Enable() {
// this app's variables
type virtigoT struct {
names []string
hypers []HyperT
hypers []*HyperT
droplets []*DropletT
}
@ -28,6 +28,7 @@ type HyperT struct {
Autoscan bool // to scan or not to scan
Delay time.Duration // how often to poll the hypervisor
Dog *time.Ticker // the watchdog timer itself
lastpoll time.Time // the last time the hypervisor polled
}
// the stuff that is needed for a hypervisor