mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-05-29 09:55:35 +02:00
WIP: persist message stats
This commit is contained in:
parent
4783cb1211
commit
6be95f8285
4 changed files with 130 additions and 31 deletions
server
|
@ -73,9 +73,9 @@ func (s *Server) execManager() {
|
|||
}
|
||||
|
||||
// Print stats
|
||||
s.mu.Lock()
|
||||
s.mu.RLock()
|
||||
messagesCount, topicsCount, visitorsCount := s.messages, len(s.topics), len(s.visitors)
|
||||
s.mu.Unlock()
|
||||
s.mu.RUnlock()
|
||||
log.
|
||||
Tag(tagManager).
|
||||
Fields(log.Context{
|
||||
|
@ -98,6 +98,19 @@ func (s *Server) execManager() {
|
|||
mset(metricUsers, usersCount)
|
||||
mset(metricSubscribers, subscribers)
|
||||
mset(metricTopics, topicsCount)
|
||||
|
||||
// Write stats
|
||||
s.mu.Lock()
|
||||
s.messagesHistory = append(s.messagesHistory, messagesCount)
|
||||
if len(s.messagesHistory) > messagesHistoryMax {
|
||||
s.messagesHistory = s.messagesHistory[1:]
|
||||
}
|
||||
s.mu.Unlock()
|
||||
go func() {
|
||||
if err := s.messageCache.UpdateStats(messagesCount); err != nil {
|
||||
log.Tag(tagManager).Err(err).Warn("Cannot write messages stats")
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func (s *Server) pruneVisitors() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue