diff --git a/README.md b/README.md new file mode 100644 index 0000000..ffa7518 --- /dev/null +++ b/README.md @@ -0,0 +1,45 @@ +# README +`micro-daemon` is a respond daemon to fetch information for Freifunk Nodes +and represent this information with Websocket- and JSON-APIs. + +## Issues/Features in the Future +It will also APIs for manipulate the fetched data + and give a access for ansible to push changes to the nodes. + +Also it's will push statistic informations to a influxdb. + +## Usage +``` +Usage of ./micro-daemon: + -aliases string + path aliases.json file (default "webroot/aliases.json") + -collectInterval int + interval for data collections (default 15) + -h string + path aliases.json file + -output string + path nodes.json file (default "webroot/nodes.json") + -p string + path aliases.json file (default "8080") + -saveInterval int + interval for data saving (default 60) +``` +## Development +### respond +It send the `gluon-neighbour-info` request and collect them together. + +It will send UDP packetes by the multicast group `ff02:0:0:0:0:0:2:1001` and port `1001`. + +### modes.Nodes +It cached the Informations of the Nodes and will save them periodical to a JSON file. +The current nodes are saved default under `nodes.json`. + + +### websocketserver +One Instance is running under `/nodes` which send updates or new Nodes, + which are collected by respond. + +### Issues +Later there should be also `/aliases` Websocket with Authentification to manage the `aliases.json` with the request for changes. + +A Implementation of the connection to influxdb are also needed, maybe log a little bit to `telegraf` from influxdb. diff --git a/main.go b/main.go index 83afc79..3bc50c6 100644 --- a/main.go +++ b/main.go @@ -14,13 +14,13 @@ import ( "time" "github.com/monitormap/micro-daemon/models" - "github.com/monitormap/micro-daemon/responed" + "github.com/monitormap/micro-daemon/respond" "github.com/monitormap/micro-daemon/websocketserver" ) var ( wsserverForNodes = websocketserver.NewServer("/nodes") - responedDaemon *responed.Daemon + respondDaemon *respond.Daemon nodes = models.NewNodes() aliases = models.NewNodes() outputNodesFile string @@ -48,7 +48,7 @@ func main() { go wsserverForNodes.Listen() go nodes.Saver(outputNodesFile, saveInterval) go aliases.Saver(outputAliasesFile, saveInterval) - responedDaemon = responed.NewDaemon(func(coll *responed.Collector, res *responed.Response) { + respondDaemon = respond.NewDaemon(func(coll *respond.Collector, res *respond.Response) { var result map[string]interface{} json.Unmarshal(res.Raw, &result) @@ -71,7 +71,7 @@ func main() { field.Set(reflect.ValueOf(result)) }) - go responedDaemon.ListenAndSend(collectInterval) + go respondDaemon.ListenAndSend(collectInterval) http.Handle("/", http.FileServer(http.Dir("webroot"))) //TODO bad @@ -85,5 +85,5 @@ func main() { // Close everything at the end wsserverForNodes.Close() - responedDaemon.Close() + respondDaemon.Close() } diff --git a/responed/collector.go b/respond/collector.go similarity index 95% rename from responed/collector.go rename to respond/collector.go index 709500a..73c02e6 100644 --- a/responed/collector.go +++ b/respond/collector.go @@ -1,4 +1,4 @@ -package responed +package respond import ( "log" @@ -17,13 +17,13 @@ const ( maxDataGramSize int = 8192 ) -//Response of the responed request +//Response of the respond request type Response struct { Address net.UDPAddr Raw []byte } -//Collector for a specificle responed messages +//Collector for a specificle respond messages type Collector struct { CollectType string connection *net.UDPConn // UDP socket diff --git a/responed/daemon.go b/respond/daemon.go similarity index 97% rename from responed/daemon.go rename to respond/daemon.go index 6348f62..241e809 100644 --- a/responed/daemon.go +++ b/respond/daemon.go @@ -1,4 +1,4 @@ -package responed +package respond import "time"