Add number of upstream connections to metrics

This commit is contained in:
Simon Ser 2021-11-15 20:58:36 +01:00
parent 7fa8c78122
commit efc4c62725
3 changed files with 13 additions and 1 deletions

View File

@ -100,6 +100,7 @@ type Server struct {
metrics struct {
downstreams int64Gauge
upstreams int64Gauge
}
}
@ -164,6 +165,11 @@ func (s *Server) registerMetrics() {
Name: "soju_downstreams_active",
Help: "Current number of downstream connections",
}, s.metrics.downstreams.Float64)
factory.NewGaugeFunc(prometheus.GaugeOpts{
Name: "soju_upstreams_active",
Help: "Current number of upstream connections",
}, s.metrics.upstreams.Float64)
}
func (s *Server) Shutdown() {
@ -343,6 +349,7 @@ func parseForwarded(h http.Header) map[string]string {
type ServerStats struct {
Users int
Downstreams int64
Upstreams int64
}
func (s *Server) Stats() *ServerStats {
@ -351,5 +358,6 @@ func (s *Server) Stats() *ServerStats {
stats.Users = len(s.users)
s.lock.Unlock()
stats.Downstreams = s.metrics.downstreams.Value()
stats.Upstreams = s.metrics.upstreams.Value()
return &stats
}

View File

@ -1035,7 +1035,7 @@ func handleServiceServerStatus(ctx context.Context, dc *downstreamConn, params [
return err
}
serverStats := dc.user.srv.Stats()
sendServicePRIVMSG(dc, fmt.Sprintf("%v/%v users, %v downstreams, %v networks, %v channels", serverStats.Users, dbStats.Users, serverStats.Downstreams, dbStats.Networks, dbStats.Channels))
sendServicePRIVMSG(dc, fmt.Sprintf("%v/%v users, %v downstreams, %v upstreams, %v networks, %v channels", serverStats.Users, dbStats.Users, serverStats.Downstreams, serverStats.Upstreams, dbStats.Networks, dbStats.Channels))
return nil
}

View File

@ -213,6 +213,8 @@ func (net *network) run() {
net.user.srv.Identd.Store(uc.RemoteAddr().String(), uc.LocalAddr().String(), userIdent(&net.user.User))
}
net.user.srv.metrics.upstreams.Add(1)
uc.register()
if err := uc.runUntilRegistered(); err != nil {
text := err.Error()
@ -239,6 +241,8 @@ func (net *network) run() {
if net.user.srv.Identd != nil {
net.user.srv.Identd.Delete(uc.RemoteAddr().String(), uc.LocalAddr().String())
}
net.user.srv.metrics.upstreams.Add(-1)
}
}