|
@@ -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
|