2015-12-29 03:08:03 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-02-19 10:30:42 +00:00
|
|
|
"flag"
|
2015-12-29 03:08:03 +00:00
|
|
|
"log"
|
2016-02-25 20:06:37 +00:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
|
2016-10-03 17:55:37 +00:00
|
|
|
"github.com/FreifunkBremen/respond-collector/database"
|
2016-03-15 22:26:30 +00:00
|
|
|
"github.com/FreifunkBremen/respond-collector/models"
|
|
|
|
"github.com/FreifunkBremen/respond-collector/respond"
|
2016-10-03 17:56:02 +00:00
|
|
|
"github.com/FreifunkBremen/respond-collector/rrd"
|
2017-01-29 19:06:56 +00:00
|
|
|
"github.com/FreifunkBremen/respond-collector/webserver"
|
2015-12-29 13:05:47 +00:00
|
|
|
)
|
2016-02-25 20:06:37 +00:00
|
|
|
|
2016-02-19 10:30:42 +00:00
|
|
|
var (
|
2016-06-16 16:03:45 +00:00
|
|
|
configFile string
|
|
|
|
config *models.Config
|
|
|
|
collector *respond.Collector
|
2016-10-03 17:55:37 +00:00
|
|
|
db *database.DB
|
2016-06-16 16:03:45 +00:00
|
|
|
nodes *models.Nodes
|
2016-02-19 10:30:42 +00:00
|
|
|
)
|
2016-02-25 20:06:37 +00:00
|
|
|
|
|
|
|
func main() {
|
2016-10-03 17:56:02 +00:00
|
|
|
var importPath string
|
|
|
|
flag.StringVar(&importPath, "import", "", "import global statistics from the given RRD file, requires influxdb")
|
2017-01-29 17:30:08 +00:00
|
|
|
flag.StringVar(&configFile, "config", "config.toml", "path of configuration file (default:config.yaml)")
|
2016-02-19 10:30:42 +00:00
|
|
|
flag.Parse()
|
2016-03-20 18:54:43 +00:00
|
|
|
config = models.ReadConfigFile(configFile)
|
2016-02-25 20:06:37 +00:00
|
|
|
|
2016-03-12 02:36:02 +00:00
|
|
|
if config.Influxdb.Enable {
|
2016-10-03 17:55:37 +00:00
|
|
|
db = database.New(config)
|
2016-10-03 22:50:39 +00:00
|
|
|
defer db.Close()
|
2016-10-03 17:56:02 +00:00
|
|
|
|
|
|
|
if importPath != "" {
|
|
|
|
importRRD(importPath)
|
2016-10-03 22:50:39 +00:00
|
|
|
return
|
2016-10-03 17:56:02 +00:00
|
|
|
}
|
2016-03-12 02:36:02 +00:00
|
|
|
}
|
|
|
|
|
2016-10-03 17:55:37 +00:00
|
|
|
nodes = models.NewNodes(config)
|
2016-11-20 17:45:18 +00:00
|
|
|
nodes.Start()
|
|
|
|
|
2016-03-09 02:26:08 +00:00
|
|
|
if config.Respondd.Enable {
|
2016-12-22 02:06:46 +00:00
|
|
|
collector = respond.NewCollector(db, nodes, config.Respondd.Interface)
|
2017-01-29 17:30:08 +00:00
|
|
|
collector.Start(config.Respondd.CollectInterval.Duration)
|
2016-10-03 22:50:39 +00:00
|
|
|
defer collector.Close()
|
2016-03-07 08:52:52 +00:00
|
|
|
}
|
2016-02-25 20:06:37 +00:00
|
|
|
|
2016-03-07 08:52:52 +00:00
|
|
|
if config.Webserver.Enable {
|
2017-01-29 19:06:56 +00:00
|
|
|
log.Println("starting webserver on", config.Webserver.Bind)
|
|
|
|
srv := webserver.New(config.Webserver.Bind, config.Webserver.Webroot)
|
|
|
|
go srv.Close()
|
2016-03-07 08:52:52 +00:00
|
|
|
}
|
2016-03-12 02:58:36 +00:00
|
|
|
|
|
|
|
// Wait for INT/TERM
|
2016-02-25 20:06:37 +00:00
|
|
|
sigs := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
sig := <-sigs
|
|
|
|
log.Println("received", sig)
|
2016-03-12 02:58:36 +00:00
|
|
|
}
|
2016-10-03 17:56:02 +00:00
|
|
|
|
|
|
|
func importRRD(path string) {
|
|
|
|
log.Println("importing RRD from", path)
|
|
|
|
for ds := range rrd.Read(path) {
|
|
|
|
db.AddPoint(
|
|
|
|
database.MeasurementGlobal,
|
|
|
|
nil,
|
|
|
|
map[string]interface{}{
|
2016-11-20 18:02:03 +00:00
|
|
|
"nodes": uint32(ds.Nodes),
|
|
|
|
"clients.total": uint32(ds.Clients),
|
2016-10-03 17:56:02 +00:00
|
|
|
},
|
|
|
|
ds.Time,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|