Пример #1
0
func RecurringTaskIncoming(begin logpoint.LogPoint) {
	dur, err := analysis.RecurringExpectedAfter(begin)
	if err == analysis.NoRecurringData {
		idl.Notice(`Skipping analysis scheduling of recurring task "` + begin.Task + `" due to missing data`)
		return
	}
	if err != nil {
		idl.Crit("Failed scheduling for analysis of recurring task", err, begin)
	}

	<-time.After(dur)
	err = analysis.CheckRecurredTaskEnd(begin)
	if err != nil {
		idl.Crit("Failed analysis of recurring task", err, begin)
	}
}
Пример #2
0
func loop(ch chan time.Time) {
	for {
		<-ch
		idl.Info("default task: tick")
		err := analysis.CheckRecurringFluctuation()
		if err != nil {
			idl.Crit("scheduled analysis.Check failed: ", err)
		}
	}
}
Пример #3
0
func RecurringBeginWatcher() {
	rc := analysis.NewResultContainer()
	err := rc.LoadLatest()
	if err != nil {
		idl.Crit("Failed scheduling of task begin analysis", err)
	}

	analyzer := func(t string, r analysis.Result) {
		go func(task string, res analysis.Result) {

			for {
				analysis.CheckRecurredTaskBegin(task)
				<-time.After(res.IntervalAvg + res.IntervalStdDev)
			}
		}(t, r)
	}

	rc.Range(analyzer)
}
Пример #4
0
func StdDev(durations []time.Duration, precision time.Duration) time.Duration {
	if len(durations) < 1 {
		return 0
	}

	var diffSqSum float64

	avg := reducePrecision(Avg(durations), precision)

	for _, duration := range durations {
		diff := reducePrecision(duration, precision) - avg
		diffSq := diff * diff
		diffSqSum = diffSqSum + diffSq
	}

	stdDeviationApproximation := math.Sqrt(diffSqSum / float64(len(durations)-1))

	if !(stdDeviationApproximation > -1) {
		idl.Crit("overflow detected - reduce standard deviation precision")
	}

	return time.Duration(stdDeviationApproximation) * precision
}