Developing lightweight computation at the DSG edge

Commit a8c2b8c5 authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

[monitor-ping] Add timer and routine for ping checks


Signed-off-by: Roger Pueyo Centelles's avatarRoger Pueyo Centelles <rpueyo@ac.upc.edu>
parent 38da0135
......@@ -48,6 +48,9 @@ var idHelp = "Numeric ID of this monitoring instance"
var localAssignCheckInterval = 5 //60
var localAssignCheckIntervalHelp = "Interval (in seconds) in which to check for changes in the local devices assignation list"
var pingCheckInterval = 10 //300
var pingCheckIntervalHelp = "Interval (in seconds) in which to perform the ping checks to the devices"
// Global data structures
// localAssign contains the list of devices assigned to this monitor and their IPv4 addresses
......@@ -89,6 +92,8 @@ func initialize() {
func initializeTimers() {
// Initialize the local assignation check timer
startLocalAssignTimer()
// Initialize the ping checks timer
startPingCheckTimer()
}
// The initializeFlags function initializes the command line flags
......@@ -100,6 +105,7 @@ func initializeFlags() {
idInt, _ := strconv.ParseInt(ID, 10, 32)
idPtr := flag.Int("id", int(idInt), idHelp)
localAssignCheckIntervalPtr := flag.Int("localAssignCheckInterval", localAssignCheckInterval, localAssignCheckIntervalHelp)
pingCheckIntervalPtr := flag.Int("pingCheckInterval", pingCheckInterval, pingCheckIntervalHelp)
flag.Parse()
......@@ -117,13 +123,25 @@ func initializeFlags() {
if *localAssignCheckIntervalPtr > 0 {
localAssignCheckInterval = *localAssignCheckIntervalPtr
}
if *pingCheckIntervalPtr > 0 {
pingCheckInterval = *pingCheckIntervalPtr
}
}
func performPingChecks() {
fmt.Println("Pinging devices...")
for _, v := range localAssign {
fmt.Print("Pinging device ")
fmt.Println(v.DeviceID)
}
}
func refreshAssignationList() {
localAssign = getLocalAssignationList()
fmt.Println("Assigned devices:")
for _, v := range localAssign {
fmt.Print("Device ")
fmt.Println(v.DeviceID)
}
}
......@@ -169,6 +187,15 @@ func startLocalAssignTimer() {
}()
}
func startPingCheckTimer() {
pingCheckTicker := time.NewTicker(time.Duration(pingCheckInterval) * time.Second)
go func() {
for range pingCheckTicker.C {
performPingChecks()
}
}()
}
func errCheck(e error, level int, message string) {
if message == "" {
message = "Unknown error"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment