Пример #1
0
func (s *StatsTestSuite) TestCounterBasic(t *C) {
	stats, _ := mm.NewStats("counter")
	stats.Add(&mm.Metric{Name: "foo", Type: "counter", Number: 3}, 1)
	stats.Add(&mm.Metric{Name: "foo", Type: "counter", Number: 9}, 2)
	stats.Add(&mm.Metric{Name: "foo", Type: "counter", Number: 11}, 3)
	got := stats.Finalize()
	t.Check(got.Cnt, Equals, 2)
	t.Check(got.Min, Equals, float64(2))
	t.Check(got.Avg, Equals, float64(4))
	t.Check(got.Max, Equals, float64(6))
}
Пример #2
0
func (s *StatsTestSuite) TestCounterReset(t *C) {
	stats, _ := mm.NewStats("counter")
	stats.Add(&mm.Metric{Name: "foo", Type: "counter", Number: 3}, 1)
	stats.Add(&mm.Metric{Name: "foo", Type: "counter", Number: 9}, 2)  // +6
	stats.Add(&mm.Metric{Name: "foo", Type: "counter", Number: 11}, 3) // +2
	stats.Add(&mm.Metric{Name: "foo", Type: "counter", Number: 0}, 4)  // reset
	stats.Add(&mm.Metric{Name: "foo", Type: "counter", Number: 4}, 5)  // +4
	stats.Add(&mm.Metric{Name: "foo", Type: "counter", Number: 9}, 6)  // +5
	got := stats.Finalize()
	t.Check(got.Cnt, Equals, 4)
	t.Check(got.Min, Equals, float64(2))
	t.Check(got.Avg, Equals, float64(4.25))
	t.Check(got.Max, Equals, float64(6))
}
Пример #3
0
func (s *StatsTestSuite) TestValueLap(t *C) {
	var err error
	stats, _ := mm.NewStats("counter")
	err = stats.Add(&mm.Metric{Name: "foo", Type: "counter", Number: 100}, 1)
	t.Check(err, IsNil)
	err = stats.Add(&mm.Metric{Name: "foo", Type: "counter", Number: 200}, 2) // +100
	t.Check(err, IsNil)
	err = stats.Add(&mm.Metric{Name: "foo", Type: "counter", Number: 0}, 3) // reset
	t.Check(err, IsNil)
	err = stats.Add(&mm.Metric{Name: "foo", Type: "counter", Number: 350}, 4) // +350
	t.Check(err, NotNil)                                                      // lap detected
	got := stats.Finalize()
	t.Check(got.Cnt, Equals, 2)
	t.Check(got.Min, Equals, float64(100))
	t.Check(got.Avg, Equals, float64(225))
	t.Check(got.Max, Equals, float64(350))
}