polling duration times work
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
a6b385e216
commit
487c6fd11c
17
argv.go
17
argv.go
|
@ -1,5 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "go.wit.com/log"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
this parses the command line arguements
|
this parses the command line arguements
|
||||||
|
|
||||||
|
@ -25,3 +27,18 @@ go install go.wit.com/apps/virtigo@latest
|
||||||
func (args) Version() string {
|
func (args) Version() string {
|
||||||
return "virtigo " + Version
|
return "virtigo " + Version
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var INFO *log.LogFlag
|
||||||
|
var POLL *log.LogFlag
|
||||||
|
var WARN *log.LogFlag
|
||||||
|
var EVENT *log.LogFlag
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
full := "go.wit.com/apps/virtigo"
|
||||||
|
short := "virtigo"
|
||||||
|
|
||||||
|
INFO = log.NewFlag("INFO", false, full, short, "general virtigo")
|
||||||
|
POLL = log.NewFlag("POLL", false, full, short, "virtigo polling")
|
||||||
|
WARN = log.NewFlag("WARN", true, full, short, "bad things")
|
||||||
|
EVENT = log.NewFlag("EVENT", true, full, short, "hypeprvisor/droplet events")
|
||||||
|
}
|
||||||
|
|
7
http.go
7
http.go
|
@ -4,8 +4,10 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
|
"go.wit.com/lib/gui/shell"
|
||||||
)
|
)
|
||||||
|
|
||||||
// remove '?' part and trailing '/'
|
// remove '?' part and trailing '/'
|
||||||
|
@ -18,7 +20,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
var tmp string
|
var tmp string
|
||||||
tmp = cleanURL(r.URL.Path)
|
tmp = cleanURL(r.URL.Path)
|
||||||
|
|
||||||
log.Info("Got URL:", tmp)
|
log.Info("Handling URL:", tmp)
|
||||||
if tmp == "/" {
|
if tmp == "/" {
|
||||||
fmt.Fprintln(w, "OK")
|
fmt.Fprintln(w, "OK")
|
||||||
return
|
return
|
||||||
|
@ -30,7 +32,8 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if tmp == "/vms" {
|
if tmp == "/vms" {
|
||||||
for _, d := range me.droplets {
|
for _, d := range me.droplets {
|
||||||
fmt.Fprintln(w, d.Hostname, d.hname, d.lastpoll)
|
dur := time.Since(d.lastpoll) // Calculate the elapsed time
|
||||||
|
fmt.Fprintln(w, d.Hostname, d.hname, shell.FormatDuration(dur))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
10
main.go
10
main.go
|
@ -24,26 +24,24 @@ func main() {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("connect to cluser here", argv.Hosts)
|
log.Info("create cluser for", argv.Hosts)
|
||||||
for _, s := range argv.Hosts {
|
for _, s := range argv.Hosts {
|
||||||
me.names = append(me.names, s)
|
me.names = append(me.names, s)
|
||||||
|
|
||||||
log.Info("Make a hypervisor struct for", s)
|
log.Info("Making a hypervisor struct for", s)
|
||||||
var h HyperT
|
var h HyperT
|
||||||
h.Hostname = s
|
h.Hostname = s
|
||||||
h.Autoscan = true
|
h.Autoscan = true
|
||||||
h.Delay = 5 * time.Second
|
h.Delay = 5 * time.Second
|
||||||
h.Scan = func() {
|
h.Scan = func() {
|
||||||
log.Info("scanned farm03?")
|
|
||||||
h.pollHypervisor()
|
h.pollHypervisor()
|
||||||
}
|
}
|
||||||
me.hypers = append(me.hypers, h)
|
me.hypers = append(me.hypers, h)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("me.names =", me.names)
|
// start the watchdog polling for each hypervisor
|
||||||
for _, h := range me.hypers {
|
for _, h := range me.hypers {
|
||||||
log.Info("me hostname =", h.Hostname)
|
log.Info("starting watchdog here for hostname =", h.Hostname)
|
||||||
log.Info("should start watchdog here for hostname =", h.Hostname)
|
|
||||||
go h.NewWatchdog()
|
go h.NewWatchdog()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
14
poll.go
14
poll.go
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
func (h HyperT) pollHypervisor() {
|
func (h HyperT) pollHypervisor() {
|
||||||
url := "http://" + h.Hostname + ":2520/vms"
|
url := "http://" + h.Hostname + ":2520/vms"
|
||||||
log.Info("wget url =", url)
|
log.Log(INFO, "wget url =", url)
|
||||||
s := shell.Wget(url)
|
s := shell.Wget(url)
|
||||||
if s == nil {
|
if s == nil {
|
||||||
return
|
return
|
||||||
|
@ -29,15 +29,16 @@ func (h HyperT) pollHypervisor() {
|
||||||
state := fields[0]
|
state := fields[0]
|
||||||
name := fields[1]
|
name := fields[1]
|
||||||
if state == "ON" {
|
if state == "ON" {
|
||||||
log.Info("POLL", h.Hostname, "STATE:", state, "HOST:", name, "rest:", fields[2:])
|
log.Log(POLL, h.Hostname, "STATE:", state, "HOST:", name, "rest:", fields[2:])
|
||||||
var found = false
|
var found = false
|
||||||
for _, d := range me.droplets {
|
for _, d := range me.droplets {
|
||||||
if d.Hostname == name {
|
if d.Hostname == name {
|
||||||
log.Info("ALREADY RECORDED", d.Hostname)
|
log.Log(INFO, "ALREADY RECORDED", d.Hostname)
|
||||||
found = true
|
found = true
|
||||||
d.lastpoll = time.Now()
|
d.lastpoll = time.Now()
|
||||||
|
// log.Info("ALREADY RECORDED", d.Hostname, d.lastpoll)
|
||||||
if d.hname != h.Hostname {
|
if d.hname != h.Hostname {
|
||||||
log.Info("DROPLET", d.Hostname, "MOVED FROM", d.hname, "TO", d.Hostname)
|
log.Log(EVENT, "DROPLET", d.Hostname, "MOVED FROM", d.hname, "TO", d.Hostname)
|
||||||
}
|
}
|
||||||
|
|
||||||
d.hname = h.Hostname
|
d.hname = h.Hostname
|
||||||
|
@ -46,11 +47,12 @@ func (h HyperT) pollHypervisor() {
|
||||||
if found {
|
if found {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var d DropletT
|
var d = new(DropletT)
|
||||||
d.Hostname = name
|
d.Hostname = name
|
||||||
d.hname = h.Hostname
|
d.hname = h.Hostname
|
||||||
|
d.lastpoll = time.Now()
|
||||||
me.droplets = append(me.droplets, d)
|
me.droplets = append(me.droplets, d)
|
||||||
log.Info(name, "IS NEW. ADDED ON", h.Hostname)
|
log.Log(EVENT, name, "IS NEW. ADDED ON", h.Hostname)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// log.Info("i, s =", hostname, i, s)
|
// log.Info("i, s =", hostname, i, s)
|
||||||
|
|
|
@ -18,7 +18,7 @@ func (b *virtigoT) Enable() {
|
||||||
type virtigoT struct {
|
type virtigoT struct {
|
||||||
names []string
|
names []string
|
||||||
hypers []HyperT
|
hypers []HyperT
|
||||||
droplets []DropletT
|
droplets []*DropletT
|
||||||
}
|
}
|
||||||
|
|
||||||
// the stuff that is needed for a hypervisor
|
// the stuff that is needed for a hypervisor
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
func (h *HyperT) NewWatchdog() {
|
func (h *HyperT) NewWatchdog() {
|
||||||
var delay int = 99
|
var delay int = 99
|
||||||
var i int = delay
|
var i int = delay
|
||||||
h.MyTicker(h.Delay, "new Watchdog() "+h.Hostname, func() {
|
h.MyTicker(h.Delay, h.Hostname, func() {
|
||||||
i += 1
|
i += 1
|
||||||
// check if the env var is set to autoscan
|
// check if the env var is set to autoscan
|
||||||
if os.Getenv("WATCHDOG_AUTO_SCAN") != "true" {
|
if os.Getenv("WATCHDOG_AUTO_SCAN") != "true" {
|
||||||
|
@ -56,7 +56,7 @@ func (h *HyperT) MyTicker(t time.Duration, name string, f func()) {
|
||||||
fmt.Println("Done!")
|
fmt.Println("Done!")
|
||||||
return
|
return
|
||||||
case t := <-h.Dog.C:
|
case t := <-h.Dog.C:
|
||||||
log.Info(name, "Current time: ", t)
|
log.Log(POLL, "Watchdog() ticked", name, "Current time: ", t)
|
||||||
h.Scan()
|
h.Scan()
|
||||||
// f()
|
// f()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue