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.

164 lines
5.1 KiB

6 years ago
6 years ago
6 years ago
  1. package consensus
  2. import (
  3. "github.com/go-kit/kit/metrics"
  4. "github.com/go-kit/kit/metrics/discard"
  5. prometheus "github.com/go-kit/kit/metrics/prometheus"
  6. stdprometheus "github.com/prometheus/client_golang/prometheus"
  7. )
  8. const MetricsSubsystem = "consensus"
  9. // Metrics contains metrics exposed by this package.
  10. type Metrics struct {
  11. // Height of the chain.
  12. Height metrics.Gauge
  13. // Number of rounds.
  14. Rounds metrics.Gauge
  15. // Number of validators.
  16. Validators metrics.Gauge
  17. // Total power of all validators.
  18. ValidatorsPower metrics.Gauge
  19. // Number of validators who did not sign.
  20. MissingValidators metrics.Gauge
  21. // Total power of the missing validators.
  22. MissingValidatorsPower metrics.Gauge
  23. // Number of validators who tried to double sign.
  24. ByzantineValidators metrics.Gauge
  25. // Total power of the byzantine validators.
  26. ByzantineValidatorsPower metrics.Gauge
  27. // Time between this and the last block.
  28. BlockIntervalSeconds metrics.Gauge
  29. // Number of transactions.
  30. NumTxs metrics.Gauge
  31. // Size of the block.
  32. BlockSizeBytes metrics.Gauge
  33. // Total number of transactions.
  34. TotalTxs metrics.Gauge
  35. // The latest block height.
  36. CommittedHeight metrics.Gauge
  37. // Whether or not a node is fast syncing. 1 if yes, 0 if no.
  38. FastSyncing metrics.Gauge
  39. }
  40. // PrometheusMetrics returns Metrics build using Prometheus client library.
  41. func PrometheusMetrics(namespace string) *Metrics {
  42. return &Metrics{
  43. Height: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  44. Namespace: namespace,
  45. Subsystem: MetricsSubsystem,
  46. Name: "height",
  47. Help: "Height of the chain.",
  48. }, []string{}),
  49. Rounds: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  50. Namespace: namespace,
  51. Subsystem: MetricsSubsystem,
  52. Name: "rounds",
  53. Help: "Number of rounds.",
  54. }, []string{}),
  55. Validators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  56. Namespace: namespace,
  57. Subsystem: MetricsSubsystem,
  58. Name: "validators",
  59. Help: "Number of validators.",
  60. }, []string{}),
  61. ValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  62. Namespace: namespace,
  63. Subsystem: MetricsSubsystem,
  64. Name: "validators_power",
  65. Help: "Total power of all validators.",
  66. }, []string{}),
  67. MissingValidators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  68. Namespace: namespace,
  69. Subsystem: MetricsSubsystem,
  70. Name: "missing_validators",
  71. Help: "Number of validators who did not sign.",
  72. }, []string{}),
  73. MissingValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  74. Namespace: namespace,
  75. Subsystem: MetricsSubsystem,
  76. Name: "missing_validators_power",
  77. Help: "Total power of the missing validators.",
  78. }, []string{}),
  79. ByzantineValidators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  80. Namespace: namespace,
  81. Subsystem: MetricsSubsystem,
  82. Name: "byzantine_validators",
  83. Help: "Number of validators who tried to double sign.",
  84. }, []string{}),
  85. ByzantineValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  86. Namespace: namespace,
  87. Subsystem: MetricsSubsystem,
  88. Name: "byzantine_validators_power",
  89. Help: "Total power of the byzantine validators.",
  90. }, []string{}),
  91. BlockIntervalSeconds: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  92. Namespace: namespace,
  93. Subsystem: MetricsSubsystem,
  94. Name: "block_interval_seconds",
  95. Help: "Time between this and the last block.",
  96. }, []string{}),
  97. NumTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  98. Namespace: namespace,
  99. Subsystem: MetricsSubsystem,
  100. Name: "num_txs",
  101. Help: "Number of transactions.",
  102. }, []string{}),
  103. BlockSizeBytes: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  104. Namespace: namespace,
  105. Subsystem: MetricsSubsystem,
  106. Name: "block_size_bytes",
  107. Help: "Size of the block.",
  108. }, []string{}),
  109. TotalTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  110. Namespace: namespace,
  111. Subsystem: MetricsSubsystem,
  112. Name: "total_txs",
  113. Help: "Total number of transactions.",
  114. }, []string{}),
  115. CommittedHeight: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  116. Namespace: namespace,
  117. Subsystem: MetricsSubsystem,
  118. Name: "latest_block_height",
  119. Help: "The latest block height.",
  120. }, []string{}),
  121. FastSyncing: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  122. Namespace: namespace,
  123. Subsystem: MetricsSubsystem,
  124. Name: "fast_syncing",
  125. Help: "Whether or not a node is fast syncing. 1 if yes, 0 if no.",
  126. }, []string{}),
  127. }
  128. }
  129. // NopMetrics returns no-op Metrics.
  130. func NopMetrics() *Metrics {
  131. return &Metrics{
  132. Height: discard.NewGauge(),
  133. Rounds: discard.NewGauge(),
  134. Validators: discard.NewGauge(),
  135. ValidatorsPower: discard.NewGauge(),
  136. MissingValidators: discard.NewGauge(),
  137. MissingValidatorsPower: discard.NewGauge(),
  138. ByzantineValidators: discard.NewGauge(),
  139. ByzantineValidatorsPower: discard.NewGauge(),
  140. BlockIntervalSeconds: discard.NewGauge(),
  141. NumTxs: discard.NewGauge(),
  142. BlockSizeBytes: discard.NewGauge(),
  143. TotalTxs: discard.NewGauge(),
  144. CommittedHeight: discard.NewGauge(),
  145. FastSyncing: discard.NewGauge(),
  146. }
  147. }