Example #1
0
func expvarLoop() {
	tick := tsdb.Tick(10 * time.Second)
	for {
		t := <-tick
		tsdbutil.ExportVars(t, func(p *tsdb.Point) {
			metric := []byte("tsp.collect-netscaler.")
			metric = append(metric, p.Metric()...)
			if err := p.SetMetric(metric); err != nil {
				panic(err)
			}
			tsdbChan <- p
		})
	}
}
Example #2
0
func expvarLoop() {
	tick := tsdb.Tick(varInterval)
	for {
		now := <-tick
		metric := make([]byte, 0, 1024)
		tsdbutil.ExportVars(now, func(p *tsdb.Point) {
			metric = append(metric[:0], "tsp.collect-statse."...)
			metric = append(metric, p.Metric()...)
			err := p.SetMetric(metric)
			if err != nil {
				log.Panic(err)
			}
			tsdbChan <- p
		})
	}
}
Example #3
0
// Self returns a tsdb.Chan that carries complete dump of expvar variables.
// Refreshed according to Interval.
func Self(prefix string) tsdb.Chan {
	ch := make(chan *tsdb.Point)
	go func() {
		tick := tsdb.Tick(Interval)
		for {
			now := <-tick
			metric := make([]byte, 0, 1024)
			tsdbutil.ExportVars(now, func(p *tsdb.Point) {
				metric = append(metric[:0], prefix...)
				metric = append(metric, p.Metric()...)
				err := p.SetMetric(metric)
				if err != nil {
					log.Panic(err)
				}
				ch <- p
			})
		}
	}()
	return ch
}
Example #4
0
// Loop loops indefinitely, running all collectors at the provided interval,
// and writing to w the resulting data points.
func Loop(w chan *tsdb.Point, interval time.Duration) {
	tick := tsdb.Tick(interval)
	t := time.Now()
	for ; ; t = <-tick {
		start := time.Now()

		emit := newEmitter(w, t)
		var wg sync.WaitGroup
		for _, c := range collectors {
			c := c
			go func() {
				collect(emit, c)
				wg.Done()
			}()
			wg.Add(1)
		}
		wg.Wait()

		statCycleMillis.Add(time.Since(start).Nanoseconds() / 1e6)
	}
}