Add metric for users locked in post-login sync
This commit is contained in:
parent
bf5be3fe62
commit
221326bcbf
30
metrics.go
30
metrics.go
@ -55,10 +55,12 @@ type MetricsHandler struct {
|
|||||||
unencryptedGroupCount prometheus.Gauge
|
unencryptedGroupCount prometheus.Gauge
|
||||||
unencryptedPrivateCount prometheus.Gauge
|
unencryptedPrivateCount prometheus.Gauge
|
||||||
|
|
||||||
connected prometheus.Gauge
|
connected prometheus.Gauge
|
||||||
connectedState map[types.WhatsAppID]bool
|
connectedState map[types.WhatsAppID]bool
|
||||||
loggedIn prometheus.Gauge
|
loggedIn prometheus.Gauge
|
||||||
loggedInState map[types.WhatsAppID]bool
|
loggedInState map[types.WhatsAppID]bool
|
||||||
|
syncLocked prometheus.Gauge
|
||||||
|
syncLockedState map[types.WhatsAppID]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMetricsHandler(address string, log log.Logger, db *database.Database) *MetricsHandler {
|
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",
|
Help: "Bridge users connected to WhatsApp",
|
||||||
}),
|
}),
|
||||||
connectedState: make(map[types.WhatsAppID]bool),
|
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() {
|
func (mh *MetricsHandler) updateStats() {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
var puppetCount int
|
var puppetCount int
|
||||||
|
2
user.go
2
user.go
@ -798,7 +798,9 @@ func (user *User) handleMessageLoop() {
|
|||||||
user.GetPortalByJID(msg.chat).messages <- msg
|
user.GetPortalByJID(msg.chat).messages <- msg
|
||||||
case <-user.syncStart:
|
case <-user.syncStart:
|
||||||
user.log.Debugln("Processing of incoming messages is locked")
|
user.log.Debugln("Processing of incoming messages is locked")
|
||||||
|
user.bridge.Metrics.TrackSyncLock(user.JID, true)
|
||||||
user.syncWait.Wait()
|
user.syncWait.Wait()
|
||||||
|
user.bridge.Metrics.TrackSyncLock(user.JID, false)
|
||||||
user.log.Debugln("Processing of incoming messages unlocked")
|
user.log.Debugln("Processing of incoming messages unlocked")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user