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.

238 lines
8.4 KiB

6 years ago
6 years ago
internal/proxy: add initial set of abci metrics (#7115) This PR adds an initial set of metrics for use ABCI. The initial metrics enable the calculation of timing histograms and call counts for each of the ABCI methods. The metrics are also labeled as either 'sync' or 'async' to determine if the method call was performed using ABCI's `*Async` methods. An example of these metrics is included here for reference: ``` tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.0001"} 0 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.0004"} 5 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.002"} 12 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.009"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.02"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.1"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.65"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="2"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="6"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="25"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="+Inf"} 13 tendermint_abci_connection_method_timing_sum{chain_id="ci",method="commit",type="sync"} 0.007802058000000001 tendermint_abci_connection_method_timing_count{chain_id="ci",method="commit",type="sync"} 13 ``` These metrics can easily be graphed using prometheus's `histogram_quantile(...)` method to pick out a particular quantile to graph or examine. I chose buckets that were somewhat of an estimate of expected range of times for ABCI operations. They start at .0001 seconds and range to 25 seconds. The hope is that this range captures enough possible times to be useful for us and operators.
3 years ago
internal/proxy: add initial set of abci metrics (#7115) This PR adds an initial set of metrics for use ABCI. The initial metrics enable the calculation of timing histograms and call counts for each of the ABCI methods. The metrics are also labeled as either 'sync' or 'async' to determine if the method call was performed using ABCI's `*Async` methods. An example of these metrics is included here for reference: ``` tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.0001"} 0 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.0004"} 5 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.002"} 12 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.009"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.02"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.1"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.65"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="2"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="6"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="25"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="+Inf"} 13 tendermint_abci_connection_method_timing_sum{chain_id="ci",method="commit",type="sync"} 0.007802058000000001 tendermint_abci_connection_method_timing_count{chain_id="ci",method="commit",type="sync"} 13 ``` These metrics can easily be graphed using prometheus's `histogram_quantile(...)` method to pick out a particular quantile to graph or examine. I chose buckets that were somewhat of an estimate of expected range of times for ABCI operations. They start at .0001 seconds and range to 25 seconds. The hope is that this range captures enough possible times to be useful for us and operators.
3 years ago
  1. package consensus
  2. import (
  3. "github.com/go-kit/kit/metrics"
  4. "github.com/go-kit/kit/metrics/discard"
  5. "github.com/tendermint/tendermint/types"
  6. prometheus "github.com/go-kit/kit/metrics/prometheus"
  7. stdprometheus "github.com/prometheus/client_golang/prometheus"
  8. )
  9. const (
  10. // MetricsSubsystem is a subsystem shared by all metrics exposed by this
  11. // package.
  12. MetricsSubsystem = "consensus"
  13. )
  14. // Metrics contains metrics exposed by this package.
  15. type Metrics struct {
  16. // Height of the chain.
  17. Height metrics.Gauge
  18. // ValidatorLastSignedHeight of a validator.
  19. ValidatorLastSignedHeight metrics.Gauge
  20. // Number of rounds.
  21. Rounds metrics.Gauge
  22. // Number of validators.
  23. Validators metrics.Gauge
  24. // Total power of all validators.
  25. ValidatorsPower metrics.Gauge
  26. // Power of a validator.
  27. ValidatorPower metrics.Gauge
  28. // Amount of blocks missed by a validator.
  29. ValidatorMissedBlocks metrics.Gauge
  30. // Number of validators who did not sign.
  31. MissingValidators metrics.Gauge
  32. // Total power of the missing validators.
  33. MissingValidatorsPower metrics.Gauge
  34. // Number of validators who tried to double sign.
  35. ByzantineValidators metrics.Gauge
  36. // Total power of the byzantine validators.
  37. ByzantineValidatorsPower metrics.Gauge
  38. // Time between this and the last block.
  39. BlockIntervalSeconds metrics.Histogram
  40. // Number of transactions.
  41. NumTxs metrics.Gauge
  42. // Size of the block.
  43. BlockSizeBytes metrics.Histogram
  44. // Total number of transactions.
  45. TotalTxs metrics.Gauge
  46. // The latest block height.
  47. CommittedHeight metrics.Gauge
  48. // Whether or not a node is block syncing. 1 if yes, 0 if no.
  49. BlockSyncing metrics.Gauge
  50. // Whether or not a node is state syncing. 1 if yes, 0 if no.
  51. StateSyncing metrics.Gauge
  52. // Number of blockparts transmitted by peer.
  53. BlockParts metrics.Counter
  54. // Histogram of time taken per step annotated with reason that the step proceeded.
  55. StepTime metrics.Histogram
  56. }
  57. // PrometheusMetrics returns Metrics build using Prometheus client library.
  58. // Optionally, labels can be provided along with their values ("foo",
  59. // "fooValue").
  60. func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics {
  61. labels := []string{}
  62. for i := 0; i < len(labelsAndValues); i += 2 {
  63. labels = append(labels, labelsAndValues[i])
  64. }
  65. return &Metrics{
  66. Height: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  67. Namespace: namespace,
  68. Subsystem: MetricsSubsystem,
  69. Name: "height",
  70. Help: "Height of the chain.",
  71. }, labels).With(labelsAndValues...),
  72. Rounds: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  73. Namespace: namespace,
  74. Subsystem: MetricsSubsystem,
  75. Name: "rounds",
  76. Help: "Number of rounds.",
  77. }, labels).With(labelsAndValues...),
  78. Validators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  79. Namespace: namespace,
  80. Subsystem: MetricsSubsystem,
  81. Name: "validators",
  82. Help: "Number of validators.",
  83. }, labels).With(labelsAndValues...),
  84. ValidatorLastSignedHeight: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  85. Namespace: namespace,
  86. Subsystem: MetricsSubsystem,
  87. Name: "validator_last_signed_height",
  88. Help: "Last signed height for a validator",
  89. }, append(labels, "validator_address")).With(labelsAndValues...),
  90. ValidatorMissedBlocks: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  91. Namespace: namespace,
  92. Subsystem: MetricsSubsystem,
  93. Name: "validator_missed_blocks",
  94. Help: "Total missed blocks for a validator",
  95. }, append(labels, "validator_address")).With(labelsAndValues...),
  96. ValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  97. Namespace: namespace,
  98. Subsystem: MetricsSubsystem,
  99. Name: "validators_power",
  100. Help: "Total power of all validators.",
  101. }, labels).With(labelsAndValues...),
  102. ValidatorPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  103. Namespace: namespace,
  104. Subsystem: MetricsSubsystem,
  105. Name: "validator_power",
  106. Help: "Power of a validator",
  107. }, append(labels, "validator_address")).With(labelsAndValues...),
  108. MissingValidators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  109. Namespace: namespace,
  110. Subsystem: MetricsSubsystem,
  111. Name: "missing_validators",
  112. Help: "Number of validators who did not sign.",
  113. }, labels).With(labelsAndValues...),
  114. MissingValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  115. Namespace: namespace,
  116. Subsystem: MetricsSubsystem,
  117. Name: "missing_validators_power",
  118. Help: "Total power of the missing validators.",
  119. }, labels).With(labelsAndValues...),
  120. ByzantineValidators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  121. Namespace: namespace,
  122. Subsystem: MetricsSubsystem,
  123. Name: "byzantine_validators",
  124. Help: "Number of validators who tried to double sign.",
  125. }, labels).With(labelsAndValues...),
  126. ByzantineValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  127. Namespace: namespace,
  128. Subsystem: MetricsSubsystem,
  129. Name: "byzantine_validators_power",
  130. Help: "Total power of the byzantine validators.",
  131. }, labels).With(labelsAndValues...),
  132. BlockIntervalSeconds: prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{
  133. Namespace: namespace,
  134. Subsystem: MetricsSubsystem,
  135. Name: "block_interval_seconds",
  136. Help: "Time between this and the last block.",
  137. }, labels).With(labelsAndValues...),
  138. NumTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  139. Namespace: namespace,
  140. Subsystem: MetricsSubsystem,
  141. Name: "num_txs",
  142. Help: "Number of transactions.",
  143. }, labels).With(labelsAndValues...),
  144. BlockSizeBytes: prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{
  145. Namespace: namespace,
  146. Subsystem: MetricsSubsystem,
  147. Name: "block_size_bytes",
  148. Help: "Size of the block.",
  149. }, labels).With(labelsAndValues...),
  150. TotalTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  151. Namespace: namespace,
  152. Subsystem: MetricsSubsystem,
  153. Name: "total_txs",
  154. Help: "Total number of transactions.",
  155. }, labels).With(labelsAndValues...),
  156. CommittedHeight: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  157. Namespace: namespace,
  158. Subsystem: MetricsSubsystem,
  159. Name: "latest_block_height",
  160. Help: "The latest block height.",
  161. }, labels).With(labelsAndValues...),
  162. BlockSyncing: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  163. Namespace: namespace,
  164. Subsystem: MetricsSubsystem,
  165. Name: "block_syncing",
  166. Help: "Whether or not a node is block syncing. 1 if yes, 0 if no.",
  167. }, labels).With(labelsAndValues...),
  168. StateSyncing: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  169. Namespace: namespace,
  170. Subsystem: MetricsSubsystem,
  171. Name: "state_syncing",
  172. Help: "Whether or not a node is state syncing. 1 if yes, 0 if no.",
  173. }, labels).With(labelsAndValues...),
  174. BlockParts: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
  175. Namespace: namespace,
  176. Subsystem: MetricsSubsystem,
  177. Name: "block_parts",
  178. Help: "Number of blockparts transmitted by peer.",
  179. }, append(labels, "peer_id")).With(labelsAndValues...),
  180. StepTime: prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{
  181. Namespace: namespace,
  182. Subsystem: MetricsSubsystem,
  183. Name: "step_time",
  184. Help: "Time spent per step.",
  185. }, append(labels, "step", "reason")).With(labelsAndValues...),
  186. }
  187. }
  188. // NopMetrics returns no-op Metrics.
  189. func NopMetrics() *Metrics {
  190. return &Metrics{
  191. Height: discard.NewGauge(),
  192. ValidatorLastSignedHeight: discard.NewGauge(),
  193. Rounds: discard.NewGauge(),
  194. Validators: discard.NewGauge(),
  195. ValidatorsPower: discard.NewGauge(),
  196. ValidatorPower: discard.NewGauge(),
  197. ValidatorMissedBlocks: discard.NewGauge(),
  198. MissingValidators: discard.NewGauge(),
  199. MissingValidatorsPower: discard.NewGauge(),
  200. ByzantineValidators: discard.NewGauge(),
  201. ByzantineValidatorsPower: discard.NewGauge(),
  202. BlockIntervalSeconds: discard.NewHistogram(),
  203. NumTxs: discard.NewGauge(),
  204. BlockSizeBytes: discard.NewHistogram(),
  205. TotalTxs: discard.NewGauge(),
  206. CommittedHeight: discard.NewGauge(),
  207. BlockSyncing: discard.NewGauge(),
  208. StateSyncing: discard.NewGauge(),
  209. BlockParts: discard.NewCounter(),
  210. }
  211. }
  212. // RecordConsMetrics uses for recording the block related metrics during fast-sync.
  213. func (m *Metrics) RecordConsMetrics(block *types.Block) {
  214. m.NumTxs.Set(float64(len(block.Data.Txs)))
  215. m.TotalTxs.Add(float64(len(block.Data.Txs)))
  216. m.BlockSizeBytes.Observe(float64(block.Size()))
  217. m.CommittedHeight.Set(float64(block.Height))
  218. }