Ejemplo n.º 1
0
func (s *mgoStatsSuite) TestDescribe(c *gc.C) {
	expectDescriptions := []*prometheus.Desc{
		clusterDesc,
		masterConnDesc,
		slaveConnDesc,
		sentOpsDesc,
		receivedOpsDesc,
		receivedDocsDesc,
		socketsAliveDesc,
		socketsInUseDesc,
		socketRefsDesc,
	}

	coll := monitoring.NewMgoStatsCollector("test")
	ch := make(chan *prometheus.Desc)
	go func() {
		defer close(ch)
		coll.Describe(ch)
	}()

	var obtainedDescriptions []*prometheus.Desc
	for d := range ch {
		obtainedDescriptions = append(obtainedDescriptions, d)
	}
	c.Assert(obtainedDescriptions, jc.DeepEquals, expectDescriptions)
}
Ejemplo n.º 2
0
func (s *mgoStatsSuite) TestCollect(c *gc.C) {
	coll := monitoring.NewMgoStatsCollector("test")
	ch := make(chan prometheus.Metric)
	go func() {
		defer close(ch)
		coll.Collect(ch)
	}()
	stats := mgo.GetStats()
	var obtainedMetrics []prometheus.Metric
	for m := range ch {
		obtainedMetrics = append(obtainedMetrics, m)
	}
	c.Assert(obtainedMetrics, gc.HasLen, 9)

	c.Assert(obtainedMetrics[0].Desc(), jc.DeepEquals, clusterDesc)
	s.assertGauge(c, obtainedMetrics[0], float64(stats.Clusters))

	c.Assert(obtainedMetrics[1].Desc(), jc.DeepEquals, masterConnDesc)
	s.assertGauge(c, obtainedMetrics[1], float64(stats.MasterConns))

	c.Assert(obtainedMetrics[2].Desc(), jc.DeepEquals, slaveConnDesc)
	s.assertGauge(c, obtainedMetrics[2], float64(stats.SlaveConns))

	c.Assert(obtainedMetrics[3].Desc(), jc.DeepEquals, sentOpsDesc)
	s.assertGauge(c, obtainedMetrics[3], float64(stats.SentOps))

	c.Assert(obtainedMetrics[4].Desc(), jc.DeepEquals, receivedOpsDesc)
	s.assertGauge(c, obtainedMetrics[4], float64(stats.ReceivedOps))

	c.Assert(obtainedMetrics[5].Desc(), jc.DeepEquals, receivedDocsDesc)
	s.assertGauge(c, obtainedMetrics[5], float64(stats.ReceivedDocs))

	c.Assert(obtainedMetrics[6].Desc(), jc.DeepEquals, socketsAliveDesc)
	s.assertGauge(c, obtainedMetrics[6], float64(stats.SocketsAlive))

	c.Assert(obtainedMetrics[7].Desc(), jc.DeepEquals, socketsInUseDesc)
	s.assertGauge(c, obtainedMetrics[7], float64(stats.SocketsInUse))

	c.Assert(obtainedMetrics[8].Desc(), jc.DeepEquals, socketRefsDesc)
	s.assertGauge(c, obtainedMetrics[8], float64(stats.SocketRefs))
}