Remove quitting users from channels
This commit is contained in:
parent
2b510d3a04
commit
33b787a969
|
@ -11,7 +11,8 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
gaugePacketsTransferred prometheus.Gauge
|
gaugePacketsTransferred prometheus.Gauge
|
||||||
gaugeClientConnections prometheus.Gauge
|
gaugeConnectionsCurrent prometheus.Gauge
|
||||||
|
gaugeConnectionsCount prometheus.Gauge
|
||||||
gaugeQueueLen prometheus.Gauge
|
gaugeQueueLen prometheus.Gauge
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,8 +21,12 @@ func monitoringRun(sv *Server) {
|
||||||
Name: "ircd_packets_transferred",
|
Name: "ircd_packets_transferred",
|
||||||
Help: "Packets handled",
|
Help: "Packets handled",
|
||||||
})
|
})
|
||||||
gaugeClientConnections = prometheus.NewGauge(prometheus.GaugeOpts{
|
gaugeConnectionsCurrent = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
Name: "ircd_clients_connected",
|
Name: "ircd_connections_current",
|
||||||
|
Help: "Client connections",
|
||||||
|
})
|
||||||
|
gaugeConnectionsCount = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
|
Name: "ircd_connections_count",
|
||||||
Help: "Client connections",
|
Help: "Client connections",
|
||||||
})
|
})
|
||||||
gaugeQueueLen = prometheus.NewGauge(prometheus.GaugeOpts{
|
gaugeQueueLen = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
|
@ -29,7 +34,8 @@ func monitoringRun(sv *Server) {
|
||||||
Help: "Unhandled msgs in dispatcher queue",
|
Help: "Unhandled msgs in dispatcher queue",
|
||||||
})
|
})
|
||||||
prometheus.MustRegister(gaugePacketsTransferred)
|
prometheus.MustRegister(gaugePacketsTransferred)
|
||||||
prometheus.MustRegister(gaugeClientConnections)
|
prometheus.MustRegister(gaugeConnectionsCurrent)
|
||||||
|
prometheus.MustRegister(gaugeConnectionsCount)
|
||||||
prometheus.MustRegister(gaugeQueueLen)
|
prometheus.MustRegister(gaugeQueueLen)
|
||||||
go monitoringUpdater(sv)
|
go monitoringUpdater(sv)
|
||||||
http.Handle("/metrics", prometheus.Handler())
|
http.Handle("/metrics", prometheus.Handler())
|
||||||
|
@ -41,7 +47,8 @@ func monitoringUpdater(sv *Server) {
|
||||||
for {
|
for {
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
gaugePacketsTransferred.Set(sv.packetsTransferred)
|
gaugePacketsTransferred.Set(sv.packetsTransferred)
|
||||||
gaugeClientConnections.Set(sv.clientConnections)
|
gaugeConnectionsCurrent.Set(sv.connectionsCurrent)
|
||||||
gaugeClientConnections.Set(sv.queueLen)
|
gaugeConnectionsCount.Set(sv.connectionsCount)
|
||||||
|
gaugeQueueLen.Set(sv.queueLen)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
51
server.go
51
server.go
|
@ -29,21 +29,22 @@ type Server struct {
|
||||||
AddClient chan Client
|
AddClient chan Client
|
||||||
DelClient chan Client
|
DelClient chan Client
|
||||||
|
|
||||||
host string
|
host string
|
||||||
info string
|
info string
|
||||||
software string
|
software string
|
||||||
version string
|
version string
|
||||||
created string
|
created string
|
||||||
motd string
|
motd string
|
||||||
clients map[string]Client
|
clients map[string]Client
|
||||||
chUsers map[string]map[string]string
|
chUsers map[string]map[string]string
|
||||||
|
//chModes map[string][]string
|
||||||
chTopics map[string]string
|
chTopics map[string]string
|
||||||
chModes map[string][]string
|
|
||||||
config *conf.ConfigFile
|
config *conf.ConfigFile
|
||||||
configPath string
|
configPath string
|
||||||
|
|
||||||
packetsTransferred float64
|
packetsTransferred float64
|
||||||
clientConnections float64
|
connectionsCurrent float64
|
||||||
|
connectionsCount float64
|
||||||
queueLen float64
|
queueLen float64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +68,8 @@ func NewServer(configPath, software, version string) *Server {
|
||||||
xlog.Init(loglevel)
|
xlog.Init(loglevel)
|
||||||
|
|
||||||
sv.packetsTransferred = 0
|
sv.packetsTransferred = 0
|
||||||
sv.clientConnections = 0
|
sv.connectionsCurrent = 0
|
||||||
|
sv.connectionsCount = 0
|
||||||
sv.queueLen = 0
|
sv.queueLen = 0
|
||||||
|
|
||||||
return sv
|
return sv
|
||||||
|
@ -101,7 +103,7 @@ func (sv *Server) listen(laddr string) {
|
||||||
xlog.Error(err.Error())
|
xlog.Error(err.Error())
|
||||||
} else {
|
} else {
|
||||||
NewRemoteClient(sv, conn)
|
NewRemoteClient(sv, conn)
|
||||||
sv.clientConnections++
|
sv.connectionsCount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,24 +113,31 @@ func (sv *Server) listenTls(laddr string) {
|
||||||
|
|
||||||
func (sv *Server) dispatch() {
|
func (sv *Server) dispatch() {
|
||||||
for {
|
for {
|
||||||
time.Sleep(1 * time.Millisecond)
|
time.Sleep(1 * time.Microsecond)
|
||||||
sv.queueLen = float64(len(sv.Dispatch))
|
sv.queueLen = float64(len(sv.Dispatch))
|
||||||
select {
|
select {
|
||||||
case msg := <-sv.Dispatch:
|
case msg := <-sv.Dispatch:
|
||||||
sv.recvMsg(msg)
|
sv.recvMsg(msg)
|
||||||
sv.packetsTransferred++
|
sv.packetsTransferred++
|
||||||
case cl := <-sv.AddClient:
|
case cl := <-sv.AddClient:
|
||||||
name := cl.Name()
|
nick := cl.Name()
|
||||||
sv.clients[name] = cl
|
sv.clients[nick] = cl
|
||||||
sv.sendLogon(cl.Name())
|
sv.sendLogon(cl.Name())
|
||||||
xlog.Info("Client registered: '%s'", name)
|
sv.connectionsCurrent = float64(len(sv.clients))
|
||||||
|
xlog.Info("Client registered: '%s'", nick)
|
||||||
xlog.Info("Server has %d client(s)", len(sv.clients))
|
xlog.Info("Server has %d client(s)", len(sv.clients))
|
||||||
xlog.Debug("Goroutines running: %d", runtime.NumGoroutine())
|
xlog.Debug("Goroutines running: %d", runtime.NumGoroutine())
|
||||||
case cl := <-sv.DelClient:
|
case cl := <-sv.DelClient:
|
||||||
name := cl.Name()
|
nick := cl.Name()
|
||||||
cl.Destroy()
|
cl.Destroy()
|
||||||
delete(sv.clients, name)
|
for _, ch := range sv.chUsers {
|
||||||
xlog.Info("Client deleted: '%s'", name)
|
if _, exists := ch[nick]; exists {
|
||||||
|
delete(ch, nick)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete(sv.clients, nick)
|
||||||
|
sv.connectionsCurrent = float64(len(sv.clients))
|
||||||
|
xlog.Info("Client deleted: '%s'", nick)
|
||||||
xlog.Info("Server has %d client(s)", len(sv.clients))
|
xlog.Info("Server has %d client(s)", len(sv.clients))
|
||||||
xlog.Debug("Goroutines running: %d", runtime.NumGoroutine())
|
xlog.Debug("Goroutines running: %d", runtime.NumGoroutine())
|
||||||
default:
|
default:
|
||||||
|
@ -175,7 +184,9 @@ func (sv *Server) sendMsg(msg *irc.Message) {
|
||||||
if msg.Pre == nick && msg.Cmd == "PRIVMSG" {
|
if msg.Pre == nick && msg.Cmd == "PRIVMSG" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
sv.clients[nick].Receive(msg)
|
if cl, exists := sv.clients[nick]; exists {
|
||||||
|
cl.Receive(msg)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if _, exists := sv.clients[msg.Args[0]]; !exists {
|
if _, exists := sv.clients[msg.Args[0]]; !exists {
|
||||||
|
|
Loading…
Reference in New Issue