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.

91 lines
3.3 KiB

  1. package statesync
  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 package.
  10. MetricsSubsystem = "statesync"
  11. )
  12. // Metrics contains metrics exposed by this package.
  13. type Metrics struct {
  14. TotalSnapshots metrics.Counter
  15. ChunkProcessAvgTime metrics.Gauge
  16. SnapshotHeight metrics.Gauge
  17. SnapshotChunk metrics.Counter
  18. SnapshotChunkTotal metrics.Gauge
  19. BackFilledBlocks metrics.Counter
  20. BackFillBlocksTotal metrics.Gauge
  21. }
  22. // PrometheusMetrics returns Metrics build using Prometheus client library.
  23. // Optionally, labels can be provided along with their values ("foo",
  24. // "fooValue").
  25. func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics {
  26. labels := []string{}
  27. for i := 0; i < len(labelsAndValues); i += 2 {
  28. labels = append(labels, labelsAndValues[i])
  29. }
  30. return &Metrics{
  31. TotalSnapshots: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
  32. Namespace: namespace,
  33. Subsystem: MetricsSubsystem,
  34. Name: "total_snapshots",
  35. Help: "The total number of snapshots discovered.",
  36. }, labels).With(labelsAndValues...),
  37. ChunkProcessAvgTime: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  38. Namespace: namespace,
  39. Subsystem: MetricsSubsystem,
  40. Name: "chunk_process_avg_time",
  41. Help: "The average processing time per chunk.",
  42. }, labels).With(labelsAndValues...),
  43. SnapshotHeight: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  44. Namespace: namespace,
  45. Subsystem: MetricsSubsystem,
  46. Name: "snapshot_height",
  47. Help: "The height of the current snapshot the has been processed.",
  48. }, labels).With(labelsAndValues...),
  49. SnapshotChunk: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
  50. Namespace: namespace,
  51. Subsystem: MetricsSubsystem,
  52. Name: "snapshot_chunk",
  53. Help: "The current number of chunks that have been processed.",
  54. }, labels).With(labelsAndValues...),
  55. SnapshotChunkTotal: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  56. Namespace: namespace,
  57. Subsystem: MetricsSubsystem,
  58. Name: "snapshot_chunks_total",
  59. Help: "The total number of chunks in the current snapshot.",
  60. }, labels).With(labelsAndValues...),
  61. BackFilledBlocks: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
  62. Namespace: namespace,
  63. Subsystem: MetricsSubsystem,
  64. Name: "backfilled_blocks",
  65. Help: "The current number of blocks that have been back-filled.",
  66. }, labels).With(labelsAndValues...),
  67. BackFillBlocksTotal: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  68. Namespace: namespace,
  69. Subsystem: MetricsSubsystem,
  70. Name: "backfilled_blocks_total",
  71. Help: "The total number of blocks that need to be back-filled.",
  72. }, labels).With(labelsAndValues...),
  73. }
  74. }
  75. // NopMetrics returns no-op Metrics.
  76. func NopMetrics() *Metrics {
  77. return &Metrics{
  78. TotalSnapshots: discard.NewCounter(),
  79. ChunkProcessAvgTime: discard.NewGauge(),
  80. SnapshotHeight: discard.NewGauge(),
  81. SnapshotChunk: discard.NewCounter(),
  82. SnapshotChunkTotal: discard.NewGauge(),
  83. BackFilledBlocks: discard.NewCounter(),
  84. BackFillBlocksTotal: discard.NewGauge(),
  85. }
  86. }