예제 #1
0
func setupMetrics(listenAddr, enabledCollectors string) {
	if enabledCollectors == "" {
		enabledCollectors = sysmetrics.FilterAvailableCollectors(sysmetrics.DefaultCollectors)
	}
	collectors, err := sysmetrics.LoadCollectors(enabledCollectors)
	if err != nil {
		log.Fatalf("Couldn't load collectors: %s", err)
	}
	nodeCollector := sysmetrics.New(collectors)
	prometheus.MustRegister(nodeCollector)
	http.Handle("/metrics", prometheus.Handler())
	go http.ListenAndServe(listenAddr, nil)
}
예제 #2
0
func main() {
	var err error
	configFile := "/etc/syndicate/syndicate.toml"
	if os.Getenv("SYNDICATE_CONFIG") != "" {
		configFile = os.Getenv("SYNDICATE_CONFIG")
	}
	flag.Parse()
	if *printVersionInfo {
		fmt.Println("syndicate-client:", syndVersion)
		fmt.Println("ring version:", ringVersion)
		fmt.Println("build date:", buildDate)
		fmt.Println("go version:", goVersion)
		return
	}
	rs := &RingSyndicates{
		ch:               make(chan bool),
		ShutdownComplete: make(chan bool),
		waitGroup:        &sync.WaitGroup{},
		stopped:          false,
	}

	var tc map[string]syndicate.Config
	if _, err := toml.DecodeFile(configFile, &tc); err != nil {
		log.Fatalln(err)
	}
	for k, v := range tc {
		log.Println("Found config for", k)
		log.Println("Config:", v)
		syndic := &RingSyndicate{
			active: false,
			name:   k,
			config: v,
		}
		syndic.server, err = syndicate.NewServer(&syndic.config, k)
		if err != nil {
			log.Fatalln(err)
		}
		rs.Syndics = append(rs.Syndics, syndic)
	}
	rs.Lock()
	defer rs.Unlock()
	for k, _ := range rs.Syndics {
		go rs.launchSyndicates(k)
	}
	//now that syndics are up and running launch global metrics endpoint
	//setup node_collector for system level metrics first
	collectors, err := sysmetrics.LoadCollectors(*enabledCollectors)
	if err != nil {
		log.Fatalf("Couldn't load collectors: %s", err)
	}
	nodeCollector := sysmetrics.New(collectors)
	prometheus.MustRegister(nodeCollector)
	http.Handle("/metrics", prometheus.Handler())
	go http.ListenAndServe(":9100", nil)
	ch := make(chan os.Signal)
	signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
	for {
		select {
		case <-ch:
			rs.Stop()
			<-rs.ShutdownComplete
			return
		case <-rs.ShutdownComplete:
			return
		}
	}
}