Beispiel #1
0
// Start implements the Unit interface.
func (this *BaseUnit) Start(ch chan<- model.Metric) {
	this.RLock()
	fetchInterval := this.fetchInterval
	this.RUnlock()

	log.Debugf("Starting fetch for unit %v...", this)

	ticker := time.NewTicker(fetchInterval)
	defer ticker.Stop()

	c := reflect.ValueOf(this.unit)
	methodFetch := c.MethodByName("Fetch")
	methodFetch.Call([]reflect.Value{reflect.ValueOf(ch)})

	for {
		select {
		case <-this.fetchStop:
			return
		case <-ticker.C:
			methodFetch.Call([]reflect.Value{reflect.ValueOf(ch)})
		}
	}
}
Beispiel #2
0
// Stop implements the Unit interface.
func (this *BaseUnit) Stop() {
	log.Debugf("Stopping fetch for unit %v...", this)
	close(this.fetchStop)
	log.Debugf("Fetch for unit %v stopped.", this)
}