diff --git a/metrics.go b/metrics.go index 89514d7..156ed0f 100644 --- a/metrics.go +++ b/metrics.go @@ -55,10 +55,12 @@ type MetricsHandler struct { unencryptedGroupCount prometheus.Gauge unencryptedPrivateCount prometheus.Gauge - connected prometheus.Gauge - connectedState map[types.WhatsAppID]bool - loggedIn prometheus.Gauge - loggedInState map[types.WhatsAppID]bool + connected prometheus.Gauge + 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 diff --git a/user.go b/user.go index 7132588..e726bbb 100644 --- a/user.go +++ b/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") } }