2015-12-29 03:08:03 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-12-29 13:05:47 +00:00
|
|
|
"flag"
|
2015-12-29 03:08:03 +00:00
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
2015-12-29 13:05:47 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
nodes = NewNodes()
|
|
|
|
outputFile string
|
|
|
|
collectInterval time.Duration
|
|
|
|
saveInterval time.Duration
|
2015-12-29 03:08:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2015-12-29 13:05:47 +00:00
|
|
|
var collectSeconds, saveSeconds int
|
|
|
|
|
|
|
|
flag.StringVar(&outputFile, "output", "nodes.json", "path output file")
|
|
|
|
flag.IntVar(&collectSeconds, "collectInterval", 15, "interval for data collections")
|
|
|
|
flag.IntVar(&saveSeconds, "saveInterval", 5, "interval for data saving")
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
collectInterval = time.Second * time.Duration(collectSeconds)
|
|
|
|
saveInterval = time.Second * time.Duration(saveSeconds)
|
|
|
|
|
|
|
|
collectors := []*Collector{
|
|
|
|
NewCollector("statistics"),
|
|
|
|
NewCollector("nodeinfo"),
|
|
|
|
NewCollector("neighbours"),
|
|
|
|
}
|
2015-12-29 03:08:03 +00:00
|
|
|
|
|
|
|
// Wait for SIGINT or SIGTERM
|
|
|
|
sigs := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
sig := <-sigs
|
|
|
|
log.Println("received", sig)
|
|
|
|
|
2015-12-29 13:05:47 +00:00
|
|
|
for _, c := range collectors {
|
|
|
|
c.Close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func check(e error) {
|
|
|
|
if e != nil {
|
|
|
|
log.Panic(e)
|
|
|
|
}
|
2015-12-29 03:08:03 +00:00
|
|
|
}
|