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.

132 lines
4.0 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. // Metrics contains metrics exposed by this package.
  9. type Metrics struct {
  10. // Height of the chain.
  11. Height metrics.Gauge
  12. // Number of rounds.
  13. Rounds metrics.Gauge
  14. // Number of validators.
  15. Validators metrics.Gauge
  16. // Total power of all validators.
  17. ValidatorsPower metrics.Gauge
  18. // Number of validators who did not sign.
  19. MissingValidators metrics.Gauge
  20. // Total power of the missing validators.
  21. MissingValidatorsPower metrics.Gauge
  22. // Number of validators who tried to double sign.
  23. ByzantineValidators metrics.Gauge
  24. // Total power of the byzantine validators.
  25. ByzantineValidatorsPower metrics.Gauge
  26. // Time between this and the last block.
  27. BlockIntervalSeconds metrics.Gauge
  28. // Number of transactions.
  29. NumTxs metrics.Gauge
  30. // Size of the block.
  31. BlockSizeBytes metrics.Gauge
  32. // Total number of transactions.
  33. TotalTxs metrics.Gauge
  34. }
  35. // PrometheusMetrics returns Metrics build using Prometheus client library.
  36. func PrometheusMetrics() *Metrics {
  37. return &Metrics{
  38. Height: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  39. Subsystem: "consensus",
  40. Name: "height",
  41. Help: "Height of the chain.",
  42. }, []string{}),
  43. Rounds: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  44. Subsystem: "consensus",
  45. Name: "rounds",
  46. Help: "Number of rounds.",
  47. }, []string{}),
  48. Validators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  49. Subsystem: "consensus",
  50. Name: "validators",
  51. Help: "Number of validators.",
  52. }, []string{}),
  53. ValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  54. Subsystem: "consensus",
  55. Name: "validators_power",
  56. Help: "Total power of all validators.",
  57. }, []string{}),
  58. MissingValidators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  59. Subsystem: "consensus",
  60. Name: "missing_validators",
  61. Help: "Number of validators who did not sign.",
  62. }, []string{}),
  63. MissingValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  64. Subsystem: "consensus",
  65. Name: "missing_validators_power",
  66. Help: "Total power of the missing validators.",
  67. }, []string{}),
  68. ByzantineValidators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  69. Subsystem: "consensus",
  70. Name: "byzantine_validators",
  71. Help: "Number of validators who tried to double sign.",
  72. }, []string{}),
  73. ByzantineValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  74. Subsystem: "consensus",
  75. Name: "byzantine_validators_power",
  76. Help: "Total power of the byzantine validators.",
  77. }, []string{}),
  78. BlockIntervalSeconds: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  79. Subsystem: "consensus",
  80. Name: "block_interval_seconds",
  81. Help: "Time between this and the last block.",
  82. }, []string{}),
  83. NumTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  84. Subsystem: "consensus",
  85. Name: "num_txs",
  86. Help: "Number of transactions.",
  87. }, []string{}),
  88. BlockSizeBytes: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  89. Subsystem: "consensus",
  90. Name: "block_size_bytes",
  91. Help: "Size of the block.",
  92. }, []string{}),
  93. TotalTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  94. Subsystem: "consensus",
  95. Name: "total_txs",
  96. Help: "Total number of transactions.",
  97. }, []string{}),
  98. }
  99. }
  100. // NopMetrics returns no-op Metrics.
  101. func NopMetrics() *Metrics {
  102. return &Metrics{
  103. Height: discard.NewGauge(),
  104. Rounds: discard.NewGauge(),
  105. Validators: discard.NewGauge(),
  106. ValidatorsPower: discard.NewGauge(),
  107. MissingValidators: discard.NewGauge(),
  108. MissingValidatorsPower: discard.NewGauge(),
  109. ByzantineValidators: discard.NewGauge(),
  110. ByzantineValidatorsPower: discard.NewGauge(),
  111. BlockIntervalSeconds: discard.NewGauge(),
  112. NumTxs: discard.NewGauge(),
  113. BlockSizeBytes: discard.NewGauge(),
  114. TotalTxs: discard.NewGauge(),
  115. }
  116. }