Esempio n. 1
0
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())
	})
}
Esempio n. 2
0
func rpcTransferUpdate() {
	ag.ParseConfig(agentConfig)
	ag.InitRpcClients()

	now := time.Now().Unix()
	value := now % 100
	metrics := []*model.MetricValue{}
	mv := &model.MetricValue{"fake-agent", "cpu.idle", value, step, "GAUGE", "module=transfer-fake", now}
	metrics = append(metrics, mv)

	fmt.Printf("[REQ .] <Total=%d> %v\n", len(metrics), metrics[0])

	var resp model.TransferResponse
	err := ag.TransferClient.Call("Transfer.Update", metrics, &resp)
	if err != nil {
		fmt.Println("[ERROR] Transfer.Update:", err)
	}

	fmt.Println("[RESP.]", &resp)
}
Esempio n. 3
0
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.GetHostnameFromAws()

	g.InitRootDir()
	g.InitLocalIps()
	g.InitRpcClients()

	funcs.BuildMappers()

	go cron.InitDataHistory()

	cron.ReportAgentStatus()
	cron.SyncMinePlugins()
	cron.SyncBuiltinMetrics()
	cron.SyncTrustableIps()
	cron.Collect()

	go http.Start()

	select {}

}