diff --git a/server.go b/server.go index 791d3bb..1fa7bb3 100644 --- a/server.go +++ b/server.go @@ -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 } diff --git a/service.go b/service.go index 72b45f2..a54f6a9 100644 --- a/service.go +++ b/service.go @@ -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 } diff --git a/user.go b/user.go index 45bb806..a92585e 100644 --- a/user.go +++ b/user.go @@ -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) } }