add watchdog
This commit is contained in:
parent
6c920e0925
commit
7b06923395
2
Makefile
2
Makefile
|
@ -6,7 +6,7 @@ REDOMOD = $(shell if [ -e go.sum ]; then echo go.sum exists; else GO111MODULE=
|
||||||
|
|
||||||
all:
|
all:
|
||||||
GO111MODULE=off go build -v -x -ldflags "-X main.VERSION=${VERSION} -X gui.GUIVERSION=${VERSION}"
|
GO111MODULE=off go build -v -x -ldflags "-X main.VERSION=${VERSION} -X gui.GUIVERSION=${VERSION}"
|
||||||
#./zood
|
./zood
|
||||||
./zood --version
|
./zood --version
|
||||||
|
|
||||||
# this is for release builds using the go.mod files
|
# this is for release builds using the go.mod files
|
||||||
|
|
17
main.go
17
main.go
|
@ -18,6 +18,7 @@ import (
|
||||||
"embed"
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"go.wit.com/dev/alexflint/arg"
|
"go.wit.com/dev/alexflint/arg"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
|
@ -37,6 +38,13 @@ func main() {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
me = new(stuff)
|
||||||
|
me.Zookeeper = "zookeeper.wit.com"
|
||||||
|
me.Hostname, _ = os.Hostname()
|
||||||
|
me.pollDelay = 3 * time.Second
|
||||||
|
|
||||||
|
log.DaemonMode(true)
|
||||||
|
|
||||||
installedPackages, err := getInstalledPackages()
|
installedPackages, err := getInstalledPackages()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error:", err)
|
fmt.Println("Error:", err)
|
||||||
|
@ -47,14 +55,7 @@ func main() {
|
||||||
for pkg, version := range installedPackages {
|
for pkg, version := range installedPackages {
|
||||||
fmt.Printf("%s: %s\n", pkg, version)
|
fmt.Printf("%s: %s\n", pkg, version)
|
||||||
}
|
}
|
||||||
os.Exit(0)
|
go NewWatchdog()
|
||||||
|
|
||||||
me = new(stuff)
|
|
||||||
me.Hostname, _ = os.Hostname()
|
|
||||||
|
|
||||||
log.DaemonMode(true)
|
|
||||||
|
|
||||||
// reportOS()
|
|
||||||
|
|
||||||
startHTTP()
|
startHTTP()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
var me *stuff
|
var me *stuff
|
||||||
|
|
||||||
// this app's variables
|
// this app's variables
|
||||||
type stuff struct {
|
type stuff struct {
|
||||||
Hostname string
|
Hostname string // my hostname to send to zookeeper
|
||||||
dirs []string
|
Zookeeper string // the dns name for the zookeeper
|
||||||
|
pollDelay time.Duration // how often to report our status
|
||||||
|
dog *time.Ticker // the watchdog timer
|
||||||
|
dirs []string
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"go.wit.com/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// timeFunction takes a function as an argument and returns the execution time.
|
||||||
|
func TimeFunction(f func()) time.Duration {
|
||||||
|
startTime := time.Now() // Record the start time
|
||||||
|
f() // Execute the function
|
||||||
|
return time.Since(startTime) // Calculate the elapsed time
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewWatchdog() {
|
||||||
|
me.dog = time.NewTicker(me.pollDelay)
|
||||||
|
defer me.dog.Stop()
|
||||||
|
done := make(chan bool)
|
||||||
|
/*
|
||||||
|
// this example would exit/destroy the ticker in 10 seconds
|
||||||
|
go func() {
|
||||||
|
time.Sleep(10 * time.Second)
|
||||||
|
done <- true
|
||||||
|
}()
|
||||||
|
*/
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-done:
|
||||||
|
fmt.Println("Done!")
|
||||||
|
return
|
||||||
|
case t := <-me.dog.C:
|
||||||
|
log.Info("Watchdog() ticked", me.Zookeeper, "Current time: ", t)
|
||||||
|
// h.pollHypervisor()
|
||||||
|
// h.Scan()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue