Пример #1
0
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)
	}
}
Пример #2
0
func TestPrometheusGauge(t *testing.T) {
	c := prometheus.NewGauge(stdprometheus.GaugeOpts{
		Namespace: "test",
		Subsystem: "prometheus_gauge",
		Name:      "foobar",
		Help:      "Dolor sit.",
	}, []string{})
	c.Set(42)
	if want, have := strings.Join([]string{
		`# HELP test_prometheus_gauge_foobar Dolor sit.`,
		`# TYPE test_prometheus_gauge_foobar gauge`,
		`test_prometheus_gauge_foobar 42`,
	}, "\n"), teststat.ScrapePrometheus(t); !strings.Contains(have, want) {
		t.Errorf("metric stanza not found or incorrect\n%s", have)
	}
	c.Add(-43)
	if want, have := strings.Join([]string{
		`# HELP test_prometheus_gauge_foobar Dolor sit.`,
		`# TYPE test_prometheus_gauge_foobar gauge`,
		`test_prometheus_gauge_foobar -1`,
	}, "\n"), teststat.ScrapePrometheus(t); !strings.Contains(have, want) {
		t.Errorf("metric stanza not found or incorrect\n%s", have)
	}
}
Пример #3
0
package metrics

import (
	"github.com/go-kit/kit/metrics"

	kitprometheus "github.com/go-kit/kit/metrics/prometheus"
	stdprometheus "github.com/prometheus/client_golang/prometheus"

	"time"
)

var (
	Fetching = kitprometheus.NewGauge(stdprometheus.GaugeOpts{
		Namespace: "glia",
		Subsystem: "fetcher",
		Name:      "fetching",
		Help:      "Number of fetching operations waiting to be processed.",
	}, []string{})
	Sending = kitprometheus.NewGauge(stdprometheus.GaugeOpts{
		Namespace: "glia",
		Subsystem: "sender",
		Name:      "sending",
		Help:      "Number of sending operations waiting to be processed.",
	}, []string{})

	FetchLatency = metrics.NewTimeHistogram(time.Microsecond, kitprometheus.NewSummary(stdprometheus.SummaryOpts{
		Namespace: "glia",
		Subsystem: "fetcher",
		Name:      "fetch_latency_microseconds",
		Help:      "Total duration of fetching in microseconds.",
	}, []string{}))