# uc-monitor-go-test [](https://goreportcard.com/report/lightkone.guifi.net/lightkone/uc-monitor-go-test)
A proof-of-concept application that leverages [AntidoteDB](https://syncfree.github.io/antidote/) to orchestrate the Guifi.net network nodes monitoring system for the [LightKone](https://www.lightkone.eu/) project.
## Description
The monitoring application is distributed in three main blocks:
- Network description fetching and feeding (functional)
- Nodes assignment among the different monitoring servers (functional, WiP)
- Actual nodes monitorisation (functional, WiP)
This proof of concept takes advantage of the [AntidoteDB Java tutorial](https://github.com/SyncFree/antidote-java-tutorial) by [Deepthi Akkoorath (@deepthidevaki)](https://github.com/deepthidevaki) and uses [Mathias Weber (@mweberUKL)](https://github.com/mweberUKL)'s Go client for AntidoteDB (previously, [João Neto (@joaomlneto)](https://github.com/joaomlneto)'s [HTTP/HTTPS REST API for AntidoteDB](https://github.com/LightKone/antidote-rest-server) was used).
## Installation
### Docker
Install `docker-ce` using your preferred method as [described here](https://docs.docker.com/install/).
### Go and required libraries
Install Go using your operating system's package manager or follow the [instructions here](https://golang.org/doc/install).
After installing Go, download and install the folowing external libraries needed:
- golang/glog:
`go get github.com/golang/glog`
- sparrc/go-ping:
`go get github.com/sparrc/go-ping`
- antidote-go-client:
`go get github.com/AntidoteDB/antidote-go-client`
### AntidoteDB Java tutorial
Get the tutorial's source code [here](https://github.com/SyncFree/antidote-java-tutorial) to download the code and [start the two AntidoteDB nodes](https://github.com/SyncFree/antidote-java-tutorial#starting-antidote-nodes).
### HTTP/HTTPS REST API
The AntidoteDB REST API server is no longer needed, but you can follow the [instructions here](https://github.com/LightKone/antidote-rest-server) to install it, as it comes handy to perform quick tests.
## Running the application
### Fetch the network description and feed it to AntidoteDB
The Guifi-UPC network (a small fraction of the whole Guifi.net) description file is included in `assets/cnml/upc.xml` and is used by default. The `monitor-fetch` program fetches the data from the file and pushes it to AntidoteDB:
```bash
$ cd src/monitor/fetch/
$ go run monitor-fetch.go
19 nodes read from ../assets/cnml/upc.xml
63 devices read from ../assets/cnml/upc.xml
54 devices exported to /tmp/gmonitor2/devs.json
16 devices removed from AntidoteDB (0 success, 0 fail)
16 graphservers removed from AntidoteDB (0 success, 0 fail)
27 IPv4 addresses removed from AntidoteDB (0 success, 0 fail)
54 devices added to AntidoteDB (54 success, 0 fail)
54 graphservers added or updated to AntidoteDB (54 success, 0 fail)
67 IPv4 addresses added or updated to AntidoteDB (67 success, 0 fail)
```
Other small sub-networks' descriptions are available in the `assets/cnml` folder, some of them overlapping and some not.
Beyond the development and testing phase, the whole Guifi.net CNML description can be loaded (warning, it's HUGE):
```bash
$ go run monitor-fetch.go -cnml_file ../assets/cnml/guifi.xml
57642 nodes read from ../assets/cnml/guifi.xml
53461 devices read from ../assets/cnml/guifi.xml
39988 devices exported to /tmp/gmonitor2/devs.json
0 devices removed from AntidoteDB (0 success, 0 fail)
0 graphservers removed from AntidoteDB (0 success, 0 fail)
0 IPv4 addresses removed from AntidoteDB (0 success, 0 fail)
39988 devices added to AntidoteDB (39988 success, 0 fail)
39988 graphservers added or updated to AntidoteDB (39988 success, 0 fail)
49671 IPv4 addresses added or updated to AntidoteDB (49671 success, 0 fail)
```
### Assign network nodes to monitoring servers
Each monitoring instance consists of three pieces of code, `monitor-assign`, `monitor-ping` and `monitor-snmp`. Eventually they will be merged into a single one encompassing all the functions.
The `monitor-assign` program gets the whole Guifi.net network description from AntidoteDB, checks which devices are not being monitored (or are not being monitored with enough redundancy) and randomly picks some of them to start monitoring them.
In the future, this random picking will be replaced by a smarter algorithm.
Different options can be specified, like the monitor's `ID`, the maximum number of devices to take care of monitoring, the minimum redundancy, etc.:
`
Initializing...
Using ID 12345
Setting timestamp to 1560419260
Updating globalAssign...
Adding device 35578 from cnmlDevices into globalAssign
Adding device 35580 from cnmlDevices into globalAssign
Adding device 41236 from cnmlDevices into globalAssign
Adding device 52800 from cnmlDevices into globalAssign
Adding device 53410 from cnmlDevices into globalAssign
Adding device 55625 from cnmlDevices into globalAssign
Adding device 58266 from cnmlDevices into globalAssign
Adding device 66287 from cnmlDevices into globalAssign
Adding device 67954 from cnmlDevices into globalAssign
Adding device 69514 from cnmlDevices into globalAssign
Adding device 74780 from cnmlDevices into globalAssign
Adding device 74943 from cnmlDevices into globalAssign
Adding device 75036 from cnmlDevices into globalAssign
Adding device 75038 from cnmlDevices into globalAssign
Adding device 75651 from cnmlDevices into globalAssign
Adding device 92844 from cnmlDevices into globalAssign
globalAssign updated!
Initialization done. Entering infinite loop...
Setting timestamp to 1560419265
Managing the monitors list...
I am monitor 12345
1 monitors registered in the database:
12345
Updating globalAssign...
globalAssign updated!
Sanitizing the assignation list...
Getting the current monitors list...
Updating the current cnml...
Ended assignation list sanitization...
Reassignation of devices
0 devices currently assigned to this monitor (maximum: 5 devices)
Updating the current cnml...
Assigning 1 new devices
16 devices unassigned
Picking 1 nodes randomly
1 devices currently assigned to this monitor
Exporting the new assigned devices list
Setting timestamp to 1560419270
Managing the monitors list...
I am monitor 12345
1 monitors registered in the database:
12345
Updating globalAssign...
globalAssign updated!
Sanitizing the assignation list...
Getting the current monitors list...
Updating the current cnml...
Monitor 12345 found, keeping it for device 52800
Ended assignation list sanitization...
Reassignation of devices
1 devices currently assigned to this monitor (maximum: 5 devices)
Updating the current cnml...
Assigning 1 new devices
15 devices unassigned
Picking 1 nodes randomly
2 devices currently assigned to this monitor
Exporting the new assigned devices list
Setting timestamp to 1560419275
Managing the monitors list...
I am monitor 12345
1 monitors registered in the database:
12345
Updating globalAssign...
globalAssign updated!
Sanitizing the assignation list...
Getting the current monitors list...
Updating the current cnml...
Monitor 12345 found, keeping it for device 52800
Monitor 12345 found, keeping it for device 75651
Ended assignation list sanitization...
Reassignation of devices
2 devices currently assigned to this monitor (maximum: 5 devices)
Updating the current cnml...
Assigning 1 new devices
14 devices unassigned
Picking 1 nodes randomly
3 devices currently assigned to this monitor
Exporting the new assigned devices list
Setting timestamp to 1560419280
Managing the monitors list...
I am monitor 12345
1 monitors registered in the database:
12345
Updating globalAssign...
globalAssign updated!
Sanitizing the assignation list...
Getting the current monitors list...
Updating the current cnml...
Monitor 12345 found, keeping it for device 52800
Monitor 12345 found, keeping it for device 75036
Monitor 12345 found, keeping it for device 75651
Ended assignation list sanitization...
Reassignation of devices
3 devices currently assigned to this monitor (maximum: 5 devices)
Updating the current cnml...
Assigning 1 new devices
13 devices unassigned
Picking 1 nodes randomly
4 devices currently assigned to this monitor
Exporting the new assigned devices list
Setting timestamp to 1560419285
Managing the monitors list...
I am monitor 12345
1 monitors registered in the database:
12345
Updating globalAssign...
globalAssign updated!
Sanitizing the assignation list...
Getting the current monitors list...
Updating the current cnml...
Monitor 12345 found, keeping it for device 52800
Monitor 12345 found, keeping it for device 75036
Monitor 12345 found, keeping it for device 75038
Monitor 12345 found, keeping it for device 75651
Ended assignation list sanitization...
Reassignation of devices
4 devices currently assigned to this monitor (maximum: 5 devices)
Updating the current cnml...
Assigning 1 new devices
12 devices unassigned
Picking 1 nodes randomly
5 devices currently assigned to this monitor
Exporting the new assigned devices list
Setting timestamp to 1560419290
Managing the monitors list...
I am monitor 12345
1 monitors registered in the database:
12345
Updating globalAssign...
globalAssign updated!
Sanitizing the assignation list...
Getting the current monitors list...
Updating the current cnml...
Monitor 12345 found, keeping it for device 52800
Monitor 12345 found, keeping it for device 75036
Monitor 12345 found, keeping it for device 75038
Monitor 12345 found, keeping it for device 75651
Monitor 12345 found, keeping it for device 92844
Ended assignation list sanitization...
Reassignation of devices
5 devices currently assigned to this monitor (maximum: 5 devices)
Updating the current cnml...
Not assigning any new device
```
$ go run monitor-assign.go -id 12345 -maxDevs 5 -minMons 3 (click here to see the whole content)
`monitor-assign` not only cares about assigning itself the devices to monitor, but also pushes this information to AntidoteDB, so that other monitors can indirectly coordinate and pick the right devices to monitor.
Additionally, it periodically sanitizes the global assignation in AntidoteDB, by pruning assignations from monitors that are not in the system anymore (crashed, unresponsive, in another network partition...)
### Monitor the nodes' liveliness (ping RTT and TTL) [WiP]
The `monitor-ping` pings the different devices the monitor is assigned periodically, and writes the information to AntidoteDB.
To have enough resolution for graphing, each device must be pinged *at least* every five minutes (and, ideally, this will happen simultaneously in other monitors, achieving the required redundancy).
The `monitor-ping` instance **must** use the same `ID` parameter as the local `monitor-assign` instance (in the future they will be merged into a single process):
`
Initializing...
Using ID 12345
Initialization done. Entering infinite loop...
Pinging devices...
Pinging device 101994
10.1.27.13
I was asked to ping 10.1.27.13
false ==> offline
Pinging device 38720
10.1.26.97
I was asked to ping 10.1.26.97
true ==> online
Pinging device 42628
10.1.25.225
I was asked to ping 10.1.25.225
true ==> online
Pinging device 83865
10.1.25.130
10.228.207.130
I was asked to ping 10.1.25.130
true ==> online
Pinging device 87503
10.1.25.194
I was asked to ping 10.1.25.194
true ==> online
Pinging devices...
Pinging device 101994
10.1.27.13
I was asked to ping 10.1.27.13
false
Pinging device 38720
10.1.26.97
I was asked to ping 10.1.26.97
```
$ go run monitor-ping.go -id 12345 (click here to see the whole content)