2015-12-29 04:08:03 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-02-19 11:30:42 +01:00
|
|
|
"flag"
|
2015-12-29 04:08:03 +01:00
|
|
|
"log"
|
2016-02-19 11:30:42 +01:00
|
|
|
"time"
|
2016-02-19 11:13:30 +01:00
|
|
|
"net/http"
|
2015-12-29 14:05:47 +01:00
|
|
|
)
|
2016-02-19 11:30:42 +01:00
|
|
|
var (
|
|
|
|
nodeserver = NewNodeServer("/nodes")
|
|
|
|
nodes = NewNodes()
|
|
|
|
outputFile string
|
|
|
|
collectInterval time.Duration
|
|
|
|
saveInterval time.Duration
|
|
|
|
)
|
2016-02-19 11:13:30 +01:00
|
|
|
func main(){
|
2016-02-19 11:30:42 +01:00
|
|
|
var collectSeconds, saveSeconds int
|
|
|
|
|
2016-02-19 11:41:39 +01:00
|
|
|
flag.StringVar(&outputFile, "output", "webroot/nodes.json", "path output file")
|
2016-02-19 11:30:42 +01:00
|
|
|
flag.IntVar(&collectSeconds, "collectInterval", 15, "interval for data collections")
|
|
|
|
flag.IntVar(&saveSeconds, "saveInterval", 5, "interval for data saving")
|
|
|
|
flag.Parse()
|
2015-12-29 14:05:47 +01:00
|
|
|
|
2016-02-19 11:30:42 +01:00
|
|
|
collectInterval = time.Second * time.Duration(collectSeconds)
|
|
|
|
saveInterval = time.Second * time.Duration(saveSeconds)
|
|
|
|
|
|
|
|
collectors := []*Collector{
|
|
|
|
NewCollector("statistics"),
|
|
|
|
NewCollector("nodeinfo"),
|
|
|
|
NewCollector("neighbours"),
|
|
|
|
}
|
|
|
|
|
|
|
|
go nodeserver.Listen()
|
|
|
|
|
2016-02-19 11:13:30 +01:00
|
|
|
// static files
|
|
|
|
http.Handle("/", http.FileServer(http.Dir("webroot")))
|
2015-12-29 14:05:47 +01:00
|
|
|
|
2016-02-19 11:13:30 +01:00
|
|
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
2016-02-19 11:30:42 +01:00
|
|
|
for _, c := range collectors {
|
|
|
|
c.Close()
|
|
|
|
}
|
2015-12-29 04:08:03 +01:00
|
|
|
}
|