Пример #1
0
func ExamplePauses() {
	pauses := NewPauses(512)
	go func() {
		for {
			pauses.Update()
			time.Sleep(time.Minute)
		}
	}()
	perc95 := instruments.Quantile(pauses.Snapshot(), 0.95)
	fmt.Println(perc95)
}
Пример #2
0
// Log logs metrics using logfmt every given duration.
func Log(source string, r *Registry, d time.Duration) {
	for {
		time.Sleep(d)
		var parts []string
		for k, m := range r.Instruments() {
			switch i := m.(type) {
			case instruments.Discrete:
				s := i.Snapshot()
				parts = append(parts, fmt.Sprintf("sample#%s=%d", k, s))
			case instruments.Sample:
				s := instruments.Quantile(i.Snapshot(), 0.95)
				parts = append(parts, fmt.Sprintf("sample#%s=%d", k, s))
			}
		}
		log.Println(fmt.Sprintf("source=%s", source), strings.Join(parts, " "))
	}
}