diff --git a/socketserver/server/commands.go b/socketserver/server/commands.go index 2cf2e29a..958939c5 100644 --- a/socketserver/server/commands.go +++ b/socketserver/server/commands.go @@ -285,6 +285,8 @@ func C2SEmoticonUses(conn *websocket.Conn, client *ClientInfo, msg ClientMessage aggregateEmoteUsageLock.Lock() defer aggregateEmoteUsageLock.Unlock() + var total int + for strEmote, val1 := range mapRoot { var emoteID int emoteID, err = strconv.Atoi(strEmote) @@ -305,9 +307,12 @@ func C2SEmoticonUses(conn *websocket.Conn, client *ClientInfo, msg ClientMessage count = 200 } destMapInner[roomName] += count + total += count } } + Statistics.EmotesReportedTotal += uint64(total) + return ResponseSuccess, nil } diff --git a/socketserver/server/stats.go b/socketserver/server/stats.go index e8b0e28c..d22634c0 100644 --- a/socketserver/server/stats.go +++ b/socketserver/server/stats.go @@ -12,9 +12,19 @@ import ( type StatsData struct { Version int + CachedStatsLastUpdate time.Time CurrentClientCount uint64 + PubSubChannelCount int + + MemoryInUse uint64 + MemoryRSS uint64 + + MemoryPerClient uint64 + + CpuUsagePct float64 + ClientConnectsTotal uint64 ClientDisconnectsTotal uint64 @@ -25,12 +35,7 @@ type StatsData struct { MessagesSent uint64 - CachedStatsLastUpdate time.Time - - MemoryInUse uint64 - MemoryRSS int64 - - CpuUsagePct float64 + EmotesReportedTotal uint64 // DisconnectReasons is at the bottom because it has indeterminate size DisconnectReasons map[string]uint64 @@ -38,9 +43,12 @@ type StatsData struct { // Statistics is several variables that get incremented during normal operation of the server. // Its structure should be versioned as it is exposed via JSON. +// +// Note as to threaded access - this is soft/fun data and not critical to data integrity. +// I don't really care. var Statistics = newStatsData() -const StatsDataVersion = 2 +const StatsDataVersion = 3 const pageSize = 4096 var cpuUsage struct { @@ -84,9 +92,20 @@ func updatePeriodicStats() { cpuUsage.SysTime = pstat.Stime Statistics.CpuUsagePct = 100 * float64(userTicks + sysTicks) / (timeDiff.Seconds() * float64(ticksPerSecond)) - Statistics.MemoryRSS = pstat.Rss * pageSize + Statistics.MemoryRSS = uint64(pstat.Rss * pageSize) + Statistics.MemoryPerClient = Statistics.MemoryRSS / Statistics.CurrentClientCount } } + + { + ChatSubscriptionLock.RLock() + Statistics.PubSubChannelCount = len(ChatSubscriptionInfo) + ChatSubscriptionLock.RUnlock() + + GlobalSubscriptionInfo.RLock() + Statistics.CurrentClientCount = uint64(len(GlobalSubscriptionInfo.Members)) + GlobalSubscriptionInfo.RUnlock() + } } func HTTPShowStatistics(w http.ResponseWriter, r *http.Request) {