示例#1
0
func TestGauge(t *testing.T) {
	var (
		name  = "xyz"
		value = 54321
		delta = 12345
		g     = expvar.NewGauge(name).With(metrics.Field{Key: "ignored", Value: "field"})
	)
	g.Set(float64(value))
	g.Add(float64(delta))
	if want, have := fmt.Sprint(value+delta), stdexpvar.Get(name).String(); want != have {
		t.Errorf("want %q, have %q", want, have)
	}
}
示例#2
0
文件: multi_test.go 项目: qband/down
func TestMultiGauge(t *testing.T) {
	g := metrics.NewMultiGauge(
		"multidelta",
		expvar.NewGauge("delta"),
		prometheus.NewGauge(stdprometheus.GaugeOpts{
			Namespace: "test",
			Subsystem: "multi_gauge",
			Name:      "kappa",
			Help:      "Kappa gauge.",
		}, []string{"a"}),
	)

	f := metrics.Field{Key: "a", Value: "aaa"}
	g.With(f).Set(34)

	if want, have := "34", stdexpvar.Get("delta").String(); want != have {
		t.Errorf("expvar: want %q, have %q", want, have)
	}
	if want, have := strings.Join([]string{
		`# HELP test_multi_gauge_kappa Kappa gauge.`,
		`# TYPE test_multi_gauge_kappa gauge`,
		`test_multi_gauge_kappa{a="aaa"} 34`,
	}, "\n"), scrapePrometheus(t); !strings.Contains(have, want) {
		t.Errorf("Prometheus metric stanza not found or incorrect\n%s", have)
	}

	g.With(f).Add(-40)

	if want, have := "-6", stdexpvar.Get("delta").String(); want != have {
		t.Errorf("expvar: want %q, have %q", want, have)
	}
	if want, have := strings.Join([]string{
		`# HELP test_multi_gauge_kappa Kappa gauge.`,
		`# TYPE test_multi_gauge_kappa gauge`,
		`test_multi_gauge_kappa{a="aaa"} -6`,
	}, "\n"), scrapePrometheus(t); !strings.Contains(have, want) {
		t.Errorf("Prometheus metric stanza not found or incorrect\n%s", have)
	}
}
示例#3
0
文件: expvar.go 项目: basvanbeek/kit
// NewGauge implements Provider.
func (p expvarProvider) NewGauge(name string) metrics.Gauge {
	return expvar.NewGauge(name)
}