Changeset 605 in code


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.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/soju.1.scd

    r577 r605  
    321321        Delete a soju user. Only admins can delete accounts.
    322322
     323*server status*
     324        Show some bouncer statistics. Only admins can query this information.
     325
    323326# AUTHORS
    324327
  • 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}
  • trunk/service.go

    r577 r605  
    293293                        },
    294294                },
     295                "server": {
     296                        children: serviceCommandSet{
     297                                "status": {
     298                                        desc:   "show server statistics",
     299                                        handle: handleServiceServerStatus,
     300                                        admin:  true,
     301                                },
     302                        },
     303                        admin: true,
     304                },
    295305        }
    296306}
     
    10081018        return nil
    10091019}
     1020
     1021func handleServiceServerStatus(dc *downstreamConn, params []string) error {
     1022        stats := dc.user.srv.Stats()
     1023        sendServicePRIVMSG(dc, fmt.Sprintf("%v users, %v downstreams", stats.Users, stats.Downstreams))
     1024        return nil
     1025}
Note: See TracChangeset for help on using the changeset viewer.