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.

174 lines
5.5 KiB

7 years ago
7 years ago
7 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. // Number of blockparts transmitted by peer.
  40. BlockParts metrics.Counter
  41. }
  42. // PrometheusMetrics returns Metrics build using Prometheus client library.
  43. func PrometheusMetrics(namespace string) *Metrics {
  44. return &Metrics{
  45. Height: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  46. Namespace: namespace,
  47. Subsystem: MetricsSubsystem,
  48. Name: "height",
  49. Help: "Height of the chain.",
  50. }, []string{}),
  51. Rounds: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  52. Namespace: namespace,
  53. Subsystem: MetricsSubsystem,
  54. Name: "rounds",
  55. Help: "Number of rounds.",
  56. }, []string{}),
  57. Validators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  58. Namespace: namespace,
  59. Subsystem: MetricsSubsystem,
  60. Name: "validators",
  61. Help: "Number of validators.",
  62. }, []string{}),
  63. ValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  64. Namespace: namespace,
  65. Subsystem: MetricsSubsystem,
  66. Name: "validators_power",
  67. Help: "Total power of all validators.",
  68. }, []string{}),
  69. MissingValidators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  70. Namespace: namespace,
  71. Subsystem: MetricsSubsystem,
  72. Name: "missing_validators",
  73. Help: "Number of validators who did not sign.",
  74. }, []string{}),
  75. MissingValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  76. Namespace: namespace,
  77. Subsystem: MetricsSubsystem,
  78. Name: "missing_validators_power",
  79. Help: "Total power of the missing validators.",
  80. }, []string{}),
  81. ByzantineValidators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  82. Namespace: namespace,
  83. Subsystem: MetricsSubsystem,
  84. Name: "byzantine_validators",
  85. Help: "Number of validators who tried to double sign.",
  86. }, []string{}),
  87. ByzantineValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  88. Namespace: namespace,
  89. Subsystem: MetricsSubsystem,
  90. Name: "byzantine_validators_power",
  91. Help: "Total power of the byzantine validators.",
  92. }, []string{}),
  93. BlockIntervalSeconds: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  94. Namespace: namespace,
  95. Subsystem: MetricsSubsystem,
  96. Name: "block_interval_seconds",
  97. Help: "Time between this and the last block.",
  98. }, []string{}),
  99. NumTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  100. Namespace: namespace,
  101. Subsystem: MetricsSubsystem,
  102. Name: "num_txs",
  103. Help: "Number of transactions.",
  104. }, []string{}),
  105. BlockSizeBytes: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  106. Namespace: namespace,
  107. Subsystem: MetricsSubsystem,
  108. Name: "block_size_bytes",
  109. Help: "Size of the block.",
  110. }, []string{}),
  111. TotalTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  112. Namespace: namespace,
  113. Subsystem: MetricsSubsystem,
  114. Name: "total_txs",
  115. Help: "Total number of transactions.",
  116. }, []string{}),
  117. CommittedHeight: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  118. Namespace: namespace,
  119. Subsystem: MetricsSubsystem,
  120. Name: "latest_block_height",
  121. Help: "The latest block height.",
  122. }, []string{}),
  123. FastSyncing: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  124. Namespace: namespace,
  125. Subsystem: MetricsSubsystem,
  126. Name: "fast_syncing",
  127. Help: "Whether or not a node is fast syncing. 1 if yes, 0 if no.",
  128. }, []string{}),
  129. BlockParts: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
  130. Namespace: namespace,
  131. Subsystem: MetricsSubsystem,
  132. Name: "block_parts",
  133. Help: "Number of blockparts transmitted by peer.",
  134. }, []string{"peer_id"}),
  135. }
  136. }
  137. // NopMetrics returns no-op Metrics.
  138. func NopMetrics() *Metrics {
  139. return &Metrics{
  140. Height: discard.NewGauge(),
  141. Rounds: discard.NewGauge(),
  142. Validators: discard.NewGauge(),
  143. ValidatorsPower: discard.NewGauge(),
  144. MissingValidators: discard.NewGauge(),
  145. MissingValidatorsPower: discard.NewGauge(),
  146. ByzantineValidators: discard.NewGauge(),
  147. ByzantineValidatorsPower: discard.NewGauge(),
  148. BlockIntervalSeconds: discard.NewGauge(),
  149. NumTxs: discard.NewGauge(),
  150. BlockSizeBytes: discard.NewGauge(),
  151. TotalTxs: discard.NewGauge(),
  152. CommittedHeight: discard.NewGauge(),
  153. FastSyncing: discard.NewGauge(),
  154. BlockParts: discard.NewCounter(),
  155. }
  156. }