Remove quitting users from channels

This commit is contained in:
Andreas Neue 2016-07-21 00:03:37 +02:00
parent 2b510d3a04
commit 33b787a969
2 changed files with 44 additions and 26 deletions

View File

@ -11,7 +11,8 @@ import (
var (
gaugePacketsTransferred prometheus.Gauge
gaugeClientConnections prometheus.Gauge
gaugeConnectionsCurrent prometheus.Gauge
gaugeConnectionsCount prometheus.Gauge
gaugeQueueLen prometheus.Gauge
)
@ -20,8 +21,12 @@ func monitoringRun(sv *Server) {
Name: "ircd_packets_transferred",
Help: "Packets handled",
})
gaugeClientConnections = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "ircd_clients_connected",
gaugeConnectionsCurrent = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "ircd_connections_current",
Help: "Client connections",
})
gaugeConnectionsCount = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "ircd_connections_count",
Help: "Client connections",
})
gaugeQueueLen = prometheus.NewGauge(prometheus.GaugeOpts{
@ -29,7 +34,8 @@ func monitoringRun(sv *Server) {
Help: "Unhandled msgs in dispatcher queue",
})
prometheus.MustRegister(gaugePacketsTransferred)
prometheus.MustRegister(gaugeClientConnections)
prometheus.MustRegister(gaugeConnectionsCurrent)
prometheus.MustRegister(gaugeConnectionsCount)
prometheus.MustRegister(gaugeQueueLen)
go monitoringUpdater(sv)
http.Handle("/metrics", prometheus.Handler())
@ -41,7 +47,8 @@ func monitoringUpdater(sv *Server) {
for {
time.Sleep(5 * time.Second)
gaugePacketsTransferred.Set(sv.packetsTransferred)
gaugeClientConnections.Set(sv.clientConnections)
gaugeClientConnections.Set(sv.queueLen)
gaugeConnectionsCurrent.Set(sv.connectionsCurrent)
gaugeConnectionsCount.Set(sv.connectionsCount)
gaugeQueueLen.Set(sv.queueLen)
}
}

View File

@ -37,13 +37,14 @@ type Server struct {
motd string
clients map[string]Client
chUsers map[string]map[string]string
//chModes map[string][]string
chTopics map[string]string
chModes map[string][]string
config *conf.ConfigFile
configPath string
packetsTransferred float64
clientConnections float64
connectionsCurrent float64
connectionsCount float64
queueLen float64
}
@ -67,7 +68,8 @@ func NewServer(configPath, software, version string) *Server {
xlog.Init(loglevel)
sv.packetsTransferred = 0
sv.clientConnections = 0
sv.connectionsCurrent = 0
sv.connectionsCount = 0
sv.queueLen = 0
return sv
@ -101,7 +103,7 @@ func (sv *Server) listen(laddr string) {
xlog.Error(err.Error())
} else {
NewRemoteClient(sv, conn)
sv.clientConnections++
sv.connectionsCount++
}
}
}
@ -111,24 +113,31 @@ func (sv *Server) listenTls(laddr string) {
func (sv *Server) dispatch() {
for {
time.Sleep(1 * time.Millisecond)
time.Sleep(1 * time.Microsecond)
sv.queueLen = float64(len(sv.Dispatch))
select {
case msg := <-sv.Dispatch:
sv.recvMsg(msg)
sv.packetsTransferred++
case cl := <-sv.AddClient:
name := cl.Name()
sv.clients[name] = cl
nick := cl.Name()
sv.clients[nick] = cl
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.Debug("Goroutines running: %d", runtime.NumGoroutine())
case cl := <-sv.DelClient:
name := cl.Name()
nick := cl.Name()
cl.Destroy()
delete(sv.clients, name)
xlog.Info("Client deleted: '%s'", name)
for _, ch := range sv.chUsers {
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.Debug("Goroutines running: %d", runtime.NumGoroutine())
default:
@ -175,7 +184,9 @@ func (sv *Server) sendMsg(msg *irc.Message) {
if msg.Pre == nick && msg.Cmd == "PRIVMSG" {
continue
}
sv.clients[nick].Receive(msg)
if cl, exists := sv.clients[nick]; exists {
cl.Receive(msg)
}
}
} else {
if _, exists := sv.clients[msg.Args[0]]; !exists {