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.

133 lines
4.1 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. // 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.Histogram
  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.NewHistogramFrom(stdprometheus.HistogramOpts{
  79. Subsystem: "consensus",
  80. Name: "block_interval_seconds",
  81. Help: "Time between this and the last block.",
  82. Buckets: []float64{1, 2.5, 5, 10, 60},
  83. }, []string{}),
  84. NumTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  85. Subsystem: "consensus",
  86. Name: "num_txs",
  87. Help: "Number of transactions.",
  88. }, []string{}),
  89. BlockSizeBytes: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  90. Subsystem: "consensus",
  91. Name: "block_size_bytes",
  92. Help: "Size of the block.",
  93. }, []string{}),
  94. TotalTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  95. Subsystem: "consensus",
  96. Name: "total_txs",
  97. Help: "Total number of transactions.",
  98. }, []string{}),
  99. }
  100. }
  101. // NopMetrics returns no-op Metrics.
  102. func NopMetrics() *Metrics {
  103. return &Metrics{
  104. Height: discard.NewGauge(),
  105. Rounds: discard.NewGauge(),
  106. Validators: discard.NewGauge(),
  107. ValidatorsPower: discard.NewGauge(),
  108. MissingValidators: discard.NewGauge(),
  109. MissingValidatorsPower: discard.NewGauge(),
  110. ByzantineValidators: discard.NewGauge(),
  111. ByzantineValidatorsPower: discard.NewGauge(),
  112. BlockIntervalSeconds: discard.NewHistogram(),
  113. NumTxs: discard.NewGauge(),
  114. BlockSizeBytes: discard.NewGauge(),
  115. TotalTxs: discard.NewGauge(),
  116. }
  117. }