Changeset 709 in code
- Timestamp:
- Nov 17, 2021, 2:58:19 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server.go
r708 r709 57 57 } 58 58 59 type int64Gauge struct { 60 v int64 // atomic 61 } 62 63 func (g *int64Gauge) Add(delta int64) { 64 atomic.AddInt64(&g.v, delta) 65 } 66 67 func (g *int64Gauge) Value() int64 { 68 return atomic.LoadInt64(&g.v) 69 } 70 71 func (g *int64Gauge) Float64() float64 { 72 return float64(g.Value()) 73 } 74 59 75 type Config struct { 60 76 Hostname string … … 75 91 MetricsRegistry prometheus.Registerer // can be nil 76 92 77 config atomic.Value // *Config 78 db Database 79 stopWG sync.WaitGroup 80 connCount int64 // atomic 93 config atomic.Value // *Config 94 db Database 95 stopWG sync.WaitGroup 81 96 82 97 lock sync.Mutex 83 98 listeners map[net.Listener]struct{} 84 99 users map[string]*user 100 101 metrics struct { 102 downstreams int64Gauge 103 } 85 104 } 86 105 … … 145 164 Name: "soju_downstreams_active", 146 165 Help: "Current number of downstream connections", 147 }, func() float64 { 148 return float64(atomic.LoadInt64(&s.connCount)) 149 }) 166 }, s.metrics.downstreams.Float64) 150 167 } 151 168 … … 235 252 }() 236 253 237 atomic.AddInt64(&s.connCount,1)254 s.metrics.downstreams.Add(1) 238 255 id := atomic.AddUint64(&lastDownstreamID, 1) 239 256 dc := newDownstreamConn(s, ic, id) … … 250 267 } 251 268 dc.Close() 252 atomic.AddInt64(&s.connCount,-1)269 s.metrics.downstreams.Add(-1) 253 270 } 254 271 … … 334 351 stats.Users = len(s.users) 335 352 s.lock.Unlock() 336 stats.Downstreams = atomic.LoadInt64(&s.connCount)353 stats.Downstreams = s.metrics.downstreams.Value() 337 354 return &stats 338 355 }
Note:
See TracChangeset
for help on using the changeset viewer.