github.com/koko1123/flow-go-1@v0.29.6/module/metrics/bitswap.go (about)

     1  package metrics
     2  
     3  import (
     4  	"github.com/prometheus/client_golang/prometheus"
     5  	"github.com/prometheus/client_golang/prometheus/promauto"
     6  )
     7  
     8  type BitswapCollector struct {
     9  	peers            *prometheus.GaugeVec
    10  	wantlist         *prometheus.GaugeVec
    11  	blobsReceived    *prometheus.GaugeVec
    12  	dataReceived     *prometheus.GaugeVec
    13  	blobsSent        *prometheus.GaugeVec
    14  	dataSent         *prometheus.GaugeVec
    15  	dupBlobsReceived *prometheus.GaugeVec
    16  	dupDataReceived  *prometheus.GaugeVec
    17  	messagesReceived *prometheus.GaugeVec
    18  }
    19  
    20  func NewBitswapCollector() *BitswapCollector {
    21  	bc := &BitswapCollector{
    22  		peers: promauto.NewGaugeVec(prometheus.GaugeOpts{
    23  			Name:      "num_peers",
    24  			Namespace: namespaceNetwork,
    25  			Subsystem: subsystemBitswap,
    26  			Help:      "the number of connected peers",
    27  		}, []string{"prefix"}),
    28  		wantlist: promauto.NewGaugeVec(prometheus.GaugeOpts{
    29  			Name:      "wantlist_size",
    30  			Namespace: namespaceNetwork,
    31  			Subsystem: subsystemBitswap,
    32  			Help:      "the wantlist size",
    33  		}, []string{"prefix"}),
    34  		blobsReceived: promauto.NewGaugeVec(prometheus.GaugeOpts{
    35  			Name:      "blobs_received",
    36  			Namespace: namespaceNetwork,
    37  			Subsystem: subsystemBitswap,
    38  			Help:      "the number of received blobs",
    39  		}, []string{"prefix"}),
    40  		dataReceived: promauto.NewGaugeVec(prometheus.GaugeOpts{
    41  			Name:      "data_received",
    42  			Namespace: namespaceNetwork,
    43  			Subsystem: subsystemBitswap,
    44  			Help:      "the amount of data received",
    45  		}, []string{"prefix"}),
    46  		blobsSent: promauto.NewGaugeVec(prometheus.GaugeOpts{
    47  			Name:      "blobs_sent",
    48  			Namespace: namespaceNetwork,
    49  			Subsystem: subsystemBitswap,
    50  			Help:      "the number of sent blobs",
    51  		}, []string{"prefix"}),
    52  		dataSent: promauto.NewGaugeVec(prometheus.GaugeOpts{
    53  			Name:      "data_sent",
    54  			Namespace: namespaceNetwork,
    55  			Subsystem: subsystemBitswap,
    56  			Help:      "the amount of data sent",
    57  		}, []string{"prefix"}),
    58  		dupBlobsReceived: promauto.NewGaugeVec(prometheus.GaugeOpts{
    59  			Name:      "dup_blobs_received",
    60  			Namespace: namespaceNetwork,
    61  			Subsystem: subsystemBitswap,
    62  			Help:      "the number of duplicate blobs received",
    63  		}, []string{"prefix"}),
    64  		dupDataReceived: promauto.NewGaugeVec(prometheus.GaugeOpts{
    65  			Name:      "dup_data_received",
    66  			Namespace: namespaceNetwork,
    67  			Subsystem: subsystemBitswap,
    68  			Help:      "the amount of duplicate data received",
    69  		}, []string{"prefix"}),
    70  		messagesReceived: promauto.NewGaugeVec(prometheus.GaugeOpts{
    71  			Name:      "messages_received",
    72  			Namespace: namespaceNetwork,
    73  			Subsystem: subsystemBitswap,
    74  			Help:      "the number of messages received",
    75  		}, []string{"prefix"}),
    76  	}
    77  
    78  	return bc
    79  }
    80  
    81  func (bc *BitswapCollector) Peers(prefix string, n int) {
    82  	bc.peers.WithLabelValues(prefix).Set(float64(n))
    83  }
    84  
    85  func (bc *BitswapCollector) Wantlist(prefix string, n int) {
    86  	bc.wantlist.WithLabelValues(prefix).Set(float64(n))
    87  }
    88  
    89  func (bc *BitswapCollector) BlobsReceived(prefix string, n uint64) {
    90  	bc.blobsReceived.WithLabelValues(prefix).Set(float64(n))
    91  }
    92  
    93  func (bc *BitswapCollector) DataReceived(prefix string, n uint64) {
    94  	bc.dataReceived.WithLabelValues(prefix).Set(float64(n))
    95  }
    96  
    97  func (bc *BitswapCollector) BlobsSent(prefix string, n uint64) {
    98  	bc.blobsSent.WithLabelValues(prefix).Set(float64(n))
    99  }
   100  
   101  func (bc *BitswapCollector) DataSent(prefix string, n uint64) {
   102  	bc.dataSent.WithLabelValues(prefix).Set(float64(n))
   103  }
   104  
   105  func (bc *BitswapCollector) DupBlobsReceived(prefix string, n uint64) {
   106  	bc.dupBlobsReceived.WithLabelValues(prefix).Set(float64(n))
   107  }
   108  
   109  func (bc *BitswapCollector) DupDataReceived(prefix string, n uint64) {
   110  	bc.dupDataReceived.WithLabelValues(prefix).Set(float64(n))
   111  }
   112  
   113  func (bc *BitswapCollector) MessagesReceived(prefix string, n uint64) {
   114  	bc.messagesReceived.WithLabelValues(prefix).Set(float64(n))
   115  }