示例#1
0
func (s *StatsDaemon) Run() {
	log.Printf("statsdaemon instance '%s' starting\n", s.instance)
	output := &common.Output{s.Metrics, s.metricAmounts, s.valid_lines, s.Invalid_lines}
	go udp.StatsListener(s.listen_addr, s.prefix, output)
	go s.adminListener()
	go s.metricStatsMonitor()
	s.metricsMonitor()
}
示例#2
0
func main() {
	flag.Parse()

	if *showVersion {
		fmt.Printf("statsdaemon v%s (built w/%s)\n", VERSION, runtime.Version())
		return
	}
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}
	if *memprofile != "" {
		f, err := os.Create(*memprofile)
		if err != nil {
			log.Fatal(err)
		}
		defer f.Close()
		defer pprof.WriteHeapProfile(f)
	}
	config.Parse(*config_file)
	pcts := strings.Split(*percentile_thresholds, ",")
	for _, pct := range pcts {
		percentThreshold.Set(pct)
	}
	inst := os.Expand(*instance, expand_cfg_vars)
	if inst == "" {
		inst = "null"
	}
	prefix_internal = "service=statsdaemon.instance=" + inst + "."
	log.Printf("statsdaemon instance '%s' starting\n", inst)

	signalchan = make(chan os.Signal, 1)
	signal.Notify(signalchan)
	if *debug {
		consumer := make(chan interface{}, 100)
		invalid_lines.Register(consumer)
		go func() {
			for line := range consumer {
				log.Printf("invalid line '%s'\n", line)
			}
		}()
	}
	output := &common.Output{Metrics, metricAmounts, valid_lines, invalid_lines}
	go udp.StatsListener(*listen_addr, prefix_internal, output)
	go udp.ArchiveStatsListener(*listen_archive_addr, prefix_internal, output)
	go adminListener()
	go metricStatsMonitor()
	metricsMonitor()
}