github.com/nyan233/littlerpc@v0.4.6-0.20230316182519-0c8d5c48abaf/plugins/metrics/traffic_metrics.go (about) 1 package metrics 2 3 import ( 4 "sync/atomic" 5 ) 6 7 type Gauge struct { 8 _count int64 9 _ [128 - 8]byte 10 } 11 12 func (g *Gauge) Inc() { 13 atomic.AddInt64(&g._count, 1) 14 } 15 16 func (g *Gauge) Add(v int64) { 17 atomic.AddInt64(&g._count, v) 18 } 19 20 func (g *Gauge) Set(v int64) { 21 atomic.StoreInt64(&g._count, v) 22 } 23 24 func (g *Gauge) Dec() { 25 atomic.AddInt64(&g._count, -1) 26 } 27 28 func (g *Gauge) Sub(v int64) { 29 atomic.AddInt64(&g._count, -v) 30 } 31 32 func (g *Gauge) Load() int64 { 33 return atomic.LoadInt64(&g._count) 34 } 35 36 // TrafficMetrics 用于统计流量 37 type TrafficMetrics struct { 38 Gauge 39 }