Merge branch 'stats'
This commit is contained in:
commit
b655e81753
|
@ -433,12 +433,12 @@ func (server *Server) Lusers(client *Client, rb *ResponseBuffer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
rb.Add(nil, server.name, RPL_LUSERCLIENT, nick, fmt.Sprintf(client.t("There are %[1]d users and %[2]d invisible on %[3]d server(s)"), stats.Total-stats.Invisible, stats.Invisible, 1))
|
rb.Add(nil, server.name, RPL_LUSERCLIENT, nick, fmt.Sprintf(client.t("There are %[1]d users and %[2]d invisible on %[3]d server(s)"), stats.Total-stats.Invisible, stats.Invisible, 1))
|
||||||
rb.Add(nil, server.name, RPL_LUSEROP, nick, strconv.Itoa(stats.Operators), client.t("IRC Operators online"))
|
rb.Add(nil, server.name, RPL_LUSEROP, nick, strconv.Itoa(int(stats.Operators)), client.t("IRC Operators online"))
|
||||||
rb.Add(nil, server.name, RPL_LUSERUNKNOWN, nick, strconv.Itoa(stats.Unknown), client.t("unregistered connections"))
|
rb.Add(nil, server.name, RPL_LUSERUNKNOWN, nick, strconv.Itoa(int(stats.Unknown)), client.t("unregistered connections"))
|
||||||
rb.Add(nil, server.name, RPL_LUSERCHANNELS, nick, strconv.Itoa(numChannels), client.t("channels formed"))
|
rb.Add(nil, server.name, RPL_LUSERCHANNELS, nick, strconv.Itoa(numChannels), client.t("channels formed"))
|
||||||
rb.Add(nil, server.name, RPL_LUSERME, nick, fmt.Sprintf(client.t("I have %[1]d clients and %[2]d servers"), stats.Total, 0))
|
rb.Add(nil, server.name, RPL_LUSERME, nick, fmt.Sprintf(client.t("I have %[1]d clients and %[2]d servers"), stats.Total, 0))
|
||||||
total := strconv.Itoa(stats.Total)
|
total := strconv.Itoa(int(stats.Total))
|
||||||
max := strconv.Itoa(stats.Max)
|
max := strconv.Itoa(int(stats.Max))
|
||||||
rb.Add(nil, server.name, RPL_LOCALUSERS, nick, total, max, fmt.Sprintf(client.t("Current local users %[1]s, max %[2]s"), total, max))
|
rb.Add(nil, server.name, RPL_LOCALUSERS, nick, total, max, fmt.Sprintf(client.t("Current local users %[1]s, max %[2]s"), total, max))
|
||||||
rb.Add(nil, server.name, RPL_GLOBALUSERS, nick, total, max, fmt.Sprintf(client.t("Current global users %[1]s, max %[2]s"), total, max))
|
rb.Add(nil, server.name, RPL_GLOBALUSERS, nick, total, max, fmt.Sprintf(client.t("Current global users %[1]s, max %[2]s"), total, max))
|
||||||
}
|
}
|
||||||
|
|
59
irc/stats.go
59
irc/stats.go
|
@ -1,55 +1,47 @@
|
||||||
package irc
|
package irc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync/atomic"
|
||||||
)
|
)
|
||||||
|
|
||||||
type StatsValues struct {
|
type StatsValues struct {
|
||||||
Unknown int // unregistered clients
|
Unknown int32 // unregistered clients
|
||||||
Total int // registered clients, including invisible
|
Total int32 // registered clients, including invisible
|
||||||
Max int // high-water mark of registered clients
|
Max int32 // high-water mark of registered clients
|
||||||
Invisible int
|
Invisible int32
|
||||||
Operators int
|
Operators int32
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stats tracks statistics for a running server
|
// Stats tracks statistics for a running server
|
||||||
type Stats struct {
|
type Stats struct {
|
||||||
StatsValues
|
StatsValues
|
||||||
|
|
||||||
mutex sync.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add Adds an unregistered client
|
// Add Adds an unregistered client
|
||||||
func (s *Stats) Add() {
|
func (s *Stats) Add() {
|
||||||
s.mutex.Lock()
|
atomic.AddInt32(&s.Unknown, 1)
|
||||||
s.Unknown += 1
|
|
||||||
s.mutex.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddRegistered Activates a registered client, e.g., for the initial attach to a persistent client
|
// AddRegistered Activates a registered client, e.g., for the initial attach to a persistent client
|
||||||
func (s *Stats) AddRegistered(invisible, operator bool) {
|
func (s *Stats) AddRegistered(invisible, operator bool) {
|
||||||
s.mutex.Lock()
|
|
||||||
if invisible {
|
if invisible {
|
||||||
s.Invisible += 1
|
atomic.AddInt32(&s.Invisible, 1)
|
||||||
}
|
}
|
||||||
if operator {
|
if operator {
|
||||||
s.Operators += 1
|
atomic.AddInt32(&s.Operators, 1)
|
||||||
}
|
}
|
||||||
s.Total += 1
|
atomic.AddInt32(&s.Total, 1)
|
||||||
s.setMax()
|
s.setMax()
|
||||||
s.mutex.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register Transition a client from unregistered to registered
|
// Register Transition a client from unregistered to registered
|
||||||
func (s *Stats) Register(invisible bool) {
|
func (s *Stats) Register(invisible bool) {
|
||||||
s.mutex.Lock()
|
atomic.AddInt32(&s.Unknown, -1)
|
||||||
s.Unknown -= 1
|
|
||||||
if invisible {
|
if invisible {
|
||||||
s.Invisible += 1
|
atomic.AddInt32(&s.Invisible, 1)
|
||||||
}
|
}
|
||||||
s.Total += 1
|
atomic.AddInt32(&s.Total, 1)
|
||||||
s.setMax()
|
s.setMax()
|
||||||
s.mutex.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Stats) setMax() {
|
func (s *Stats) setMax() {
|
||||||
|
@ -60,39 +52,32 @@ func (s *Stats) setMax() {
|
||||||
|
|
||||||
// ChangeInvisible Modify the Invisible count
|
// ChangeInvisible Modify the Invisible count
|
||||||
func (s *Stats) ChangeInvisible(increment int) {
|
func (s *Stats) ChangeInvisible(increment int) {
|
||||||
s.mutex.Lock()
|
atomic.AddInt32(&s.Invisible, int32(increment))
|
||||||
s.Invisible += increment
|
|
||||||
s.mutex.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChangeOperators Modify the Operator count
|
// ChangeOperators Modify the Operator count
|
||||||
func (s *Stats) ChangeOperators(increment int) {
|
func (s *Stats) ChangeOperators(increment int) {
|
||||||
s.mutex.Lock()
|
atomic.AddInt32(&s.Operators, int32(increment))
|
||||||
s.Operators += increment
|
|
||||||
s.mutex.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove a user from the server
|
// Remove a user from the server
|
||||||
func (s *Stats) Remove(registered, invisible, operator bool) {
|
func (s *Stats) Remove(registered, invisible, operator bool) {
|
||||||
s.mutex.Lock()
|
switch registered {
|
||||||
if registered {
|
case true:
|
||||||
s.Total -= 1
|
atomic.AddInt32(&s.Total, -1)
|
||||||
} else {
|
default:
|
||||||
s.Unknown -= 1
|
atomic.AddInt32(&s.Unknown, -1)
|
||||||
}
|
}
|
||||||
if invisible {
|
if invisible {
|
||||||
s.Invisible -= 1
|
atomic.AddInt32(&s.Invisible, -1)
|
||||||
}
|
}
|
||||||
if operator {
|
if operator {
|
||||||
s.Operators -= 1
|
atomic.AddInt32(&s.Operators, -1)
|
||||||
}
|
}
|
||||||
s.mutex.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetValues GetStats retrives total, invisible and oper count
|
// GetValues GetStats retrives total, invisible and oper count
|
||||||
func (s *Stats) GetValues() (result StatsValues) {
|
func (s *Stats) GetValues() (result StatsValues) {
|
||||||
s.mutex.Lock()
|
|
||||||
result = s.StatsValues
|
result = s.StatsValues
|
||||||
s.mutex.Unlock()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue