add README

This commit is contained in:
Martin Geno 2016-02-26 09:28:31 +01:00
parent 5c9eff324f
commit 16473e25cf
4 changed files with 54 additions and 9 deletions

45
README.md Normal file
View File

@ -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.

10
main.go
View File

@ -14,13 +14,13 @@ import (
"time" "time"
"github.com/monitormap/micro-daemon/models" "github.com/monitormap/micro-daemon/models"
"github.com/monitormap/micro-daemon/responed" "github.com/monitormap/micro-daemon/respond"
"github.com/monitormap/micro-daemon/websocketserver" "github.com/monitormap/micro-daemon/websocketserver"
) )
var ( var (
wsserverForNodes = websocketserver.NewServer("/nodes") wsserverForNodes = websocketserver.NewServer("/nodes")
responedDaemon *responed.Daemon respondDaemon *respond.Daemon
nodes = models.NewNodes() nodes = models.NewNodes()
aliases = models.NewNodes() aliases = models.NewNodes()
outputNodesFile string outputNodesFile string
@ -48,7 +48,7 @@ func main() {
go wsserverForNodes.Listen() go wsserverForNodes.Listen()
go nodes.Saver(outputNodesFile, saveInterval) go nodes.Saver(outputNodesFile, saveInterval)
go aliases.Saver(outputAliasesFile, 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{} var result map[string]interface{}
json.Unmarshal(res.Raw, &result) json.Unmarshal(res.Raw, &result)
@ -71,7 +71,7 @@ func main() {
field.Set(reflect.ValueOf(result)) field.Set(reflect.ValueOf(result))
}) })
go responedDaemon.ListenAndSend(collectInterval) go respondDaemon.ListenAndSend(collectInterval)
http.Handle("/", http.FileServer(http.Dir("webroot"))) http.Handle("/", http.FileServer(http.Dir("webroot")))
//TODO bad //TODO bad
@ -85,5 +85,5 @@ func main() {
// Close everything at the end // Close everything at the end
wsserverForNodes.Close() wsserverForNodes.Close()
responedDaemon.Close() respondDaemon.Close()
} }

View File

@ -1,4 +1,4 @@
package responed package respond
import ( import (
"log" "log"
@ -17,13 +17,13 @@ const (
maxDataGramSize int = 8192 maxDataGramSize int = 8192
) )
//Response of the responed request //Response of the respond request
type Response struct { type Response struct {
Address net.UDPAddr Address net.UDPAddr
Raw []byte Raw []byte
} }
//Collector for a specificle responed messages //Collector for a specificle respond messages
type Collector struct { type Collector struct {
CollectType string CollectType string
connection *net.UDPConn // UDP socket connection *net.UDPConn // UDP socket

View File

@ -1,4 +1,4 @@
package responed package respond
import "time" import "time"