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.

62 lines
2.0 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. prometheus "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. }
  20. // PrometheusMetrics returns Metrics build using Prometheus client library.
  21. func PrometheusMetrics(namespace string) *Metrics {
  22. return &Metrics{
  23. Peers: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  24. Namespace: namespace,
  25. Subsystem: MetricsSubsystem,
  26. Name: "peers",
  27. Help: "Number of peers.",
  28. }, []string{}),
  29. PeerReceiveBytesTotal: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
  30. Namespace: namespace,
  31. Subsystem: MetricsSubsystem,
  32. Name: "peer_receive_bytes_total",
  33. Help: "Number of bytes received from a given peer.",
  34. }, []string{"peer_id"}),
  35. PeerSendBytesTotal: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
  36. Namespace: namespace,
  37. Subsystem: MetricsSubsystem,
  38. Name: "peer_send_bytes_total",
  39. Help: "Number of bytes sent to a given peer.",
  40. }, []string{"peer_id"}),
  41. PeerPendingSendBytes: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  42. Namespace: namespace,
  43. Subsystem: MetricsSubsystem,
  44. Name: "peer_pending_send_bytes",
  45. Help: "Number of pending bytes to be sent to a given peer.",
  46. }, []string{"peer_id"}),
  47. }
  48. }
  49. // NopMetrics returns no-op Metrics.
  50. func NopMetrics() *Metrics {
  51. return &Metrics{
  52. Peers: discard.NewGauge(),
  53. PeerReceiveBytesTotal: discard.NewCounter(),
  54. PeerSendBytesTotal: discard.NewCounter(),
  55. PeerPendingSendBytes: discard.NewGauge(),
  56. }
  57. }