feat: implement WhatsApp connection and message metrics

Added tracking for all WhatsApp-related metrics:

Connection metrics:
- active_connections: Gauge tracking active connections (inc on open, dec on close)
- connection_attempts_total: Counter for connection attempts (success/failure)

Message metrics:
- messages_sent_total: Counter with type label (text, image, video, audio, etc)
- messages_received_total: Counter with type label
- history_sync_messages_total: Counter for history sync messages

Added helper functions in prometheus-metrics.ts:
- incrementActiveConnections(), decrementActiveConnections(), setActiveConnections()
- recordConnectionAttempt(status)
- recordMessageSent(type), recordMessageReceived(type)
- recordMessageRetry(type), recordMessageFailure(type, reason)
- setMessagesQueued(count, priority)
- recordHistorySyncMessages(count)
This commit is contained in:
Claude
2026-01-22 14:20:17 +00:00
parent f9ed1dc16f
commit de5988ba8f
5 changed files with 159 additions and 3 deletions
+14 -1
View File
@@ -54,7 +54,12 @@ import {
jidEncode,
S_WHATSAPP_NET
} from '../WABinary'
import { recordConnectionError } from '../Utils/prometheus-metrics'
import {
recordConnectionError,
recordConnectionAttempt,
incrementActiveConnections,
decrementActiveConnections
} from '../Utils/prometheus-metrics'
import { BinaryInfo } from '../WAM/BinaryInfo.js'
import { USyncQuery, USyncUser } from '../WAUSync/'
import { WebSocketClient } from './Client'
@@ -764,8 +769,12 @@ export const makeSocket = (config: SocketConfig) => {
errorType = `error_${statusCode}`
}
recordConnectionError(errorType)
recordConnectionAttempt('failure')
}
// Decrement active connections
decrementActiveConnections()
clearInterval(keepAliveReq)
clearTimeout(qrTimer)
@@ -1080,6 +1089,10 @@ export const makeSocket = (config: SocketConfig) => {
ev.emit('connection.update', { connection: 'open' })
// Record successful connection metrics
recordConnectionAttempt('success')
incrementActiveConnections()
if (node.attrs.lid && authState.creds.me?.id) {
const myLID = node.attrs.lid
process.nextTick(async () => {