Beispiel #1
0
func (sc *StatsCollector) LogStats(exp *command.Expansions) {
	sc.expandCommands(exp)

	if sc.Interval < 0 {
		panic(fmt.Sprintf("Illegal interval: %v", sc.Interval))
	}
	if sc.stop != nil {
		panic("StatsCollector goroutine already running!")
	}
	if sc.Interval == 0 {
		sc.Interval = 60 * time.Second
	}

	sysloggerInfoWriter := evergreen.NewInfoLoggingWriter(sc.logger)
	sysloggerErrWriter := evergreen.NewErrorLoggingWriter(sc.logger)
	sc.stop = make(chan bool)

	go func() {
		ticker := time.NewTicker(sc.Interval)
		for {
			select {
			case <-ticker.C:
				for _, cmd := range sc.Cmds {
					sc.logger.Logf(slogger.INFO, "Running %v", cmd)
					command := &command.LocalCommand{
						CmdString: cmd,
						Stdout:    sysloggerInfoWriter,
						Stderr:    sysloggerErrWriter,
					}
					if err := command.Run(); err != nil {
						sc.logger.Logf(slogger.ERROR, "error running '%v': %v", cmd, err)
					}
				}
			case <-sc.stop:
				sc.logger.Logf(slogger.INFO, "StatsCollector ticker stopping.")
				ticker.Stop()
				sc.stop = nil
				return
			}
		}
	}()
}
Beispiel #2
0
func (sc *StatsCollector) LogStats(exp *command.Expansions) {
	sc.expandCommands(exp)

	if sc.Interval < 0 {
		panic(fmt.Sprintf("Illegal interval: %v", sc.Interval))
	}
	if sc.Interval == 0 {
		sc.Interval = 60 * time.Second
	}

	sysloggerInfoWriter := evergreen.NewInfoLoggingWriter(sc.logger)
	sysloggerErrWriter := evergreen.NewErrorLoggingWriter(sc.logger)

	go func() {
		for {
			select {
			case <-sc.stop:
				sc.logger.Logf(slogger.INFO, "StatsCollector ticker stopping.")
				return
			default:
				for _, cmd := range sc.Cmds {
					sc.logger.Logf(slogger.INFO, "Running %v", cmd)
					command := &command.LocalCommand{
						CmdString: cmd,
						Stdout:    sysloggerInfoWriter,
						Stderr:    sysloggerErrWriter,
					}
					if err := command.Run(); err != nil {
						sc.logger.Logf(slogger.ERROR, "error running '%v': %v", cmd, err)
					}
				}
				time.Sleep(sc.Interval)
			}
		}
	}()
}