Esempio n. 1
0
func (a *Reporter) Start() hitman.KillChannel {
	done := hitman.NewKillChannel()
	tripwire := 1 * time.Second
	tic := time.NewTicker(tripwire).C
	last := time.Now().UnixNano()
	_1000ms := time.Duration(1000)
	fuzz := time.Duration(10)

	go func() {
		for {
			select {
			case cleaner := <-done:
				cleaner.WaitGroup.Done()
				fmt.Println("Closing reporter")
				return
			case p1 := <-a.points:
				a.batch.AddPoint(p1)
				n := len(a.points)
				for i := 0; i < n; i++ {
					a.batch.AddPoint(<-a.points)
				}
			case <-tic:
				now := time.Now().UnixNano()
				diff := now - last
				delta := time.Duration(diff) / time.Millisecond
				isOverdue := _1000ms < (delta + fuzz)

				if !isOverdue {
					continue
				}
				fmt.Println(len(a.accum), len(a.points), len(a.batch.Points()))
				bp := a.batch
				newPts, err := flux.NewBatchPoints(a.conf)
				if err != nil {
					fmt.Println(err)
				}
				a.batch = newPts
				a.accum <- bp
				last = time.Now().UnixNano()
			}
		}
	}()

	return done
}
Esempio n. 2
0
func (a *Flusher) Start() hitman.KillChannel {
	killSwitch := hitman.NewKillChannel()

	go func() {
		for {
			select {
			case cleaner := <-killSwitch:
				cleaner.WaitGroup.Done()
				return
			case batch := <-a.points:
				pts := batch.Points()
				for n, p := range pts {
					a.flush(p, n)
				}
			}
		}
	}()

	return killSwitch
}
Esempio n. 3
0
func (f *Fired) Start() hitman.KillChannel {
	add := f.add
	m, err := capture.New("client.request")
	if err != nil {
		panic(err)
	}
	m.Tag("service", "fire")
	m.Tag("ip", "127.0.0.1")
	tic := time.NewTicker(20 * time.Millisecond).C
	numIncoming := int32(f.numIncoming)
	kill := hitman.NewKillChannel()

	go func() {
		for {
			select {
			case cleaner := <-kill:
				cleaner.WaitGroup.Done()
				return
			case now := <-tic:
				n := rand.Int31n(numIncoming)
				r := now.UnixNano()
				for i := int32(0); i < n; i++ {
					m.Field("value", r)
					m.Field("now", r)

					pt, err := m.Point()
					if err != nil {
						fmt.Println(err)
					}
					add <- pt
				}
			}
		}
	}()

	return kill
}