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.

71 lines
2.3 KiB

7 years ago
7 years ago
  1. package p2p
  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 MetricsSubsystem = "p2p"
  9. // Metrics contains metrics exposed by this package.
  10. type Metrics struct {
  11. // Number of peers.
  12. Peers metrics.Gauge
  13. // Number of bytes received from a given peer.
  14. PeerReceiveBytesTotal metrics.Counter
  15. // Number of bytes sent to a given peer.
  16. PeerSendBytesTotal metrics.Counter
  17. // Pending bytes to be sent to a given peer.
  18. PeerPendingSendBytes metrics.Gauge
  19. // Number of transactions submitted by each peer.
  20. NumTxs metrics.Gauge
  21. }
  22. // PrometheusMetrics returns Metrics build using Prometheus client library.
  23. func PrometheusMetrics(namespace string) *Metrics {
  24. return &Metrics{
  25. Peers: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  26. Namespace: namespace,
  27. Subsystem: MetricsSubsystem,
  28. Name: "peers",
  29. Help: "Number of peers.",
  30. }, []string{}),
  31. PeerReceiveBytesTotal: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
  32. Namespace: namespace,
  33. Subsystem: MetricsSubsystem,
  34. Name: "peer_receive_bytes_total",
  35. Help: "Number of bytes received from a given peer.",
  36. }, []string{"peer_id"}),
  37. PeerSendBytesTotal: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
  38. Namespace: namespace,
  39. Subsystem: MetricsSubsystem,
  40. Name: "peer_send_bytes_total",
  41. Help: "Number of bytes sent to a given peer.",
  42. }, []string{"peer_id"}),
  43. PeerPendingSendBytes: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  44. Namespace: namespace,
  45. Subsystem: MetricsSubsystem,
  46. Name: "peer_pending_send_bytes",
  47. Help: "Number of pending bytes to be sent to a given peer.",
  48. }, []string{"peer_id"}),
  49. NumTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  50. Namespace: namespace,
  51. Subsystem: MetricsSubsystem,
  52. Name: "num_txs",
  53. Help: "Number of transactions submitted by each peer.",
  54. }, []string{"peer_id"}),
  55. }
  56. }
  57. // NopMetrics returns no-op Metrics.
  58. func NopMetrics() *Metrics {
  59. return &Metrics{
  60. Peers: discard.NewGauge(),
  61. PeerReceiveBytesTotal: discard.NewCounter(),
  62. PeerSendBytesTotal: discard.NewCounter(),
  63. PeerPendingSendBytes: discard.NewGauge(),
  64. NumTxs: discard.NewGauge(),
  65. }
  66. }