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.

213 lines
7.3 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 (
  9. // MetricsSubsystem is a subsystem shared by all metrics exposed by this
  10. // package.
  11. MetricsSubsystem = "consensus"
  12. )
  13. // Metrics contains metrics exposed by this package.
  14. type Metrics struct {
  15. // Height of the chain.
  16. Height metrics.Gauge
  17. // ValidatorLastSignedHeight of a validator.
  18. ValidatorLastSignedHeight metrics.Gauge
  19. // Number of rounds.
  20. Rounds metrics.Gauge
  21. // Number of validators.
  22. Validators metrics.Gauge
  23. // Total power of all validators.
  24. ValidatorsPower metrics.Gauge
  25. // Power of a validator.
  26. ValidatorPower metrics.Gauge
  27. // Amount of blocks missed by a validator.
  28. ValidatorMissedBlocks metrics.Gauge
  29. // Number of validators who did not sign.
  30. MissingValidators metrics.Gauge
  31. // Total power of the missing validators.
  32. MissingValidatorsPower metrics.Gauge
  33. // Number of validators who tried to double sign.
  34. ByzantineValidators metrics.Gauge
  35. // Total power of the byzantine validators.
  36. ByzantineValidatorsPower metrics.Gauge
  37. // Time between this and the last block.
  38. BlockIntervalSeconds metrics.Gauge
  39. // Number of transactions.
  40. NumTxs metrics.Gauge
  41. // Size of the block.
  42. BlockSizeBytes metrics.Gauge
  43. // Total number of transactions.
  44. TotalTxs metrics.Gauge
  45. // The latest block height.
  46. CommittedHeight metrics.Gauge
  47. // Whether or not a node is fast syncing. 1 if yes, 0 if no.
  48. FastSyncing metrics.Gauge
  49. // Number of blockparts transmitted by peer.
  50. BlockParts metrics.Counter
  51. }
  52. // PrometheusMetrics returns Metrics build using Prometheus client library.
  53. // Optionally, labels can be provided along with their values ("foo",
  54. // "fooValue").
  55. func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics {
  56. labels := []string{}
  57. for i := 0; i < len(labelsAndValues); i += 2 {
  58. labels = append(labels, labelsAndValues[i])
  59. }
  60. return &Metrics{
  61. Height: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  62. Namespace: namespace,
  63. Subsystem: MetricsSubsystem,
  64. Name: "height",
  65. Help: "Height of the chain.",
  66. }, labels).With(labelsAndValues...),
  67. Rounds: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  68. Namespace: namespace,
  69. Subsystem: MetricsSubsystem,
  70. Name: "rounds",
  71. Help: "Number of rounds.",
  72. }, labels).With(labelsAndValues...),
  73. Validators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  74. Namespace: namespace,
  75. Subsystem: MetricsSubsystem,
  76. Name: "validators",
  77. Help: "Number of validators.",
  78. }, labels).With(labelsAndValues...),
  79. ValidatorLastSignedHeight: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  80. Namespace: namespace,
  81. Subsystem: MetricsSubsystem,
  82. Name: "validator_last_signed_height",
  83. Help: "Last signed height for a validator",
  84. }, append(labels, "validator_address")).With(labelsAndValues...),
  85. ValidatorMissedBlocks: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  86. Namespace: namespace,
  87. Subsystem: MetricsSubsystem,
  88. Name: "validator_missed_blocks",
  89. Help: "Total missed blocks for a validator",
  90. }, append(labels, "validator_address")).With(labelsAndValues...),
  91. ValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  92. Namespace: namespace,
  93. Subsystem: MetricsSubsystem,
  94. Name: "validators_power",
  95. Help: "Total power of all validators.",
  96. }, labels).With(labelsAndValues...),
  97. ValidatorPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  98. Namespace: namespace,
  99. Subsystem: MetricsSubsystem,
  100. Name: "validator_power",
  101. Help: "Power of a validator",
  102. }, append(labels, "validator_address")).With(labelsAndValues...),
  103. MissingValidators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  104. Namespace: namespace,
  105. Subsystem: MetricsSubsystem,
  106. Name: "missing_validators",
  107. Help: "Number of validators who did not sign.",
  108. }, labels).With(labelsAndValues...),
  109. MissingValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  110. Namespace: namespace,
  111. Subsystem: MetricsSubsystem,
  112. Name: "missing_validators_power",
  113. Help: "Total power of the missing validators.",
  114. }, labels).With(labelsAndValues...),
  115. ByzantineValidators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  116. Namespace: namespace,
  117. Subsystem: MetricsSubsystem,
  118. Name: "byzantine_validators",
  119. Help: "Number of validators who tried to double sign.",
  120. }, labels).With(labelsAndValues...),
  121. ByzantineValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  122. Namespace: namespace,
  123. Subsystem: MetricsSubsystem,
  124. Name: "byzantine_validators_power",
  125. Help: "Total power of the byzantine validators.",
  126. }, labels).With(labelsAndValues...),
  127. BlockIntervalSeconds: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  128. Namespace: namespace,
  129. Subsystem: MetricsSubsystem,
  130. Name: "block_interval_seconds",
  131. Help: "Time between this and the last block.",
  132. }, labels).With(labelsAndValues...),
  133. NumTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  134. Namespace: namespace,
  135. Subsystem: MetricsSubsystem,
  136. Name: "num_txs",
  137. Help: "Number of transactions.",
  138. }, labels).With(labelsAndValues...),
  139. BlockSizeBytes: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  140. Namespace: namespace,
  141. Subsystem: MetricsSubsystem,
  142. Name: "block_size_bytes",
  143. Help: "Size of the block.",
  144. }, labels).With(labelsAndValues...),
  145. TotalTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  146. Namespace: namespace,
  147. Subsystem: MetricsSubsystem,
  148. Name: "total_txs",
  149. Help: "Total number of transactions.",
  150. }, labels).With(labelsAndValues...),
  151. CommittedHeight: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  152. Namespace: namespace,
  153. Subsystem: MetricsSubsystem,
  154. Name: "latest_block_height",
  155. Help: "The latest block height.",
  156. }, labels).With(labelsAndValues...),
  157. FastSyncing: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  158. Namespace: namespace,
  159. Subsystem: MetricsSubsystem,
  160. Name: "fast_syncing",
  161. Help: "Whether or not a node is fast syncing. 1 if yes, 0 if no.",
  162. }, labels).With(labelsAndValues...),
  163. BlockParts: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
  164. Namespace: namespace,
  165. Subsystem: MetricsSubsystem,
  166. Name: "block_parts",
  167. Help: "Number of blockparts transmitted by peer.",
  168. }, append(labels, "peer_id")).With(labelsAndValues...),
  169. }
  170. }
  171. // NopMetrics returns no-op Metrics.
  172. func NopMetrics() *Metrics {
  173. return &Metrics{
  174. Height: discard.NewGauge(),
  175. ValidatorLastSignedHeight: discard.NewGauge(),
  176. Rounds: discard.NewGauge(),
  177. Validators: discard.NewGauge(),
  178. ValidatorsPower: discard.NewGauge(),
  179. ValidatorPower: discard.NewGauge(),
  180. ValidatorMissedBlocks: discard.NewGauge(),
  181. MissingValidators: discard.NewGauge(),
  182. MissingValidatorsPower: discard.NewGauge(),
  183. ByzantineValidators: discard.NewGauge(),
  184. ByzantineValidatorsPower: discard.NewGauge(),
  185. BlockIntervalSeconds: discard.NewGauge(),
  186. NumTxs: discard.NewGauge(),
  187. BlockSizeBytes: discard.NewGauge(),
  188. TotalTxs: discard.NewGauge(),
  189. CommittedHeight: discard.NewGauge(),
  190. FastSyncing: discard.NewGauge(),
  191. BlockParts: discard.NewCounter(),
  192. }
  193. }