Add metric for users locked in post-login sync
This commit is contained in:
parent
bf5be3fe62
commit
221326bcbf
22
metrics.go
22
metrics.go
@ -59,6 +59,8 @@ type MetricsHandler struct {
|
||||
connectedState map[types.WhatsAppID]bool
|
||||
loggedIn prometheus.Gauge
|
||||
loggedInState map[types.WhatsAppID]bool
|
||||
syncLocked prometheus.Gauge
|
||||
syncLockedState map[types.WhatsAppID]bool
|
||||
}
|
||||
|
||||
func NewMetricsHandler(address string, log log.Logger, db *database.Database) *MetricsHandler {
|
||||
@ -112,6 +114,11 @@ func NewMetricsHandler(address string, log log.Logger, db *database.Database) *M
|
||||
Help: "Bridge users connected to WhatsApp",
|
||||
}),
|
||||
connectedState: make(map[types.WhatsAppID]bool),
|
||||
syncLocked: promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "bridge_sync_locked",
|
||||
Help: "Bridge users locked in post-login sync",
|
||||
}),
|
||||
syncLockedState: make(map[types.WhatsAppID]bool),
|
||||
}
|
||||
}
|
||||
|
||||
@ -167,6 +174,21 @@ func (mh *MetricsHandler) TrackConnectionState(jid types.WhatsAppID, connected b
|
||||
}
|
||||
}
|
||||
|
||||
func (mh *MetricsHandler) TrackSyncLock(jid types.WhatsAppID, locked bool) {
|
||||
if !mh.running {
|
||||
return
|
||||
}
|
||||
currentVal, ok := mh.syncLockedState[jid]
|
||||
if !ok || currentVal != locked {
|
||||
mh.syncLockedState[jid] = locked
|
||||
if locked {
|
||||
mh.syncLocked.Inc()
|
||||
} else {
|
||||
mh.syncLocked.Dec()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (mh *MetricsHandler) updateStats() {
|
||||
start := time.Now()
|
||||
var puppetCount int
|
||||
|
2
user.go
2
user.go
@ -798,7 +798,9 @@ func (user *User) handleMessageLoop() {
|
||||
user.GetPortalByJID(msg.chat).messages <- msg
|
||||
case <-user.syncStart:
|
||||
user.log.Debugln("Processing of incoming messages is locked")
|
||||
user.bridge.Metrics.TrackSyncLock(user.JID, true)
|
||||
user.syncWait.Wait()
|
||||
user.bridge.Metrics.TrackSyncLock(user.JID, false)
|
||||
user.log.Debugln("Processing of incoming messages unlocked")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user