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.

64 lines
2.0 KiB

7 years ago
7 years ago
  1. package mempool
  2. import (
  3. "github.com/go-kit/kit/metrics"
  4. "github.com/go-kit/kit/metrics/discard"
  5. "github.com/go-kit/kit/metrics/prometheus"
  6. stdprometheus "github.com/prometheus/client_golang/prometheus"
  7. )
  8. const MetricsSubsytem = "mempool"
  9. // Metrics contains metrics exposed by this package.
  10. // see MetricsProvider for descriptions.
  11. type Metrics struct {
  12. // Size of the mempool.
  13. Size metrics.Gauge
  14. // Histogram of transaction sizes, in bytes.
  15. TxSizeBytes metrics.Histogram
  16. // Number of failed transactions.
  17. FailedTxs metrics.Counter
  18. // Number of times transactions are rechecked in the mempool.
  19. RecheckTimes metrics.Counter
  20. }
  21. // PrometheusMetrics returns Metrics build using Prometheus client library.
  22. func PrometheusMetrics(namespace string) *Metrics {
  23. return &Metrics{
  24. Size: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  25. Namespace: namespace,
  26. Subsystem: MetricsSubsytem,
  27. Name: "size",
  28. Help: "Size of the mempool (number of uncommitted transactions).",
  29. }, []string{}),
  30. TxSizeBytes: prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{
  31. Namespace: namespace,
  32. Subsystem: MetricsSubsytem,
  33. Name: "tx_size_bytes",
  34. Help: "Transaction sizes in bytes.",
  35. Buckets: stdprometheus.ExponentialBuckets(1, 3, 17),
  36. }, []string{}),
  37. FailedTxs: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
  38. Namespace: namespace,
  39. Subsystem: MetricsSubsytem,
  40. Name: "failed_txs",
  41. Help: "Number of failed transactions.",
  42. }, []string{}),
  43. RecheckTimes: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
  44. Namespace: namespace,
  45. Subsystem: MetricsSubsytem,
  46. Name: "recheck_times",
  47. Help: "Number of times transactions are rechecked in the mempool.",
  48. }, []string{}),
  49. }
  50. }
  51. // NopMetrics returns no-op Metrics.
  52. func NopMetrics() *Metrics {
  53. return &Metrics{
  54. Size: discard.NewGauge(),
  55. TxSizeBytes: discard.NewHistogram(),
  56. FailedTxs: discard.NewCounter(),
  57. RecheckTimes: discard.NewCounter(),
  58. }
  59. }