mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-09-16 12:43:05 +00:00
smp server: prometheus metrics for delievered and not acknowledged messages (to monitor stuck deliveries)
This commit is contained in:
@@ -579,15 +579,23 @@ smpServer started cfg@ServerConfig {transports, transportConfig = tCfg, startOpt
|
||||
let threadsCount = 0
|
||||
#endif
|
||||
clientsCount <- IM.size <$> getServerClients srv
|
||||
deliveredSubs <- getDeliveredMetrics
|
||||
smpSubs <- getSubscribersMetrics subscribers
|
||||
ntfSubs <- getSubscribersMetrics ntfSubscribers
|
||||
loadedCounts <- loadedQueueCounts ms
|
||||
pure RealTimeMetrics {socketStats, threadsCount, clientsCount, smpSubs, ntfSubs, loadedCounts}
|
||||
pure RealTimeMetrics {socketStats, threadsCount, clientsCount, deliveredSubs, smpSubs, ntfSubs, loadedCounts}
|
||||
where
|
||||
getSubscribersMetrics ServerSubscribers {queueSubscribers, subClients} = do
|
||||
subsCount <- M.size <$> getSubscribedClients queueSubscribers
|
||||
subClientsCount <- IS.size <$> readTVarIO subClients
|
||||
pure RTSubscriberMetrics {subsCount, subClientsCount}
|
||||
getDeliveredMetrics = foldM countClnd (RTSubscriberMetrics 0 0) =<< getServerClients srv
|
||||
countClnd metrics (AClient _ _ Client {subscriptions}) = do
|
||||
cnt <- foldM countSubs 0 =<< readTVarIO subscriptions
|
||||
pure $ if cnt > 0
|
||||
then metrics {subsCount = subsCount metrics + cnt, subClientsCount = subClientsCount metrics + 1}
|
||||
else metrics
|
||||
countSubs !cnt Sub {delivered} = (\empty -> if empty then cnt else cnt + 1) <$> atomically (isEmptyTMVar delivered)
|
||||
|
||||
runClient :: Transport c => X.CertificateChain -> C.APrivateSignKey -> TProxy c 'TServer -> c 'TServer -> M ()
|
||||
runClient srvCert srvSignKey tp h = do
|
||||
|
||||
@@ -33,6 +33,7 @@ data RealTimeMetrics = RealTimeMetrics
|
||||
{ socketStats :: [(ServiceName, SocketStats)],
|
||||
threadsCount :: Int,
|
||||
clientsCount :: Int,
|
||||
deliveredSubs :: RTSubscriberMetrics,
|
||||
smpSubs :: RTSubscriberMetrics,
|
||||
ntfSubs :: RTSubscriberMetrics,
|
||||
loadedCounts :: LoadedQueueCounts
|
||||
@@ -53,6 +54,7 @@ prometheusMetrics sm rtm ts =
|
||||
{ socketStats,
|
||||
threadsCount,
|
||||
clientsCount,
|
||||
deliveredSubs,
|
||||
smpSubs,
|
||||
ntfSubs,
|
||||
loadedCounts
|
||||
@@ -368,6 +370,14 @@ prometheusMetrics sm rtm ts =
|
||||
\# TYPE simplex_smp_clients_total gauge\n\
|
||||
\simplex_smp_clients_total " <> mshow clientsCount <> "\n\
|
||||
\\n\
|
||||
\# HELP simplex_smp_delivered_total Total SMP subscriptions with delivered messages\n\
|
||||
\# TYPE simplex_smp_delivered_total gauge\n\
|
||||
\simplex_smp_delivered_total " <> mshow (subsCount deliveredSubs) <> "\n# delivered.subsCount\n\
|
||||
\\n\
|
||||
\# HELP simplex_smp_delivered_clients_total Subscribed clients\n\
|
||||
\# TYPE simplex_smp_delivered_clients_total gauge\n\
|
||||
\simplex_smp_delivered_clients_total " <> mshow (subClientsCount deliveredSubs) <> "\n# delivered.subClientsCount\n\
|
||||
\\n\
|
||||
\# HELP simplex_smp_subscribtion_total Total SMP subscriptions\n\
|
||||
\# TYPE simplex_smp_subscribtion_total gauge\n\
|
||||
\simplex_smp_subscribtion_total " <> mshow (subsCount smpSubs) <> "\n# smp.subsCount\n\
|
||||
|
||||
Reference in New Issue
Block a user