make STDOUT output easier to read

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-17 15:54:39 -05:00
parent c3a69690ee
commit f5fb6736f6
5 changed files with 19 additions and 15 deletions

View File

@ -33,15 +33,15 @@ func readDropletFile(filename string) {
d = new(DropletT) d = new(DropletT)
d.Hostname = name d.Hostname = name
if len(fields) > 1 && fields[1] != "ON" { if len(fields) > 1 && fields[1] != "ON" {
d.State = "OFF" d.ConfigState = "OFF"
} else { } else {
d.State = "ON" d.ConfigState = "ON"
} }
if len(fields) >= 3 { if len(fields) >= 3 {
d.hyperPreferred = fields[2] d.hyperPreferred = fields[2]
} }
me.droplets = append(me.droplets, d) me.droplets = append(me.droplets, d)
log.Log(EVENT, "NEW CONFIG DROPLET", d.Hostname, d.State, d.hyperPreferred) log.Log(EVENT, "config new droplet", d.Hostname, d.ConfigState, d.hyperPreferred)
} else { } else {
log.Info("not sure what to do here. duplicate droplet", name, "in config file") log.Info("not sure what to do here. duplicate droplet", name, "in config file")
} }
@ -83,7 +83,7 @@ func addHypervisor(name string) *HyperT {
log.Info("not sure what to do here. duplicate hypervisor", name, "in config file") log.Info("not sure what to do here. duplicate hypervisor", name, "in config file")
return h return h
} }
log.Log(EVENT, "Adding new hypervisor", name) log.Log(EVENT, "config new hypervisor", name)
h = new(HyperT) h = new(HyperT)
h.Hostname = name h.Hostname = name
h.Autoscan = true h.Autoscan = true

View File

@ -23,12 +23,12 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
// is the cluster running what it should? // is the cluster running what it should?
if tmp == "/droplets" { if tmp == "/droplets" {
for _, d := range me.droplets { for _, d := range me.droplets {
if d.State != "ON" { if d.ConfigState != "ON" {
continue continue
} }
dur := time.Since(d.lastpoll) // Calculate the elapsed time dur := time.Since(d.lastpoll) // Calculate the elapsed time
if d.CurrentState != "ON" { if d.CurrentState != "ON" {
fmt.Fprintln(w, "BAD STATE ", d.Hostname, d.hname, "(", d.State, "vs", d.CurrentState, ")", shell.FormatDuration(dur)) fmt.Fprintln(w, "BAD STATE ", d.Hostname, d.hname, "(", d.ConfigState, "vs", d.CurrentState, ")", shell.FormatDuration(dur))
} else { } else {
dur := time.Since(d.lastpoll) // Calculate the elapsed time dur := time.Since(d.lastpoll) // Calculate the elapsed time
fmt.Fprintln(w, "GOOD STATE ON", d.Hostname, d.hname, shell.FormatDuration(dur)) fmt.Fprintln(w, "GOOD STATE ON", d.Hostname, d.hname, shell.FormatDuration(dur))
@ -65,7 +65,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
} }
// l := shell.FormatDuration(dur) // l := shell.FormatDuration(dur)
// log.Warn("HOST =", h.Hostname, "Last poll =", l) // log.Warn("HOST =", h.Hostname, "Last poll =", l)
//if d.State != "ON" { //if d.ConfigState != "ON" {
// continue // continue
//} //}
// dur := time.Since(d.lastpoll) // Calculate the elapsed time // dur := time.Since(d.lastpoll) // Calculate the elapsed time

11
main.go
View File

@ -34,9 +34,14 @@ func main() {
// initialize the grid as unstable // initialize the grid as unstable
me.unstable = time.Now() me.unstable = time.Now()
log.Info("create cluser for", argv.Hosts) log.Info("command line hypervisors:", argv.Hosts)
for _, name := range argv.Hosts { for _, name := range argv.Hosts {
h := addHypervisor(name) h := findHypervisor(name)
if h != nil {
log.Info("command line hypervisor", name, "already in config file")
continue
}
h = addHypervisor(name)
h.Active = true h.Active = true
} }
@ -52,7 +57,7 @@ func main() {
// start the watchdog polling for each hypervisor // start the watchdog polling for each hypervisor
for _, h := range me.hypers { for _, h := range me.hypers {
log.Info("starting watchdog here for hostname =", h.Hostname) log.Info("starting polling on", h.Hostname)
go h.NewWatchdog() go h.NewWatchdog()
} }

View File

@ -64,8 +64,7 @@ func (h *HyperT) pollHypervisor() {
continue continue
} }
log.Log(EVENT, "new droplet", d.Hostname, "was not in the config file") log.Log(EVENT, "new droplet", d.Hostname, "on", h.Hostname, "(in config file without preferred hypervisor)")
log.Log(EVENT, "new droplet", d.Hostname, "moved", d.hname, h.Hostname, "config file hypervisor =", d.hname)
} }
d.hname = h.Hostname d.hname = h.Hostname
} }
@ -106,7 +105,7 @@ func clusterHealthy() (bool, string) {
for _, d := range me.droplets { for _, d := range me.droplets {
total += 1 total += 1
if d.State != "ON" { if d.ConfigState != "ON" {
continue continue
} }
dur := time.Since(d.lastpoll) // Calculate the elapsed time dur := time.Since(d.lastpoll) // Calculate the elapsed time
@ -117,7 +116,7 @@ func clusterHealthy() (bool, string) {
continue continue
} }
if d.CurrentState != "ON" { if d.CurrentState != "ON" {
log.Info("BAD STATE", d.State, d.Hostname, d.hname, "CurrentState =", d.CurrentState, shell.FormatDuration(dur)) log.Info("BAD STATE", d.ConfigState, d.Hostname, d.hname, "CurrentState =", d.CurrentState, shell.FormatDuration(dur))
good = false good = false
failed += 1 failed += 1
} else { } else {

View File

@ -38,7 +38,7 @@ type HyperT struct {
// the stuff that is needed for a hypervisor // the stuff that is needed for a hypervisor
type DropletT struct { type DropletT struct {
Hostname string // the name of the virtual machine. should be unique (probably enforce this forever) Hostname string // the name of the virtual machine. should be unique (probably enforce this forever)
State string // what the state of the droplet is SUPPOSED TO BE ConfigState string // what the state of the droplet is SUPPOSED TO BE
CurrentState string // what the state of the droplet is ACTUALLY IS CurrentState string // what the state of the droplet is ACTUALLY IS
hyperPreferred string // the hypervisor to prefer to run the droplet on hyperPreferred string // the hypervisor to prefer to run the droplet on
hname string // the hypervisor it's currently running on hname string // the hypervisor it's currently running on