clean up logging of initial scan of droplets

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-17 15:29:47 -05:00
parent 25b0709668
commit c3a69690ee
4 changed files with 37 additions and 18 deletions

1
README
View File

@ -16,6 +16,7 @@ Notes & Goals:
* Be super easy to use.
* Automatically map access to serial and graphical consoles
* Only temporarily generate libvirt XML files for virsh create
* This is intended for managing Virtual Machines, not for containers
* This often uses the DO nomenclature 'droplets' instead of 'virtual machines' or 'domU'
* Every droplet is considered hostile

View File

@ -23,6 +23,9 @@ func (h *HyperT) RestartDaemon() {
dur := time.Since(h.lastpoll) // Calculate the elapsed time
log.Info("KILLED DAEMON", h.Hostname, shell.FormatDuration(dur), "curl", url)
me.killcount += 1
// mark the cluster as unstable so droplet starts can be throttled
me.unstable = time.Now()
}
var stableTimeout time.Duration = 43 * time.Second

View File

@ -28,7 +28,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
}
dur := time.Since(d.lastpoll) // Calculate the elapsed time
if d.CurrentState != "ON" {
fmt.Fprintln(w, "BAD STATE ", d.Hostname, "State =", d.State, "CurrentState =", d.CurrentState, shell.FormatDuration(dur))
fmt.Fprintln(w, "BAD STATE ", d.Hostname, d.hname, "(", d.State, "vs", d.CurrentState, ")", shell.FormatDuration(dur))
} else {
dur := time.Since(d.lastpoll) // Calculate the elapsed time
fmt.Fprintln(w, "GOOD STATE ON", d.Hostname, d.hname, shell.FormatDuration(dur))

43
poll.go
View File

@ -32,20 +32,7 @@ func (h *HyperT) pollHypervisor() {
if state == "ON" {
log.Log(POLL, h.Hostname, "STATE:", state, "HOST:", name, "rest:", fields[2:])
d := findDroplet(name)
if d != nil {
log.Log(INFO, "ALREADY RECORDED", d.Hostname)
d.lastpoll = time.Now()
d.CurrentState = "ON"
// log.Info("ALREADY RECORDED", d.Hostname, d.lastpoll)
if d.hname == "" {
log.Log(EVENT, "DROPLET", d.Hostname, "PROBABLY WAS NEVER POLLED YET")
}
if d.hname != h.Hostname {
log.Log(EVENT, "DROPLET", d.Hostname, "MOVED FROM", d.hname, "TO", h.Hostname)
d.hname = h.Hostname
}
continue
}
if d == nil {
// this is a new unknown droplet (not in the config file)
d = new(DropletT)
d.Hostname = name
@ -55,6 +42,34 @@ func (h *HyperT) pollHypervisor() {
me.droplets = append(me.droplets, d)
log.Log(EVENT, name, "IS NEW. ADDED ON", h.Hostname)
}
log.Log(INFO, "ALREADY RECORDED", d.Hostname)
// update the status to ON and the last polled value
d.CurrentState = "ON"
d.lastpoll = time.Now()
// this means the droplet is still where it was before
if d.hname == h.Hostname {
continue
}
if d.hname == "" {
// 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.hyperPreferred == h.Hostname {
log.Log(EVENT, "new droplet", d.Hostname, "(matches config hypervisor", h.Hostname + ")")
d.hname = h.Hostname
continue
}
log.Log(EVENT, "new droplet", d.Hostname, "was not in the config file")
log.Log(EVENT, "new droplet", d.Hostname, "moved", d.hname, h.Hostname, "config file hypervisor =", d.hname)
}
d.hname = h.Hostname
}
continue
}
h.lastpoll = time.Now()
h.killcount = 0 // poll worked. reset killcount