Esempio n. 1
0
func (app Application) StartQueueGauge() {
	if app.env.VCAPApplication.InstanceIndex != 0 {
		return
	}

	queueGauge := metrics.NewQueueGauge(app.mother.Queue(), metrics.DefaultLogger, time.Tick(1*time.Second))
	go queueGauge.Run()
}
Esempio n. 2
0
	. "github.com/onsi/gomega"
)

var _ = Describe("QueueGauge", func() {
	var (
		gauge  metrics.QueueGauge
		timer  chan time.Time
		queue  *mocks.Queue
		buffer *bytes.Buffer
	)

	BeforeEach(func() {
		buffer = bytes.NewBuffer([]byte{})
		queue = mocks.NewQueue()
		timer = make(chan time.Time, 10)
		gauge = metrics.NewQueueGauge(queue, metrics.NewLogger(buffer), timer)
	})

	It("reports the number of items on the queue as a metric", func() {
		go gauge.Run()

		Expect(buffer.String()).To(BeEmpty())

		timer <- time.Now()

		Eventually(func() []string {
			return strings.Split(buffer.String(), "\n")
		}).Should(Equal([]string{
			`[METRIC] {"kind":"gauge","payload":{"name":"notifications.queue.length","value":0}}`,
			`[METRIC] {"kind":"gauge","payload":{"name":"notifications.queue.retry","tags":{"count":"0"},"value":0}}`,
			`[METRIC] {"kind":"gauge","payload":{"name":"notifications.queue.retry","tags":{"count":"1"},"value":0}}`,