func configAdminRoutes() { http.HandleFunc("/exit", func(w http.ResponseWriter, r *http.Request) { if g.IsTrustable(r.RemoteAddr) { w.Write([]byte("exiting...")) go func() { time.Sleep(time.Second) os.Exit(0) }() } else { w.Write([]byte("no privilege")) } }) http.HandleFunc("/config/reload", func(w http.ResponseWriter, r *http.Request) { if g.IsTrustable(r.RemoteAddr) { g.ParseConfig(g.ConfigFile) RenderDataJson(w, g.Config()) } else { w.Write([]byte("no privilege")) } }) http.HandleFunc("/workdir", func(w http.ResponseWriter, r *http.Request) { RenderDataJson(w, file.SelfDir()) }) http.HandleFunc("/ips", func(w http.ResponseWriter, r *http.Request) { RenderDataJson(w, g.TrustableIps()) }) }
func main() { cfg := flag.String("c", "cfg.json", "configuration file") version := flag.Bool("v", false, "show version") check := flag.Bool("check", false, "check collector") flag.Parse() if *version { fmt.Println(g.VERSION) os.Exit(0) } if *check { funcs.CheckCollector() os.Exit(0) } g.ParseConfig(*cfg) g.InitRootDir() g.InitPublicIps() g.InitRpcClients() funcs.BuildMappers() go cron.InitDataHistory() cron.ReportAgentStatus() cron.SyncMinePlugins() cron.SyncBuiltinMetrics() cron.SyncTrustableIps() cron.Collect() go http.Start() select {} }