You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1018 B

  1. package eventlog
  2. import (
  3. "github.com/go-kit/kit/metrics/prometheus"
  4. stdprometheus "github.com/prometheus/client_golang/prometheus"
  5. )
  6. // gauge is the subset of the Prometheus gauge interface used here.
  7. type gauge interface {
  8. Set(float64)
  9. }
  10. // Metrics define the metrics exported by the eventlog package.
  11. type Metrics struct {
  12. numItemsGauge gauge
  13. }
  14. // discard is a no-op implementation of the gauge interface.
  15. type discard struct{}
  16. func (discard) Set(float64) {}
  17. const eventlogSubsystem = "eventlog"
  18. // PrometheusMetrics returns a collection of eventlog metrics for Prometheus.
  19. func PrometheusMetrics(ns string, fields ...string) *Metrics {
  20. var labels []string
  21. for i := 0; i < len(fields); i += 2 {
  22. labels = append(labels, fields[i])
  23. }
  24. return &Metrics{
  25. numItemsGauge: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  26. Namespace: ns,
  27. Subsystem: eventlogSubsystem,
  28. Name: "num_items",
  29. Help: "Number of items currently resident in the event log.",
  30. }, labels).With(fields...),
  31. }
  32. }