Пример #1
0
func doMain() error {
	flag.Parse()
	runtime.GOMAXPROCS(int(*maxThreads))
	runtime.LockOSThread()
	circularBuffer := logbuf.New(*logbufLines)
	logger := log.New(circularBuffer, "", log.LstdFlags)
	probers, err := setupProbers()
	if err != nil {
		return err
	}
	latencyBucketer := tricorder.NewGeometricBucketer(0.1, 100e3)
	scanTimeDistribution := latencyBucketer.NewDistribution()
	var scanStartTime time.Time
	if err := tricorder.RegisterMetric("scan-duration",
		scanTimeDistribution, units.Millisecond,
		"duration of last probe"); err != nil {
		return err
	}
	if err := tricorder.RegisterMetric("scan-start-time", &scanStartTime,
		units.None, "start time of last probe"); err != nil {
		return err
	}
	rpc.HandleHTTP()
	httpd.AddHtmlWriter(circularBuffer)
	if err := httpd.StartServer(*portNum); err != nil {
		return err
	}
	for {
		scanStartTime = time.Now()
		for _, p := range probers {
			if err := p.Probe(); err != nil {
				logger.Println(err)
			}
		}
		scanDuration := time.Since(scanStartTime)
		scanTimeDistribution.Add(scanDuration)
		time.Sleep(time.Second*time.Duration(*probeInterval) - scanDuration)
	}
	_ = logger
	return nil
}
Пример #2
0
func doMain() error {
	flag.Parse()
	runtime.GOMAXPROCS(int(*maxThreads))
	runtime.LockOSThread()
	circularBuffer := logbuf.New()
	logger := log.New(circularBuffer, "", log.LstdFlags)
	proberList, err := setupProbers()
	if err != nil {
		return err
	}
	if err := setupHealthchecks(*configDir, proberList, logger); err != nil {
		logger.Printf("Error occured while setting up Healthchecks")
		return err
	}
	httpd.AddHtmlWriter(proberList)
	httpd.AddHtmlWriter(circularBuffer)
	sighupChannel := make(chan os.Signal)
	signal.Notify(sighupChannel, syscall.SIGHUP)
	sigtermChannel := make(chan os.Signal)
	signal.Notify(sigtermChannel, syscall.SIGTERM, syscall.SIGINT)
	rpc.HandleHTTP()
	if err := httpd.StartServer(*portNum); err != nil {
		return err
	}
	writePidfile()
	proberList.StartProbing(*probeInterval, logger)
	for {
		select {
		case <-sighupChannel:
			err = syscall.Exec(os.Args[0], os.Args, os.Environ())
			if err != nil {
				logger.Printf("Unable to Exec:%s\t%s\n", os.Args[0], err)
			}
		case <-sigtermChannel:
			gracefulCleanup()
		}
	}
	return nil
}