github.com/nyan233/littlerpc@v0.4.6-0.20230316182519-0c8d5c48abaf/plugins/metrics/call_metrics.go (about)

     1  package metrics
     2  
     3  import "sync/atomic"
     4  
     5  type CallMetrics struct {
     6  	// 用于即未成功也未失败的计数, 可能由阻塞等原因引起
     7  	Count    int64
     8  	Complete int64
     9  	Failed   int64
    10  }
    11  
    12  func (m *CallMetrics) IncComplete() {
    13  	atomic.AddInt64(&m.Complete, 1)
    14  }
    15  
    16  func (m *CallMetrics) IncFailed() {
    17  	atomic.AddInt64(&m.Failed, 1)
    18  }
    19  
    20  func (m *CallMetrics) IncCount() {
    21  	atomic.AddInt64(&m.Count, 1)
    22  }
    23  
    24  func (m *CallMetrics) LoadComplete() int64 {
    25  	return atomic.LoadInt64(&m.Complete)
    26  }
    27  
    28  func (m *CallMetrics) LoadFailed() int64 {
    29  	return atomic.LoadInt64(&m.Failed)
    30  }
    31  
    32  func (m *CallMetrics) LoadCount() int64 {
    33  	return atomic.LoadInt64(&m.Count)
    34  }
    35  
    36  func (m *CallMetrics) LoadAll() int64 {
    37  	return m.LoadComplete() + m.LoadFailed()
    38  }