Changeset 605 in code for trunk/server.go


Ignore:
Timestamp:
Oct 5, 2021, 5:13:53 PM (4 years ago)
Author:
contact
Message:

Add "server status" command

Right now, it prints the number of active users and number of
downstream connections.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/server.go

    r601 r605  
    5656        Identd         *Identd // can be nil
    5757
    58         db     Database
    59         stopWG sync.WaitGroup
     58        db        Database
     59        stopWG    sync.WaitGroup
     60        connCount int64 // atomic
    6061
    6162        lock      sync.Mutex
     
    166167
    167168func (s *Server) handle(ic ircConn) {
     169        atomic.AddInt64(&s.connCount, 1)
    168170        id := atomic.AddUint64(&lastDownstreamID, 1)
    169171        dc := newDownstreamConn(s, ic, id)
     
    178180        }
    179181        dc.Close()
     182        atomic.AddInt64(&s.connCount, -1)
    180183}
    181184
     
    250253        return params
    251254}
     255
     256type ServerStats struct {
     257        Users       int
     258        Downstreams int64
     259}
     260
     261func (s *Server) Stats() *ServerStats {
     262        var stats ServerStats
     263        s.lock.Lock()
     264        stats.Users = len(s.users)
     265        s.lock.Unlock()
     266        stats.Downstreams = atomic.LoadInt64(&s.connCount)
     267        return &stats
     268}
Note: See TracChangeset for help on using the changeset viewer.