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.

46 lines
1.3 KiB

  1. package state
  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 = "state"
  12. )
  13. // Metrics contains metrics exposed by this package.
  14. type Metrics struct {
  15. // Time between BeginBlock and EndBlock.
  16. BlockProcessingTime metrics.Histogram
  17. }
  18. // PrometheusMetrics returns Metrics build using Prometheus client library.
  19. // Optionally, labels can be provided along with their values ("foo",
  20. // "fooValue").
  21. func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics {
  22. labels := []string{}
  23. for i := 0; i < len(labelsAndValues); i += 2 {
  24. labels = append(labels, labelsAndValues[i])
  25. }
  26. return &Metrics{
  27. BlockProcessingTime: prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{
  28. Namespace: namespace,
  29. Subsystem: MetricsSubsystem,
  30. Name: "block_processing_time",
  31. Help: "Time between BeginBlock and EndBlock in ms.",
  32. Buckets: stdprometheus.LinearBuckets(1, 10, 10),
  33. }, labels).With(labelsAndValues...),
  34. }
  35. }
  36. // NopMetrics returns no-op Metrics.
  37. func NopMetrics() *Metrics {
  38. return &Metrics{
  39. BlockProcessingTime: discard.NewHistogram(),
  40. }
  41. }