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:
|
||||
GO111MODULE=off go build -v -x -ldflags "-X main.VERSION=${VERSION} -X gui.GUIVERSION=${VERSION}"
|
||||
#./zood
|
||||
./zood
|
||||
./zood --version
|
||||
|
||||
# this is for release builds using the go.mod files
|
||||
|
|
17
main.go
17
main.go
|
@ -18,6 +18,7 @@ import (
|
|||
"embed"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"go.wit.com/dev/alexflint/arg"
|
||||
"go.wit.com/log"
|
||||
|
@ -37,6 +38,13 @@ func main() {
|
|||
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()
|
||||
if err != nil {
|
||||
fmt.Println("Error:", err)
|
||||
|
@ -47,14 +55,7 @@ func main() {
|
|||
for pkg, version := range installedPackages {
|
||||
fmt.Printf("%s: %s\n", pkg, version)
|
||||
}
|
||||
os.Exit(0)
|
||||
|
||||
me = new(stuff)
|
||||
me.Hostname, _ = os.Hostname()
|
||||
|
||||
log.DaemonMode(true)
|
||||
|
||||
// reportOS()
|
||||
go NewWatchdog()
|
||||
|
||||
startHTTP()
|
||||
}
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
package main
|
||||
|
||||
import "time"
|
||||
|
||||
var me *stuff
|
||||
|
||||
// this app's variables
|
||||
type stuff struct {
|
||||
Hostname string
|
||||
dirs []string
|
||||
Hostname string // my hostname to send to zookeeper
|
||||
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