virtigoctl/watchdog.go

39 lines
912 B
Go

package main
import (
"time"
pb "go.wit.com/lib/protobuf/virtbuf"
"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 (h *HyperT) sendDirs() {
url := "http://" + h.pb.Hostname + ":2520/cluster"
var msg string
var data []byte
var c *pb.Cluster
c = new(pb.Cluster)
for _, dir := range me.cluster.Dirs {
c.Dirs = append(c.Dirs, dir)
}
msg = c.FormatJSON()
data = []byte(msg) // Convert the string to []byte
req, err := httpPost(url, data)
if err != nil {
log.Info("error:", err)
return
}
// log.Info("http post url:", url)
// log.Info("http post data:", msg)
log.Info("EVENT start droplet response: " + string(req))
}