Developing lightweight computation at the DSG edge

Commit 0573c596 authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

[monitor-ping] Update to new CNML and actually ping addresses



The routine pings actual devices.
Signed-off-by: Roger Pueyo Centelles's avatarRoger Pueyo Centelles <rpueyo@ac.upc.edu>
parent 03417e6a
package main
import (
"encoding/json"
"flag"
"fmt"
"os"
......@@ -11,6 +12,8 @@ import (
"uc-monitor-go-test/goclidote"
"github.com/golang/glog"
ping "lightkone.guifi.net/lightkone/go-ping"
)
// Define error levels
......@@ -51,6 +54,9 @@ var localAssignCheckIntervalHelp = "Interval (in seconds) in which to check for
var pingCheckInterval = 10 //300
var pingCheckIntervalHelp = "Interval (in seconds) in which to perform the ping checks to the devices"
var pingCount = 5 //Number of pings to perform
var pingTimeout time.Duration = 5 * 1000 * 1000 * 1000 //Ping timeout in ns (5s)
// Global data structures
// localAssign contains the list of devices assigned to this monitor and their IPv4 addresses
......@@ -133,16 +139,49 @@ func performPingChecks() {
for _, v := range localAssign {
fmt.Print("Pinging device ")
fmt.Println(v.DeviceID)
fmt.Println(v.Device.ID)
for _, w := range v.Device.Addresses {
fmt.Println(w)
}
//rtts := pingAddress(v.Device.Addresses[0]).Rtts
rtts := pingAddress(v.Device.Addresses[0])
fmt.Printf("%T\n", rtts)
// fmt.Println(len(rtts))
// for l, w := range rtts {
// rtts[l] = w / 1000
// }
jrtts, err := json.Marshal(rtts)
if err != nil {
panic(err)
}
fmt.Printf("%s\n", jrtts)
}
}
func pingAddress(IPAddress string) *ping.Statistics {
fmt.Print("I was asked to ping ")
fmt.Println(IPAddress)
pinger, err := ping.NewPinger(IPAddress)
errCheck(err, WARNING, fmt.Sprintf("Unable to create a new ping instance to %s", IPAddress))
pinger.SetPrivileged(false)
pinger.Count = pingCount
pinger.Timeout = pingTimeout
pinger.Run()
return pinger.Statistics()
}
func refreshAssignationList() {
localAssign = getLocalAssignationList()
fmt.Println("Assigned devices:")
for _, v := range localAssign {
fmt.Println(v.DeviceID)
fmt.Println(v.Device.ID)
}
}
......@@ -170,7 +209,8 @@ func getGlobalAssignationList() []cnml.DeviceMonitorAssignation {
for _, v := range getCnmlDevicesList() {
{
var newDev cnml.DeviceMonitorAssignation
newDev.DeviceID = v.ID
newDev.Device.ID = v.ID
newDev.Device.Addresses = v.Addresses
newDev.MonitorID = goclidote.AntidoteReadItemsFromSetInBucket(fmt.Sprintf("device-%d", v.ID), "monitors", dbHost, dbPort)
globalAssign = append(globalAssign, newDev)
}
......
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