diff options
Diffstat (limited to 'poll.go')
| -rw-r--r-- | poll.go | 76 |
1 files changed, 41 insertions, 35 deletions
@@ -8,6 +8,7 @@ import ( "go.wit.com/lib/gui/shell" pb "go.wit.com/lib/protobuf/virtbuf" "go.wit.com/log" + "google.golang.org/protobuf/types/known/timestamppb" ) func (h *HyperT) pollHypervisor() { @@ -34,43 +35,40 @@ func (h *HyperT) pollHypervisor() { log.Log(POLL, h.pb.Hostname, "STATE:", state, "HOST:", name, "rest:", fields[2:]) d := findDroplet(name) if d == nil { - // this is a new unknown droplet (not in the config file) - d = new(DropletT) - d.pb.Hostname = name - d.h = h - d.lastpoll = time.Now() - d.CurrentState = pb.DropletState_ON - me.droplets = append(me.droplets, d) - log.Log(EVENT, name, "IS NEW. ADDED ON", h.pb.Hostname) + // not sure whawt now? } - log.Log(INFO, "ALREADY RECORDED", d.pb.Hostname) + log.Log(INFO, "ALREADY RECORDED", d.Hostname) // update the status to ON and the last polled value d.CurrentState = pb.DropletState_ON - d.lastpoll = time.Now() - if d.h == nil { + now := time.Now() + d.LastPoll = timestamppb.New(now) + + var cur *HyperT + // cur := find(d.CurrentHypervisor) + if cur == nil { // this means the droplet was in the config file // but this is the first time it's shown up as running // this should mean a droplet is running where the config file says it probably should be running - if d.pb.PreferredHypervisor == h.pb.Hostname { - log.Log(EVENT, "new droplet", d.pb.Hostname, "(matches config hypervisor", h.pb.Hostname+")") - d.h = h + if d.PreferredHypervisor == h.pb.Hostname { + log.Log(EVENT, "new droplet", d.Hostname, "(matches config hypervisor", h.pb.Hostname+")") + cur = h continue } - log.Log(EVENT, "new droplet", d.pb.Hostname, "on", h.pb.Hostname, "(in config file without preferred hypervisor)") - d.h = h + log.Log(EVENT, "new droplet", d.Hostname, "on", h.pb.Hostname, "(in config file without preferred hypervisor)") + cur = h continue } // this means the droplet is still where it was before - if d.h.pb.Hostname != h.pb.Hostname { - log.Log(EVENT, "droplet", d.h.pb.Hostname, "moved to", h.pb.Hostname) + if cur.pb.Hostname != h.pb.Hostname { + log.Log(EVENT, "droplet", d.Hostname, "moved to", h.pb.Hostname) continue } - d.h = h + cur = h } continue } @@ -78,16 +76,23 @@ func (h *HyperT) pollHypervisor() { h.killcount = 0 // poll worked. reset killcount } -func findDroplet(name string) *DropletT { - for _, d := range me.droplets { - if d.pb.Hostname == name { - return d +func findDroplet(name string) *pb.Droplet { + /* + for _, d := range me.droplets { + if d.Hostname == name { + return d + } } - } + */ return nil } +/* func findHypervisor(name string) *HyperT { + if h, ok := me.hmap[name]; ok { + return h + } + return nil for _, h := range me.hypers { if h.pb.Hostname == name { return h @@ -95,6 +100,7 @@ func findHypervisor(name string) *HyperT { } return nil } +*/ // check the state of the cluster and return a string // that is intended to be sent to an uptime monitor like Kuma @@ -107,30 +113,30 @@ func clusterHealthy() (bool, string) { var unknown int var unknownList []string - for _, d := range me.droplets { + for _, d := range me.cluster.Droplets { total += 1 - if d.pb.StartState != pb.DropletState_ON { + if d.StartState != pb.DropletState_ON { continue } - dur := time.Since(d.lastpoll) // Calculate the elapsed time + dur := time.Since(d.LastPoll.AsTime()) // Calculate the elapsed time if d.CurrentState == pb.DropletState_UNKNOWN { - // log.Info("SKIP. hostname has not been polled yet", d.pb.Hostname, d.hname) + // log.Info("SKIP. hostname has not been polled yet", d.Hostname, d.hname) unknown += 1 - unknownList = append(unknownList, d.pb.Hostname) + unknownList = append(unknownList, d.Hostname) continue } var hname string - if d.h != nil { - hname = d.h.pb.Hostname + if d.CurrentHypervisor != "" { + hname = d.CurrentHypervisor } if d.CurrentState != pb.DropletState_ON { - log.Info("BAD STATE", d.pb.StartState, d.pb.Hostname, hname, "CurrentState =", d.CurrentState, shell.FormatDuration(dur)) + log.Info("BAD STATE", d.StartState, d.Hostname, hname, "CurrentState =", d.CurrentState, shell.FormatDuration(dur)) good = false failed += 1 } else { - dur := time.Since(d.lastpoll) // Calculate the elapsed time + dur := time.Since(d.LastPoll.AsTime()) // Calculate the elapsed time if dur > time.Minute { - log.Info("GOOD STATE MISSING", d.pb.Hostname, hname, shell.FormatDuration(dur)) + log.Info("GOOD STATE MISSING", d.Hostname, hname, shell.FormatDuration(dur)) good = false d.CurrentState = pb.DropletState_UNKNOWN failed += 1 @@ -143,7 +149,7 @@ func clusterHealthy() (bool, string) { continue } working += 1 - // log.Info("GOOD STATE ON", d.pb.Hostname, d.hname, "dur =", l) + // log.Info("GOOD STATE ON", d.Hostname, d.hname, "dur =", l) } } var summary string = "(" |
