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.

47 lines
1.3 KiB

  1. package evidence
  2. import (
  3. "github.com/go-kit/kit/metrics"
  4. "github.com/go-kit/kit/metrics/discard"
  5. "github.com/go-kit/kit/metrics/prometheus"
  6. stdprometheus "github.com/prometheus/client_golang/prometheus"
  7. )
  8. const (
  9. // MetricsSubsystem is a subsystem shared by all metrics exposed by this
  10. // package.
  11. MetricsSubsystem = "evidence_pool"
  12. )
  13. // Metrics contains metrics exposed by this package.
  14. // see MetricsProvider for descriptions.
  15. type Metrics struct {
  16. // Number of evidence in the evidence pool
  17. NumEvidence metrics.Gauge
  18. }
  19. // PrometheusMetrics returns Metrics build using Prometheus client library.
  20. // Optionally, labels can be provided along with their values ("foo",
  21. // "fooValue").
  22. func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics {
  23. labels := []string{}
  24. for i := 0; i < len(labelsAndValues); i += 2 {
  25. labels = append(labels, labelsAndValues[i])
  26. }
  27. return &Metrics{
  28. NumEvidence: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  29. Namespace: namespace,
  30. Subsystem: MetricsSubsystem,
  31. Name: "num_evidence",
  32. Help: "Number of pending evidence in evidence pool.",
  33. }, labels).With(labelsAndValues...),
  34. }
  35. }
  36. // NopMetrics returns no-op Metrics.
  37. func NopMetrics() *Metrics {
  38. return &Metrics{
  39. NumEvidence: discard.NewGauge(),
  40. }
  41. }