{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}

module Simplex.Messaging.Server.Stats
  ( ServerStats (..),
    ServerStatsData (..),
    PeriodStats (..),
    PeriodStatsData (..),
    PeriodStatCounts (..),
    ProxyStats (..),
    ProxyStatsData (..),
    ServiceStats (..),
    ServiceStatsData (..),
    TimeBuckets (..),
    newServerStats,
    getServerStatsData,
    setServerStats,
    newPeriodStats,
    newPeriodStatsData,
    getPeriodStatsData,
    setPeriodStats,
    periodStatDataCounts,
    periodStatCounts,
    updatePeriodStats,
    newProxyStats,
    newProxyStatsData,
    getProxyStatsData,
    getResetProxyStatsData,
    setProxyStats,
    newServiceStatsData,
    newServiceStats,
    getServiceStatsData,
    getResetServiceStatsData,
    setServiceStats,
    emptyTimeBuckets,
    updateTimeBuckets,
  ) where

import Control.Applicative (optional, (<|>))
import qualified Data.Attoparsec.ByteString.Char8 as A
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.Hashable (hash)
import Data.IORef
import Data.Int (Int64)
import qualified Data.IntMap.Strict as IM
import Data.IntSet (IntSet)
import qualified Data.IntSet as IS
import Data.Set (Set)
import qualified Data.Set as S
import Data.Text (Text)
import Data.Time.Calendar.Month (pattern MonthDay)
import Data.Time.Calendar.OrdinalDate (mondayStartWeek)
import Data.Time.Clock (UTCTime (..))
import GHC.IORef (atomicSwapIORef)
import Simplex.Messaging.Encoding.String
import Simplex.Messaging.Protocol (EntityId (..))
import Simplex.Messaging.SystemTime
import Simplex.Messaging.Util (atomicModifyIORef'_, tshow, unlessM)

data ServerStats = ServerStats
  { ServerStats -> IORef UTCTime
fromTime :: IORef UTCTime,
    ServerStats -> IORef Int
qCreated :: IORef Int,
    ServerStats -> IORef Int
qSecured :: IORef Int,
    ServerStats -> IORef Int
qDeletedAll :: IORef Int,
    ServerStats -> IORef Int
qDeletedAllB :: IORef Int,
    ServerStats -> IORef Int
qDeletedNew :: IORef Int,
    ServerStats -> IORef Int
qDeletedSecured :: IORef Int,
    ServerStats -> IORef Int
qBlocked :: IORef Int,
    ServerStats -> IORef Int
qSub :: IORef Int, -- only includes subscriptions when there were pending messages
    -- qSubNoMsg :: IORef Int, -- this stat creates too many STM transactions
    ServerStats -> IORef Int
qSubAllB :: IORef Int, -- count of all subscription batches (with and without pending messages)
    ServerStats -> IORef Int
qSubAuth :: IORef Int,
    ServerStats -> IORef Int
qSubDuplicate :: IORef Int,
    ServerStats -> IORef Int
qSubProhibited :: IORef Int,
    ServerStats -> IORef Int
qSubEnd :: IORef Int,
    ServerStats -> IORef Int
qSubEndB :: IORef Int,
    ServerStats -> IORef Int
ntfCreated :: IORef Int,
    ServerStats -> IORef Int
ntfNewCreated :: IORef Int, -- credentials created at the time of queue creation
    ServerStats -> IORef Int
ntfDeleted :: IORef Int,
    ServerStats -> IORef Int
ntfDeletedB :: IORef Int,
    ServerStats -> IORef Int
ntfSub :: IORef Int,
    ServerStats -> IORef Int
ntfSubB :: IORef Int,
    ServerStats -> IORef Int
ntfSubAuth :: IORef Int,
    ServerStats -> IORef Int
ntfSubDuplicate :: IORef Int,
    ServerStats -> IORef Int
msgSent :: IORef Int,
    ServerStats -> IORef Int
msgSentAuth :: IORef Int,
    ServerStats -> IORef Int
msgSentQuota :: IORef Int,
    ServerStats -> IORef Int
msgSentLarge :: IORef Int,
    ServerStats -> IORef Int
msgSentBlock :: IORef Int,
    ServerStats -> IORef Int
msgRecv :: IORef Int,
    ServerStats -> IORef TimeBuckets
msgRecvAckTimes :: IORef TimeBuckets,
    ServerStats -> IORef Int
msgRecvGet :: IORef Int,
    ServerStats -> IORef Int
msgGet :: IORef Int,
    ServerStats -> IORef Int
msgGetNoMsg :: IORef Int,
    ServerStats -> IORef Int
msgGetAuth :: IORef Int,
    ServerStats -> IORef Int
msgGetDuplicate :: IORef Int,
    ServerStats -> IORef Int
msgGetProhibited :: IORef Int,
    ServerStats -> IORef Int
msgExpired :: IORef Int,
    ServerStats -> PeriodStats
activeQueues :: PeriodStats,
    -- subscribedQueues :: PeriodStats, -- this stat uses too much memory
    ServerStats -> IORef Int
msgSentNtf :: IORef Int, -- sent messages with NTF flag
    ServerStats -> IORef Int
msgRecvNtf :: IORef Int, -- received messages with NTF flag
    ServerStats -> PeriodStats
activeQueuesNtf :: PeriodStats,
    ServerStats -> IORef Int
msgNtfs :: IORef Int, -- messages notications delivered to NTF server (<= msgSentNtf)
    ServerStats -> IORef Int
msgNtfsB :: IORef Int, -- messages notication batches delivered to NTF server
    ServerStats -> IORef Int
msgNtfNoSub :: IORef Int, -- no subscriber to notifications (e.g., NTF server not connected)
    ServerStats -> IORef Int
msgNtfLost :: IORef Int, -- notification is lost because NTF delivery queue is full
    ServerStats -> IORef Int
msgNtfExpired :: IORef Int, -- expired
    ServerStats -> ProxyStats
pRelays :: ProxyStats,
    ServerStats -> ProxyStats
pRelaysOwn :: ProxyStats,
    ServerStats -> ProxyStats
pMsgFwds :: ProxyStats,
    ServerStats -> ProxyStats
pMsgFwdsOwn :: ProxyStats,
    ServerStats -> IORef Int
pMsgFwdsRecv :: IORef Int,
    ServerStats -> ServiceStats
rcvServices :: ServiceStats,
    ServerStats -> ServiceStats
ntfServices :: ServiceStats,
    ServerStats -> IORef Int
qCount :: IORef Int,
    ServerStats -> IORef Int
msgCount :: IORef Int,
    ServerStats -> IORef Int
ntfCount :: IORef Int
  }

data ServerStatsData = ServerStatsData
  { ServerStatsData -> UTCTime
_fromTime :: UTCTime,
    ServerStatsData -> Int
_qCreated :: Int,
    ServerStatsData -> Int
_qSecured :: Int,
    ServerStatsData -> Int
_qDeletedAll :: Int,
    ServerStatsData -> Int
_qDeletedAllB :: Int,
    ServerStatsData -> Int
_qDeletedNew :: Int,
    ServerStatsData -> Int
_qDeletedSecured :: Int,
    ServerStatsData -> Int
_qBlocked :: Int,
    ServerStatsData -> Int
_qSub :: Int,
    ServerStatsData -> Int
_qSubAllB :: Int,
    ServerStatsData -> Int
_qSubAuth :: Int,
    ServerStatsData -> Int
_qSubDuplicate :: Int,
    ServerStatsData -> Int
_qSubProhibited :: Int,
    ServerStatsData -> Int
_qSubEnd :: Int,
    ServerStatsData -> Int
_qSubEndB :: Int,
    ServerStatsData -> Int
_ntfCreated :: Int,
    ServerStatsData -> Int
_ntfNewCreated :: Int,
    ServerStatsData -> Int
_ntfDeleted :: Int,
    ServerStatsData -> Int
_ntfDeletedB :: Int,
    ServerStatsData -> Int
_ntfSub :: Int,
    ServerStatsData -> Int
_ntfSubB :: Int,
    ServerStatsData -> Int
_ntfSubAuth :: Int,
    ServerStatsData -> Int
_ntfSubDuplicate :: Int,
    ServerStatsData -> Int
_msgSent :: Int,
    ServerStatsData -> Int
_msgSentAuth :: Int,
    ServerStatsData -> Int
_msgSentQuota :: Int,
    ServerStatsData -> Int
_msgSentLarge :: Int,
    ServerStatsData -> Int
_msgSentBlock :: Int,
    ServerStatsData -> Int
_msgRecv :: Int,
    ServerStatsData -> TimeBuckets
_msgRecvAckTimes :: TimeBuckets,
    ServerStatsData -> Int
_msgRecvGet :: Int,
    ServerStatsData -> Int
_msgGet :: Int,
    ServerStatsData -> Int
_msgGetNoMsg :: Int,
    ServerStatsData -> Int
_msgGetAuth :: Int,
    ServerStatsData -> Int
_msgGetDuplicate :: Int,
    ServerStatsData -> Int
_msgGetProhibited :: Int,
    ServerStatsData -> Int
_msgExpired :: Int,
    ServerStatsData -> PeriodStatsData
_activeQueues :: PeriodStatsData,
    ServerStatsData -> Int
_msgSentNtf :: Int,
    ServerStatsData -> Int
_msgRecvNtf :: Int,
    ServerStatsData -> PeriodStatsData
_activeQueuesNtf :: PeriodStatsData,
    ServerStatsData -> Int
_msgNtfs :: Int,
    ServerStatsData -> Int
_msgNtfsB :: Int,
    ServerStatsData -> Int
_msgNtfNoSub :: Int,
    ServerStatsData -> Int
_msgNtfLost :: Int,
    ServerStatsData -> Int
_msgNtfExpired :: Int,
    ServerStatsData -> ProxyStatsData
_pRelays :: ProxyStatsData,
    ServerStatsData -> ProxyStatsData
_pRelaysOwn :: ProxyStatsData,
    ServerStatsData -> ProxyStatsData
_pMsgFwds :: ProxyStatsData,
    ServerStatsData -> ProxyStatsData
_pMsgFwdsOwn :: ProxyStatsData,
    ServerStatsData -> Int
_pMsgFwdsRecv :: Int,
    ServerStatsData -> ServiceStatsData
_ntfServices :: ServiceStatsData,
    ServerStatsData -> ServiceStatsData
_rcvServices :: ServiceStatsData,
    ServerStatsData -> Int
_qCount :: Int,
    ServerStatsData -> Int
_msgCount :: Int,
    ServerStatsData -> Int
_ntfCount :: Int
  }
  deriving (Int -> ServerStatsData -> ShowS
[ServerStatsData] -> ShowS
ServerStatsData -> String
(Int -> ServerStatsData -> ShowS)
-> (ServerStatsData -> String)
-> ([ServerStatsData] -> ShowS)
-> Show ServerStatsData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ServerStatsData -> ShowS
showsPrec :: Int -> ServerStatsData -> ShowS
$cshow :: ServerStatsData -> String
show :: ServerStatsData -> String
$cshowList :: [ServerStatsData] -> ShowS
showList :: [ServerStatsData] -> ShowS
Show)

newServerStats :: UTCTime -> IO ServerStats
newServerStats :: UTCTime -> IO ServerStats
newServerStats UTCTime
ts = do
  IORef UTCTime
fromTime <- UTCTime -> IO (IORef UTCTime)
forall a. a -> IO (IORef a)
newIORef UTCTime
ts
  IORef Int
qCreated <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
qSecured <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
qDeletedAll <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
qDeletedAllB <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
qDeletedNew <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
qDeletedSecured <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
qBlocked <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
qSub <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
qSubAllB <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
qSubAuth <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
qSubDuplicate <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
qSubProhibited <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
qSubEnd <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
qSubEndB <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
ntfCreated <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
ntfNewCreated <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
ntfDeleted <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
ntfDeletedB <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
ntfSub <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
ntfSubB <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
ntfSubAuth <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
ntfSubDuplicate <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
msgSent <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
msgSentAuth <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
msgSentQuota <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
msgSentLarge <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
msgSentBlock <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
msgRecv <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef TimeBuckets
msgRecvAckTimes <- TimeBuckets -> IO (IORef TimeBuckets)
forall a. a -> IO (IORef a)
newIORef (TimeBuckets -> IO (IORef TimeBuckets))
-> TimeBuckets -> IO (IORef TimeBuckets)
forall a b. (a -> b) -> a -> b
$ Int64 -> Int64 -> IntMap Int -> TimeBuckets
TimeBuckets Int64
0 Int64
0 IntMap Int
forall a. IntMap a
IM.empty
  IORef Int
msgRecvGet <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
msgGet <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
msgGetNoMsg <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
msgGetAuth <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
msgGetDuplicate <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
msgGetProhibited <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
msgExpired <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  PeriodStats
activeQueues <- IO PeriodStats
newPeriodStats
  IORef Int
msgSentNtf <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
msgRecvNtf <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  PeriodStats
activeQueuesNtf <- IO PeriodStats
newPeriodStats
  IORef Int
msgNtfs <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
msgNtfsB <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
msgNtfNoSub <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
msgNtfLost <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
msgNtfExpired <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  ProxyStats
pRelays <- IO ProxyStats
newProxyStats
  ProxyStats
pRelaysOwn <- IO ProxyStats
newProxyStats
  ProxyStats
pMsgFwds <- IO ProxyStats
newProxyStats
  ProxyStats
pMsgFwdsOwn <- IO ProxyStats
newProxyStats
  IORef Int
pMsgFwdsRecv <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  ServiceStats
rcvServices <- IO ServiceStats
newServiceStats
  ServiceStats
ntfServices <- IO ServiceStats
newServiceStats
  IORef Int
qCount <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
msgCount <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
ntfCount <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  ServerStats -> IO ServerStats
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
    ServerStats
      { IORef UTCTime
fromTime :: IORef UTCTime
fromTime :: IORef UTCTime
fromTime,
        IORef Int
qCreated :: IORef Int
qCreated :: IORef Int
qCreated,
        IORef Int
qSecured :: IORef Int
qSecured :: IORef Int
qSecured,
        IORef Int
qDeletedAll :: IORef Int
qDeletedAll :: IORef Int
qDeletedAll,
        IORef Int
qDeletedAllB :: IORef Int
qDeletedAllB :: IORef Int
qDeletedAllB,
        IORef Int
qDeletedNew :: IORef Int
qDeletedNew :: IORef Int
qDeletedNew,
        IORef Int
qDeletedSecured :: IORef Int
qDeletedSecured :: IORef Int
qDeletedSecured,
        IORef Int
qBlocked :: IORef Int
qBlocked :: IORef Int
qBlocked,
        IORef Int
qSub :: IORef Int
qSub :: IORef Int
qSub,
        IORef Int
qSubAllB :: IORef Int
qSubAllB :: IORef Int
qSubAllB,
        IORef Int
qSubAuth :: IORef Int
qSubAuth :: IORef Int
qSubAuth,
        IORef Int
qSubDuplicate :: IORef Int
qSubDuplicate :: IORef Int
qSubDuplicate,
        IORef Int
qSubProhibited :: IORef Int
qSubProhibited :: IORef Int
qSubProhibited,
        IORef Int
qSubEnd :: IORef Int
qSubEnd :: IORef Int
qSubEnd,
        IORef Int
qSubEndB :: IORef Int
qSubEndB :: IORef Int
qSubEndB,
        IORef Int
ntfCreated :: IORef Int
ntfCreated :: IORef Int
ntfCreated,
        IORef Int
ntfNewCreated :: IORef Int
ntfNewCreated :: IORef Int
ntfNewCreated,
        IORef Int
ntfDeleted :: IORef Int
ntfDeleted :: IORef Int
ntfDeleted,
        IORef Int
ntfDeletedB :: IORef Int
ntfDeletedB :: IORef Int
ntfDeletedB,
        IORef Int
ntfSub :: IORef Int
ntfSub :: IORef Int
ntfSub,
        IORef Int
ntfSubB :: IORef Int
ntfSubB :: IORef Int
ntfSubB,
        IORef Int
ntfSubAuth :: IORef Int
ntfSubAuth :: IORef Int
ntfSubAuth,
        IORef Int
ntfSubDuplicate :: IORef Int
ntfSubDuplicate :: IORef Int
ntfSubDuplicate,
        IORef Int
msgSent :: IORef Int
msgSent :: IORef Int
msgSent,
        IORef Int
msgSentAuth :: IORef Int
msgSentAuth :: IORef Int
msgSentAuth,
        IORef Int
msgSentQuota :: IORef Int
msgSentQuota :: IORef Int
msgSentQuota,
        IORef Int
msgSentLarge :: IORef Int
msgSentLarge :: IORef Int
msgSentLarge,
        IORef Int
msgSentBlock :: IORef Int
msgSentBlock :: IORef Int
msgSentBlock,
        IORef Int
msgRecv :: IORef Int
msgRecv :: IORef Int
msgRecv,
        IORef TimeBuckets
msgRecvAckTimes :: IORef TimeBuckets
msgRecvAckTimes :: IORef TimeBuckets
msgRecvAckTimes,
        IORef Int
msgRecvGet :: IORef Int
msgRecvGet :: IORef Int
msgRecvGet,
        IORef Int
msgGet :: IORef Int
msgGet :: IORef Int
msgGet,
        IORef Int
msgGetNoMsg :: IORef Int
msgGetNoMsg :: IORef Int
msgGetNoMsg,
        IORef Int
msgGetAuth :: IORef Int
msgGetAuth :: IORef Int
msgGetAuth,
        IORef Int
msgGetDuplicate :: IORef Int
msgGetDuplicate :: IORef Int
msgGetDuplicate,
        IORef Int
msgGetProhibited :: IORef Int
msgGetProhibited :: IORef Int
msgGetProhibited,
        IORef Int
msgExpired :: IORef Int
msgExpired :: IORef Int
msgExpired,
        PeriodStats
activeQueues :: PeriodStats
activeQueues :: PeriodStats
activeQueues,
        IORef Int
msgSentNtf :: IORef Int
msgSentNtf :: IORef Int
msgSentNtf,
        IORef Int
msgRecvNtf :: IORef Int
msgRecvNtf :: IORef Int
msgRecvNtf,
        PeriodStats
activeQueuesNtf :: PeriodStats
activeQueuesNtf :: PeriodStats
activeQueuesNtf,
        IORef Int
msgNtfs :: IORef Int
msgNtfs :: IORef Int
msgNtfs,
        IORef Int
msgNtfsB :: IORef Int
msgNtfsB :: IORef Int
msgNtfsB,
        IORef Int
msgNtfNoSub :: IORef Int
msgNtfNoSub :: IORef Int
msgNtfNoSub,
        IORef Int
msgNtfLost :: IORef Int
msgNtfLost :: IORef Int
msgNtfLost,
        IORef Int
msgNtfExpired :: IORef Int
msgNtfExpired :: IORef Int
msgNtfExpired,
        ProxyStats
pRelays :: ProxyStats
pRelays :: ProxyStats
pRelays,
        ProxyStats
pRelaysOwn :: ProxyStats
pRelaysOwn :: ProxyStats
pRelaysOwn,
        ProxyStats
pMsgFwds :: ProxyStats
pMsgFwds :: ProxyStats
pMsgFwds,
        ProxyStats
pMsgFwdsOwn :: ProxyStats
pMsgFwdsOwn :: ProxyStats
pMsgFwdsOwn,
        IORef Int
pMsgFwdsRecv :: IORef Int
pMsgFwdsRecv :: IORef Int
pMsgFwdsRecv,
        ServiceStats
rcvServices :: ServiceStats
rcvServices :: ServiceStats
rcvServices,
        ServiceStats
ntfServices :: ServiceStats
ntfServices :: ServiceStats
ntfServices,
        IORef Int
qCount :: IORef Int
qCount :: IORef Int
qCount,
        IORef Int
msgCount :: IORef Int
msgCount :: IORef Int
msgCount,
        IORef Int
ntfCount :: IORef Int
ntfCount :: IORef Int
ntfCount
      }

getServerStatsData :: ServerStats -> IO ServerStatsData
getServerStatsData :: ServerStats -> IO ServerStatsData
getServerStatsData ServerStats
s = do
  UTCTime
_fromTime <- IORef UTCTime -> IO UTCTime
forall a. IORef a -> IO a
readIORef (IORef UTCTime -> IO UTCTime) -> IORef UTCTime -> IO UTCTime
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef UTCTime
fromTime ServerStats
s
  Int
_qCreated <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
qCreated ServerStats
s
  Int
_qSecured <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
qSecured ServerStats
s
  Int
_qDeletedAll <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
qDeletedAll ServerStats
s
  Int
_qDeletedAllB <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
qDeletedAllB ServerStats
s
  Int
_qDeletedNew <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
qDeletedNew ServerStats
s
  Int
_qDeletedSecured <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
qDeletedSecured ServerStats
s
  Int
_qBlocked <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
qBlocked ServerStats
s
  Int
_qSub <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
qSub ServerStats
s
  Int
_qSubAllB <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
qSubAllB ServerStats
s
  Int
_qSubAuth <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
qSubAuth ServerStats
s
  Int
_qSubDuplicate <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
qSubDuplicate ServerStats
s
  Int
_qSubProhibited <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
qSubProhibited ServerStats
s
  Int
_qSubEnd <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
qSubEnd ServerStats
s
  Int
_qSubEndB <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
qSubEndB ServerStats
s
  Int
_ntfCreated <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
ntfCreated ServerStats
s
  Int
_ntfNewCreated <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
ntfNewCreated ServerStats
s
  Int
_ntfDeleted <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
ntfDeleted ServerStats
s
  Int
_ntfDeletedB <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
ntfDeletedB ServerStats
s
  Int
_ntfSub <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
ntfSub ServerStats
s
  Int
_ntfSubB <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
ntfSubB ServerStats
s
  Int
_ntfSubAuth <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
ntfSubAuth ServerStats
s
  Int
_ntfSubDuplicate <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
ntfSubDuplicate ServerStats
s
  Int
_msgSent <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
msgSent ServerStats
s
  Int
_msgSentAuth <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
msgSentAuth ServerStats
s
  Int
_msgSentQuota <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
msgSentQuota ServerStats
s
  Int
_msgSentLarge <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
msgSentLarge ServerStats
s
  Int
_msgSentBlock <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
msgSentBlock ServerStats
s
  Int
_msgRecv <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
msgRecv ServerStats
s
  TimeBuckets
_msgRecvAckTimes <- IORef TimeBuckets -> IO TimeBuckets
forall a. IORef a -> IO a
readIORef (IORef TimeBuckets -> IO TimeBuckets)
-> IORef TimeBuckets -> IO TimeBuckets
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef TimeBuckets
msgRecvAckTimes ServerStats
s
  Int
_msgRecvGet <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
msgRecvGet ServerStats
s
  Int
_msgGet <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
msgGet ServerStats
s
  Int
_msgGetNoMsg <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
msgGetNoMsg ServerStats
s
  Int
_msgGetAuth <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
msgGetAuth ServerStats
s
  Int
_msgGetDuplicate <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
msgGetDuplicate ServerStats
s
  Int
_msgGetProhibited <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
msgGetProhibited ServerStats
s
  Int
_msgExpired <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
msgExpired ServerStats
s
  PeriodStatsData
_activeQueues <- PeriodStats -> IO PeriodStatsData
getPeriodStatsData (PeriodStats -> IO PeriodStatsData)
-> PeriodStats -> IO PeriodStatsData
forall a b. (a -> b) -> a -> b
$ ServerStats -> PeriodStats
activeQueues ServerStats
s
  Int
_msgSentNtf <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
msgSentNtf ServerStats
s
  Int
_msgRecvNtf <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
msgRecvNtf ServerStats
s
  PeriodStatsData
_activeQueuesNtf <- PeriodStats -> IO PeriodStatsData
getPeriodStatsData (PeriodStats -> IO PeriodStatsData)
-> PeriodStats -> IO PeriodStatsData
forall a b. (a -> b) -> a -> b
$ ServerStats -> PeriodStats
activeQueuesNtf ServerStats
s
  Int
_msgNtfs <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
msgNtfs ServerStats
s
  Int
_msgNtfsB <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
msgNtfsB ServerStats
s
  Int
_msgNtfNoSub <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
msgNtfNoSub ServerStats
s
  Int
_msgNtfLost <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
msgNtfLost ServerStats
s
  Int
_msgNtfExpired <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
msgNtfExpired ServerStats
s
  ProxyStatsData
_pRelays <- ProxyStats -> IO ProxyStatsData
getProxyStatsData (ProxyStats -> IO ProxyStatsData)
-> ProxyStats -> IO ProxyStatsData
forall a b. (a -> b) -> a -> b
$ ServerStats -> ProxyStats
pRelays ServerStats
s
  ProxyStatsData
_pRelaysOwn <- ProxyStats -> IO ProxyStatsData
getProxyStatsData (ProxyStats -> IO ProxyStatsData)
-> ProxyStats -> IO ProxyStatsData
forall a b. (a -> b) -> a -> b
$ ServerStats -> ProxyStats
pRelaysOwn ServerStats
s
  ProxyStatsData
_pMsgFwds <- ProxyStats -> IO ProxyStatsData
getProxyStatsData (ProxyStats -> IO ProxyStatsData)
-> ProxyStats -> IO ProxyStatsData
forall a b. (a -> b) -> a -> b
$ ServerStats -> ProxyStats
pMsgFwds ServerStats
s
  ProxyStatsData
_pMsgFwdsOwn <- ProxyStats -> IO ProxyStatsData
getProxyStatsData (ProxyStats -> IO ProxyStatsData)
-> ProxyStats -> IO ProxyStatsData
forall a b. (a -> b) -> a -> b
$ ServerStats -> ProxyStats
pMsgFwdsOwn ServerStats
s
  Int
_pMsgFwdsRecv <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
pMsgFwdsRecv ServerStats
s
  ServiceStatsData
_rcvServices <- ServiceStats -> IO ServiceStatsData
getServiceStatsData (ServiceStats -> IO ServiceStatsData)
-> ServiceStats -> IO ServiceStatsData
forall a b. (a -> b) -> a -> b
$ ServerStats -> ServiceStats
rcvServices ServerStats
s
  ServiceStatsData
_ntfServices <- ServiceStats -> IO ServiceStatsData
getServiceStatsData (ServiceStats -> IO ServiceStatsData)
-> ServiceStats -> IO ServiceStatsData
forall a b. (a -> b) -> a -> b
$ ServerStats -> ServiceStats
ntfServices ServerStats
s
  Int
_qCount <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
qCount ServerStats
s
  Int
_msgCount <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
msgCount ServerStats
s
  Int
_ntfCount <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServerStats -> IORef Int
ntfCount ServerStats
s
  ServerStatsData -> IO ServerStatsData
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
    ServerStatsData
      { UTCTime
_fromTime :: UTCTime
_fromTime :: UTCTime
_fromTime,
        Int
_qCreated :: Int
_qCreated :: Int
_qCreated,
        Int
_qSecured :: Int
_qSecured :: Int
_qSecured,
        Int
_qDeletedAll :: Int
_qDeletedAll :: Int
_qDeletedAll,
        Int
_qDeletedAllB :: Int
_qDeletedAllB :: Int
_qDeletedAllB,
        Int
_qDeletedNew :: Int
_qDeletedNew :: Int
_qDeletedNew,
        Int
_qDeletedSecured :: Int
_qDeletedSecured :: Int
_qDeletedSecured,
        Int
_qBlocked :: Int
_qBlocked :: Int
_qBlocked,
        Int
_qSub :: Int
_qSub :: Int
_qSub,
        Int
_qSubAllB :: Int
_qSubAllB :: Int
_qSubAllB,
        Int
_qSubAuth :: Int
_qSubAuth :: Int
_qSubAuth,
        Int
_qSubDuplicate :: Int
_qSubDuplicate :: Int
_qSubDuplicate,
        Int
_qSubProhibited :: Int
_qSubProhibited :: Int
_qSubProhibited,
        Int
_qSubEnd :: Int
_qSubEnd :: Int
_qSubEnd,
        Int
_qSubEndB :: Int
_qSubEndB :: Int
_qSubEndB,
        Int
_ntfCreated :: Int
_ntfCreated :: Int
_ntfCreated,
        Int
_ntfNewCreated :: Int
_ntfNewCreated :: Int
_ntfNewCreated,
        Int
_ntfDeleted :: Int
_ntfDeleted :: Int
_ntfDeleted,
        Int
_ntfDeletedB :: Int
_ntfDeletedB :: Int
_ntfDeletedB,
        Int
_ntfSub :: Int
_ntfSub :: Int
_ntfSub,
        Int
_ntfSubB :: Int
_ntfSubB :: Int
_ntfSubB,
        Int
_ntfSubAuth :: Int
_ntfSubAuth :: Int
_ntfSubAuth,
        Int
_ntfSubDuplicate :: Int
_ntfSubDuplicate :: Int
_ntfSubDuplicate,
        Int
_msgSent :: Int
_msgSent :: Int
_msgSent,
        Int
_msgSentAuth :: Int
_msgSentAuth :: Int
_msgSentAuth,
        Int
_msgSentQuota :: Int
_msgSentQuota :: Int
_msgSentQuota,
        Int
_msgSentLarge :: Int
_msgSentLarge :: Int
_msgSentLarge,
        Int
_msgSentBlock :: Int
_msgSentBlock :: Int
_msgSentBlock,
        Int
_msgRecv :: Int
_msgRecv :: Int
_msgRecv,
        TimeBuckets
_msgRecvAckTimes :: TimeBuckets
_msgRecvAckTimes :: TimeBuckets
_msgRecvAckTimes,
        Int
_msgRecvGet :: Int
_msgRecvGet :: Int
_msgRecvGet,
        Int
_msgGet :: Int
_msgGet :: Int
_msgGet,
        Int
_msgGetNoMsg :: Int
_msgGetNoMsg :: Int
_msgGetNoMsg,
        Int
_msgGetAuth :: Int
_msgGetAuth :: Int
_msgGetAuth,
        Int
_msgGetDuplicate :: Int
_msgGetDuplicate :: Int
_msgGetDuplicate,
        Int
_msgGetProhibited :: Int
_msgGetProhibited :: Int
_msgGetProhibited,
        Int
_msgExpired :: Int
_msgExpired :: Int
_msgExpired,
        PeriodStatsData
_activeQueues :: PeriodStatsData
_activeQueues :: PeriodStatsData
_activeQueues,
        Int
_msgSentNtf :: Int
_msgSentNtf :: Int
_msgSentNtf,
        Int
_msgRecvNtf :: Int
_msgRecvNtf :: Int
_msgRecvNtf,
        PeriodStatsData
_activeQueuesNtf :: PeriodStatsData
_activeQueuesNtf :: PeriodStatsData
_activeQueuesNtf,
        Int
_msgNtfs :: Int
_msgNtfs :: Int
_msgNtfs,
        Int
_msgNtfsB :: Int
_msgNtfsB :: Int
_msgNtfsB,
        Int
_msgNtfNoSub :: Int
_msgNtfNoSub :: Int
_msgNtfNoSub,
        Int
_msgNtfLost :: Int
_msgNtfLost :: Int
_msgNtfLost,
        Int
_msgNtfExpired :: Int
_msgNtfExpired :: Int
_msgNtfExpired,
        ProxyStatsData
_pRelays :: ProxyStatsData
_pRelays :: ProxyStatsData
_pRelays,
        ProxyStatsData
_pRelaysOwn :: ProxyStatsData
_pRelaysOwn :: ProxyStatsData
_pRelaysOwn,
        ProxyStatsData
_pMsgFwds :: ProxyStatsData
_pMsgFwds :: ProxyStatsData
_pMsgFwds,
        ProxyStatsData
_pMsgFwdsOwn :: ProxyStatsData
_pMsgFwdsOwn :: ProxyStatsData
_pMsgFwdsOwn,
        Int
_pMsgFwdsRecv :: Int
_pMsgFwdsRecv :: Int
_pMsgFwdsRecv,
        ServiceStatsData
_rcvServices :: ServiceStatsData
_rcvServices :: ServiceStatsData
_rcvServices,
        ServiceStatsData
_ntfServices :: ServiceStatsData
_ntfServices :: ServiceStatsData
_ntfServices,
        Int
_qCount :: Int
_qCount :: Int
_qCount,
        Int
_msgCount :: Int
_msgCount :: Int
_msgCount,
        Int
_ntfCount :: Int
_ntfCount :: Int
_ntfCount
      }

-- this function is not thread safe, it is used on server start only
setServerStats :: ServerStats -> ServerStatsData -> IO ()
setServerStats :: ServerStats -> ServerStatsData -> IO ()
setServerStats ServerStats
s ServerStatsData
d = do
  IORef UTCTime -> UTCTime -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef UTCTime
fromTime ServerStats
s) (UTCTime -> IO ()) -> UTCTime -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> UTCTime
_fromTime ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
qCreated ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_qCreated ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
qSecured ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_qSecured ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
qDeletedAll ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_qDeletedAll ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
qDeletedAllB ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_qDeletedAllB ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
qDeletedNew ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_qDeletedNew ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
qDeletedSecured ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_qDeletedSecured ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
qBlocked ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_qBlocked ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
qSub ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_qSub ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
qSubAllB ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_qSubAllB ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
qSubAuth ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_qSubAuth ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
qSubDuplicate ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_qSubDuplicate ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
qSubProhibited ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_qSubProhibited ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
qSubEnd ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_qSubEnd ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
qSubEndB ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_qSubEndB ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
ntfCreated ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_ntfCreated ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
ntfNewCreated ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_ntfNewCreated ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
ntfDeleted ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_ntfDeleted ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
ntfDeletedB ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_ntfDeletedB ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
ntfSub ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_ntfSub ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
ntfSubB ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_ntfSubB ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
ntfSubAuth ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_ntfSubAuth ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
ntfSubDuplicate ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_ntfSubDuplicate ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
msgSent ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_msgSent ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
msgSentAuth ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_msgSentAuth ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
msgSentQuota ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_msgSentQuota ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
msgSentLarge ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_msgSentLarge ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
msgSentBlock ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_msgSentBlock ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
msgRecv ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_msgRecv ServerStatsData
d
  IORef TimeBuckets -> TimeBuckets -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef TimeBuckets
msgRecvAckTimes ServerStats
s) (TimeBuckets -> IO ()) -> TimeBuckets -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> TimeBuckets
_msgRecvAckTimes ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
msgRecvGet ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_msgRecvGet ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
msgGet ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_msgGet ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
msgGetNoMsg ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_msgGetNoMsg ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
msgGetAuth ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_msgGetAuth ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
msgGetDuplicate ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_msgGetDuplicate ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
msgGetProhibited ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_msgGetProhibited ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
msgExpired ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_msgExpired ServerStatsData
d
  PeriodStats -> PeriodStatsData -> IO ()
setPeriodStats (ServerStats -> PeriodStats
activeQueues ServerStats
s) (ServerStatsData -> PeriodStatsData
_activeQueues ServerStatsData
d)
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
msgSentNtf ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_msgSentNtf ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
msgRecvNtf ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_msgRecvNtf ServerStatsData
d
  PeriodStats -> PeriodStatsData -> IO ()
setPeriodStats (ServerStats -> PeriodStats
activeQueuesNtf ServerStats
s) (ServerStatsData -> PeriodStatsData
_activeQueuesNtf ServerStatsData
d)
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
msgNtfs ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_msgNtfs ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
msgNtfsB ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_msgNtfsB ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
msgNtfNoSub ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_msgNtfNoSub ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
msgNtfLost ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_msgNtfLost ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
msgNtfExpired ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_msgNtfExpired ServerStatsData
d
  ProxyStats -> ProxyStatsData -> IO ()
setProxyStats (ServerStats -> ProxyStats
pRelays ServerStats
s) (ProxyStatsData -> IO ()) -> ProxyStatsData -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> ProxyStatsData
_pRelays ServerStatsData
d
  ProxyStats -> ProxyStatsData -> IO ()
setProxyStats (ServerStats -> ProxyStats
pRelaysOwn ServerStats
s) (ProxyStatsData -> IO ()) -> ProxyStatsData -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> ProxyStatsData
_pRelaysOwn ServerStatsData
d
  ProxyStats -> ProxyStatsData -> IO ()
setProxyStats (ServerStats -> ProxyStats
pMsgFwds ServerStats
s) (ProxyStatsData -> IO ()) -> ProxyStatsData -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> ProxyStatsData
_pMsgFwds ServerStatsData
d
  ProxyStats -> ProxyStatsData -> IO ()
setProxyStats (ServerStats -> ProxyStats
pMsgFwdsOwn ServerStats
s) (ProxyStatsData -> IO ()) -> ProxyStatsData -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> ProxyStatsData
_pMsgFwdsOwn ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
pMsgFwdsRecv ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_pMsgFwdsRecv ServerStatsData
d
  ServiceStats -> ServiceStatsData -> IO ()
setServiceStats (ServerStats -> ServiceStats
rcvServices ServerStats
s) (ServiceStatsData -> IO ()) -> ServiceStatsData -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> ServiceStatsData
_rcvServices ServerStatsData
d
  ServiceStats -> ServiceStatsData -> IO ()
setServiceStats (ServerStats -> ServiceStats
ntfServices ServerStats
s) (ServiceStatsData -> IO ()) -> ServiceStatsData -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> ServiceStatsData
_ntfServices ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
qCount ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_qCount ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
msgCount ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_msgCount ServerStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServerStats -> IORef Int
ntfCount ServerStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServerStatsData -> Int
_ntfCount ServerStatsData
d

instance StrEncoding ServerStatsData where
  strEncode :: ServerStatsData -> ByteString
strEncode ServerStatsData
d =
    [ByteString] -> ByteString
B.unlines
      [ ByteString
"fromTime=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> UTCTime -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> UTCTime
_fromTime ServerStatsData
d),
        ByteString
"qCreated=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_qCreated ServerStatsData
d),
        ByteString
"qSecured=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_qSecured ServerStatsData
d),
        ByteString
"qDeletedAll=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_qDeletedAll ServerStatsData
d),
        ByteString
"qDeletedNew=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_qDeletedNew ServerStatsData
d),
        ByteString
"qDeletedSecured=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_qDeletedSecured ServerStatsData
d),
        ByteString
"qDeletedAllB=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_qDeletedAllB ServerStatsData
d),
        ByteString
"qBlocked=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_qBlocked ServerStatsData
d),
        ByteString
"qCount=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_qCount ServerStatsData
d),
        ByteString
"qSub=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_qSub ServerStatsData
d),
        ByteString
"qSubAllB=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_qSubAllB ServerStatsData
d),
        ByteString
"qSubAuth=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_qSubAuth ServerStatsData
d),
        ByteString
"qSubDuplicate=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_qSubDuplicate ServerStatsData
d),
        ByteString
"qSubProhibited=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_qSubProhibited ServerStatsData
d),
        ByteString
"qSubEnd=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_qSubEnd ServerStatsData
d),
        ByteString
"qSubEndB=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_qSubEndB ServerStatsData
d),
        ByteString
"ntfCreated=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_ntfCreated ServerStatsData
d),
        ByteString
"ntfNewCreated=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_ntfNewCreated ServerStatsData
d),
        ByteString
"ntfDeleted=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_ntfDeleted ServerStatsData
d),
        ByteString
"ntfDeletedB=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_ntfDeletedB ServerStatsData
d),
        ByteString
"ntfSub=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_ntfSub ServerStatsData
d),
        ByteString
"ntfSubB=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_ntfSubB ServerStatsData
d),
        ByteString
"ntfSubAuth=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_ntfSubAuth ServerStatsData
d),
        ByteString
"ntfSubDuplicate=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_ntfSubDuplicate ServerStatsData
d),
        ByteString
"msgSent=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_msgSent ServerStatsData
d),
        ByteString
"msgSentAuth=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_msgSentAuth ServerStatsData
d),
        ByteString
"msgSentQuota=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_msgSentQuota ServerStatsData
d),
        ByteString
"msgSentLarge=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_msgSentLarge ServerStatsData
d),
        ByteString
"msgSentBlock=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_msgSentBlock ServerStatsData
d),
        ByteString
"msgRecv=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_msgRecv ServerStatsData
d),
        ByteString
"msgRecvGet=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_msgRecvGet ServerStatsData
d),
        ByteString
"msgGet=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_msgGet ServerStatsData
d),
        ByteString
"msgGetNoMsg=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_msgGetNoMsg ServerStatsData
d),
        ByteString
"msgGetAuth=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_msgGetAuth ServerStatsData
d),
        ByteString
"msgGetDuplicate=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_msgGetDuplicate ServerStatsData
d),
        ByteString
"msgGetProhibited=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_msgGetProhibited ServerStatsData
d),
        ByteString
"msgExpired=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_msgExpired ServerStatsData
d),
        ByteString
"msgSentNtf=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_msgSentNtf ServerStatsData
d),
        ByteString
"msgRecvNtf=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_msgRecvNtf ServerStatsData
d),
        ByteString
"msgNtfs=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_msgNtfs ServerStatsData
d),
        ByteString
"msgNtfsB=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_msgNtfsB ServerStatsData
d),
        ByteString
"msgNtfNoSub=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_msgNtfNoSub ServerStatsData
d),
        ByteString
"msgNtfLost=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_msgNtfLost ServerStatsData
d),
        ByteString
"msgNtfExpired=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_msgNtfExpired ServerStatsData
d),
        ByteString
"activeQueues:",
        PeriodStatsData -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> PeriodStatsData
_activeQueues ServerStatsData
d),
        ByteString
"activeQueuesNtf:",
        PeriodStatsData -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> PeriodStatsData
_activeQueuesNtf ServerStatsData
d),
        ByteString
"pRelays:",
        ProxyStatsData -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> ProxyStatsData
_pRelays ServerStatsData
d),
        ByteString
"pRelaysOwn:",
        ProxyStatsData -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> ProxyStatsData
_pRelaysOwn ServerStatsData
d),
        ByteString
"pMsgFwds:",
        ProxyStatsData -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> ProxyStatsData
_pMsgFwds ServerStatsData
d),
        ByteString
"pMsgFwdsOwn:",
        ProxyStatsData -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> ProxyStatsData
_pMsgFwdsOwn ServerStatsData
d),
        ByteString
"pMsgFwdsRecv=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> Int
_pMsgFwdsRecv ServerStatsData
d),
        ByteString
"rcvServices:",
        ServiceStatsData -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> ServiceStatsData
_rcvServices ServerStatsData
d),
        ByteString
"ntfServices:",
        ServiceStatsData -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ServerStatsData -> ServiceStatsData
_ntfServices ServerStatsData
d)
      ]
  strP :: Parser ServerStatsData
strP = do
    UTCTime
_fromTime <- Parser ByteString ByteString
"fromTime=" Parser ByteString ByteString
-> Parser ByteString UTCTime -> Parser ByteString UTCTime
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString UTCTime
forall a. StrEncoding a => Parser a
strP Parser ByteString UTCTime
-> Parser ByteString () -> Parser ByteString UTCTime
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine
    Int
_qCreated <- Parser ByteString ByteString
"qCreated=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP Parser ByteString Int
-> Parser ByteString () -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine
    Int
_qSecured <- Parser ByteString ByteString
"qSecured=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP Parser ByteString Int
-> Parser ByteString () -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine
    (Int
_qDeletedAll, Int
_qDeletedNew, Int
_qDeletedSecured) <-
      (,Int
0,Int
0) (Int -> (Int, Int, Int))
-> Parser ByteString Int -> Parser ByteString (Int, Int, Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser ByteString ByteString
"qDeleted=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP Parser ByteString Int
-> Parser ByteString () -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine)
        Parser ByteString (Int, Int, Int)
-> Parser ByteString (Int, Int, Int)
-> Parser ByteString (Int, Int, Int)
forall a.
Parser ByteString a -> Parser ByteString a -> Parser ByteString a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ((,,) (Int -> Int -> Int -> (Int, Int, Int))
-> Parser ByteString Int
-> Parser ByteString (Int -> Int -> (Int, Int, Int))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser ByteString ByteString
"qDeletedAll=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP Parser ByteString Int
-> Parser ByteString () -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine) Parser ByteString (Int -> Int -> (Int, Int, Int))
-> Parser ByteString Int
-> Parser ByteString (Int -> (Int, Int, Int))
forall a b.
Parser ByteString (a -> b)
-> Parser ByteString a -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser ByteString ByteString
"qDeletedNew=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP Parser ByteString Int
-> Parser ByteString () -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine) Parser ByteString (Int -> (Int, Int, Int))
-> Parser ByteString Int -> Parser ByteString (Int, Int, Int)
forall a b.
Parser ByteString (a -> b)
-> Parser ByteString a -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser ByteString ByteString
"qDeletedSecured=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP Parser ByteString Int
-> Parser ByteString () -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine))
    Int
_qDeletedAllB <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"qDeletedAllB="
    Int
_qBlocked <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"qBlocked="
    Int
_qCount <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"qCount="
    Int
_qSub <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"qSub="
    Int
_qSubNoMsg <- ByteString -> Parser ByteString Int
skipInt ByteString
"qSubNoMsg=" -- skipping it for backward compatibility
    Int
_qSubAllB <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"qSubAllB="
    Int
_qSubAuth <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"qSubAuth="
    Int
_qSubDuplicate <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"qSubDuplicate="
    Int
_qSubProhibited <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"qSubProhibited="
    Int
_qSubEnd <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"qSubEnd="
    Int
_qSubEndB <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"qSubEndB="
    Int
_ntfCreated <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"ntfCreated="
    Int
_ntfNewCreated <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"ntfNewCreated="
    Int
_ntfDeleted <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"ntfDeleted="
    Int
_ntfDeletedB <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"ntfDeletedB="
    Int
_ntfSub <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"ntfSub="
    Int
_ntfSubB <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"ntfSubB="
    Int
_ntfSubAuth <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"ntfSubAuth="
    Int
_ntfSubDuplicate <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"ntfSubDuplicate="
    Int
_msgSent <- Parser ByteString ByteString
"msgSent=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP Parser ByteString Int
-> Parser ByteString () -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine
    Int
_msgSentAuth <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"msgSentAuth="
    Int
_msgSentQuota <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"msgSentQuota="
    Int
_msgSentLarge <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"msgSentLarge="
    Int
_msgSentBlock <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"msgSentBlock="
    Int
_msgRecv <- Parser ByteString ByteString
"msgRecv=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP Parser ByteString Int
-> Parser ByteString () -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine
    Int
_msgRecvGet <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"msgRecvGet="
    Int
_msgGet <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"msgGet="
    Int
_msgGetNoMsg <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"msgGetNoMsg="
    Int
_msgGetAuth <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"msgGetAuth="
    Int
_msgGetDuplicate <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"msgGetDuplicate="
    Int
_msgGetProhibited <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"msgGetProhibited="
    Int
_msgExpired <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"msgExpired="
    Int
_msgSentNtf <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"msgSentNtf="
    Int
_msgRecvNtf <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"msgRecvNtf="
    Int
_msgNtfs <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"msgNtfs="
    Int
_msgNtfsB <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"msgNtfsB="
    Int
_msgNtfNoSub <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"msgNtfNoSub="
    Int
_msgNtfLost <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"msgNtfLost="
    Int
_msgNtfExpired <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"msgNtfExpired="
    PeriodStatsData
_activeQueues <-
      Parser ByteString ByteString
-> Parser ByteString (Maybe ByteString)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Parser ByteString ByteString
"activeQueues:" Parser ByteString ByteString
-> Parser ByteString () -> Parser ByteString ByteString
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine) Parser ByteString (Maybe ByteString)
-> (Maybe ByteString -> Parser ByteString PeriodStatsData)
-> Parser ByteString PeriodStatsData
forall a b.
Parser ByteString a
-> (a -> Parser ByteString b) -> Parser ByteString b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
        Just ByteString
_ -> Parser ByteString PeriodStatsData
forall a. StrEncoding a => Parser a
strP Parser ByteString PeriodStatsData
-> Parser ByteString (Maybe ())
-> Parser ByteString PeriodStatsData
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString () -> Parser ByteString (Maybe ())
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser ByteString ()
A.endOfLine
        Maybe ByteString
_ -> do
          IntSet
_day <- Parser ByteString ByteString
"dayMsgQueues=" Parser ByteString ByteString
-> Parser ByteString IntSet -> Parser ByteString IntSet
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString IntSet
forall a. StrEncoding a => Parser a
strP Parser ByteString IntSet
-> Parser ByteString () -> Parser ByteString IntSet
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine
          IntSet
_week <- Parser ByteString ByteString
"weekMsgQueues=" Parser ByteString ByteString
-> Parser ByteString IntSet -> Parser ByteString IntSet
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString IntSet
forall a. StrEncoding a => Parser a
strP Parser ByteString IntSet
-> Parser ByteString () -> Parser ByteString IntSet
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine
          IntSet
_month <- Parser ByteString ByteString
"monthMsgQueues=" Parser ByteString ByteString
-> Parser ByteString IntSet -> Parser ByteString IntSet
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString IntSet
forall a. StrEncoding a => Parser a
strP Parser ByteString IntSet
-> Parser ByteString (Maybe ()) -> Parser ByteString IntSet
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString () -> Parser ByteString (Maybe ())
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser ByteString ()
A.endOfLine
          PeriodStatsData -> Parser ByteString PeriodStatsData
forall a. a -> Parser ByteString a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PeriodStatsData {IntSet
_day :: IntSet
_day :: IntSet
_day, IntSet
_week :: IntSet
_week :: IntSet
_week, IntSet
_month :: IntSet
_month :: IntSet
_month}
    PeriodStatsData
_subscribedQueues <-
      Parser ByteString ByteString
-> Parser ByteString (Maybe ByteString)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Parser ByteString ByteString
"subscribedQueues:" Parser ByteString ByteString
-> Parser ByteString () -> Parser ByteString ByteString
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine) Parser ByteString (Maybe ByteString)
-> (Maybe ByteString -> Parser ByteString PeriodStatsData)
-> Parser ByteString PeriodStatsData
forall a b.
Parser ByteString a
-> (a -> Parser ByteString b) -> Parser ByteString b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
        Just ByteString
_ -> PeriodStatsData
newPeriodStatsData PeriodStatsData
-> Parser ByteString PeriodStatsData
-> Parser ByteString PeriodStatsData
forall a b. a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (forall a. StrEncoding a => Parser a
strP @PeriodStatsData Parser ByteString PeriodStatsData
-> Parser ByteString (Maybe ())
-> Parser ByteString PeriodStatsData
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString () -> Parser ByteString (Maybe ())
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser ByteString ()
A.endOfLine)
        Maybe ByteString
_ -> PeriodStatsData -> Parser ByteString PeriodStatsData
forall a. a -> Parser ByteString a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PeriodStatsData
newPeriodStatsData
    PeriodStatsData
_activeQueuesNtf <-
      Parser ByteString ByteString
-> Parser ByteString (Maybe ByteString)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Parser ByteString ByteString
"activeQueuesNtf:" Parser ByteString ByteString
-> Parser ByteString () -> Parser ByteString ByteString
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine) Parser ByteString (Maybe ByteString)
-> (Maybe ByteString -> Parser ByteString PeriodStatsData)
-> Parser ByteString PeriodStatsData
forall a b.
Parser ByteString a
-> (a -> Parser ByteString b) -> Parser ByteString b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
        Just ByteString
_ -> Parser ByteString PeriodStatsData
forall a. StrEncoding a => Parser a
strP Parser ByteString PeriodStatsData
-> Parser ByteString (Maybe ())
-> Parser ByteString PeriodStatsData
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString () -> Parser ByteString (Maybe ())
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser ByteString ()
A.endOfLine
        Maybe ByteString
_ -> PeriodStatsData -> Parser ByteString PeriodStatsData
forall a. a -> Parser ByteString a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PeriodStatsData
newPeriodStatsData
    ProxyStatsData
_pRelays <- ByteString -> Parser ByteString ProxyStatsData
proxyStatsP ByteString
"pRelays:"
    ProxyStatsData
_pRelaysOwn <- ByteString -> Parser ByteString ProxyStatsData
proxyStatsP ByteString
"pRelaysOwn:"
    ProxyStatsData
_pMsgFwds <- ByteString -> Parser ByteString ProxyStatsData
proxyStatsP ByteString
"pMsgFwds:"
    ProxyStatsData
_pMsgFwdsOwn <- ByteString -> Parser ByteString ProxyStatsData
proxyStatsP ByteString
"pMsgFwdsOwn:"
    Int
_pMsgFwdsRecv <- ByteString -> Parser ByteString Int
forall {a}.
(StrEncoding a, Num a) =>
ByteString -> Parser ByteString a
opt ByteString
"pMsgFwdsRecv="
    ServiceStatsData
_rcvServices <- ByteString -> Parser ByteString ServiceStatsData
serviceStatsP ByteString
"rcvServices:"
    ServiceStatsData
_ntfServices <- ByteString -> Parser ByteString ServiceStatsData
serviceStatsP ByteString
"ntfServices:"
    ServerStatsData -> Parser ServerStatsData
forall a. a -> Parser ByteString a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
      ServerStatsData
        { UTCTime
_fromTime :: UTCTime
_fromTime :: UTCTime
_fromTime,
          Int
_qCreated :: Int
_qCreated :: Int
_qCreated,
          Int
_qSecured :: Int
_qSecured :: Int
_qSecured,
          Int
_qDeletedAll :: Int
_qDeletedAll :: Int
_qDeletedAll,
          Int
_qDeletedAllB :: Int
_qDeletedAllB :: Int
_qDeletedAllB,
          Int
_qDeletedNew :: Int
_qDeletedNew :: Int
_qDeletedNew,
          Int
_qDeletedSecured :: Int
_qDeletedSecured :: Int
_qDeletedSecured,
          Int
_qBlocked :: Int
_qBlocked :: Int
_qBlocked,
          Int
_qSub :: Int
_qSub :: Int
_qSub,
          Int
_qSubAllB :: Int
_qSubAllB :: Int
_qSubAllB,
          Int
_qSubAuth :: Int
_qSubAuth :: Int
_qSubAuth,
          Int
_qSubDuplicate :: Int
_qSubDuplicate :: Int
_qSubDuplicate,
          Int
_qSubProhibited :: Int
_qSubProhibited :: Int
_qSubProhibited,
          Int
_qSubEnd :: Int
_qSubEnd :: Int
_qSubEnd,
          Int
_qSubEndB :: Int
_qSubEndB :: Int
_qSubEndB,
          Int
_ntfCreated :: Int
_ntfCreated :: Int
_ntfCreated,
          Int
_ntfNewCreated :: Int
_ntfNewCreated :: Int
_ntfNewCreated,
          Int
_ntfDeleted :: Int
_ntfDeleted :: Int
_ntfDeleted,
          Int
_ntfDeletedB :: Int
_ntfDeletedB :: Int
_ntfDeletedB,
          Int
_ntfSub :: Int
_ntfSub :: Int
_ntfSub,
          Int
_ntfSubB :: Int
_ntfSubB :: Int
_ntfSubB,
          Int
_ntfSubAuth :: Int
_ntfSubAuth :: Int
_ntfSubAuth,
          Int
_ntfSubDuplicate :: Int
_ntfSubDuplicate :: Int
_ntfSubDuplicate,
          Int
_msgSent :: Int
_msgSent :: Int
_msgSent,
          Int
_msgSentAuth :: Int
_msgSentAuth :: Int
_msgSentAuth,
          Int
_msgSentQuota :: Int
_msgSentQuota :: Int
_msgSentQuota,
          Int
_msgSentLarge :: Int
_msgSentLarge :: Int
_msgSentLarge,
          Int
_msgSentBlock :: Int
_msgSentBlock :: Int
_msgSentBlock,
          Int
_msgRecv :: Int
_msgRecv :: Int
_msgRecv,
          _msgRecvAckTimes :: TimeBuckets
_msgRecvAckTimes = TimeBuckets
emptyTimeBuckets,
          Int
_msgRecvGet :: Int
_msgRecvGet :: Int
_msgRecvGet,
          Int
_msgGet :: Int
_msgGet :: Int
_msgGet,
          Int
_msgGetNoMsg :: Int
_msgGetNoMsg :: Int
_msgGetNoMsg,
          Int
_msgGetAuth :: Int
_msgGetAuth :: Int
_msgGetAuth,
          Int
_msgGetDuplicate :: Int
_msgGetDuplicate :: Int
_msgGetDuplicate,
          Int
_msgGetProhibited :: Int
_msgGetProhibited :: Int
_msgGetProhibited,
          Int
_msgExpired :: Int
_msgExpired :: Int
_msgExpired,
          Int
_msgSentNtf :: Int
_msgSentNtf :: Int
_msgSentNtf,
          Int
_msgRecvNtf :: Int
_msgRecvNtf :: Int
_msgRecvNtf,
          Int
_msgNtfs :: Int
_msgNtfs :: Int
_msgNtfs,
          Int
_msgNtfsB :: Int
_msgNtfsB :: Int
_msgNtfsB,
          Int
_msgNtfNoSub :: Int
_msgNtfNoSub :: Int
_msgNtfNoSub,
          Int
_msgNtfLost :: Int
_msgNtfLost :: Int
_msgNtfLost,
          Int
_msgNtfExpired :: Int
_msgNtfExpired :: Int
_msgNtfExpired,
          PeriodStatsData
_activeQueues :: PeriodStatsData
_activeQueues :: PeriodStatsData
_activeQueues,
          PeriodStatsData
_activeQueuesNtf :: PeriodStatsData
_activeQueuesNtf :: PeriodStatsData
_activeQueuesNtf,
          ProxyStatsData
_pRelays :: ProxyStatsData
_pRelays :: ProxyStatsData
_pRelays,
          ProxyStatsData
_pRelaysOwn :: ProxyStatsData
_pRelaysOwn :: ProxyStatsData
_pRelaysOwn,
          ProxyStatsData
_pMsgFwds :: ProxyStatsData
_pMsgFwds :: ProxyStatsData
_pMsgFwds,
          ProxyStatsData
_pMsgFwdsOwn :: ProxyStatsData
_pMsgFwdsOwn :: ProxyStatsData
_pMsgFwdsOwn,
          Int
_pMsgFwdsRecv :: Int
_pMsgFwdsRecv :: Int
_pMsgFwdsRecv,
          ServiceStatsData
_rcvServices :: ServiceStatsData
_rcvServices :: ServiceStatsData
_rcvServices,
          ServiceStatsData
_ntfServices :: ServiceStatsData
_ntfServices :: ServiceStatsData
_ntfServices,
          Int
_qCount :: Int
_qCount :: Int
_qCount,
          _msgCount :: Int
_msgCount = Int
0,
          _ntfCount :: Int
_ntfCount = Int
0
        }
    where
      opt :: ByteString -> Parser ByteString a
opt ByteString
s = ByteString -> Parser ByteString ByteString
A.string ByteString
s Parser ByteString ByteString
-> Parser ByteString a -> Parser ByteString a
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString a
forall a. StrEncoding a => Parser a
strP Parser ByteString a -> Parser ByteString () -> Parser ByteString a
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine Parser ByteString a -> Parser ByteString a -> Parser ByteString a
forall a.
Parser ByteString a -> Parser ByteString a -> Parser ByteString a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> a -> Parser ByteString a
forall a. a -> Parser ByteString a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
0
      skipInt :: ByteString -> Parser ByteString Int
skipInt ByteString
s = (Int
0 :: Int) Int -> Parser ByteString (Maybe ()) -> Parser ByteString Int
forall a b. a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Parser ByteString () -> Parser ByteString (Maybe ())
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (ByteString -> Parser ByteString ByteString
A.string ByteString
s Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall a. StrEncoding a => Parser a
strP @Int Parser ByteString Int
-> Parser ByteString () -> Parser ByteString ()
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString ()
A.endOfLine)
      proxyStatsP :: ByteString -> Parser ByteString ProxyStatsData
proxyStatsP ByteString
key =
        Parser ByteString () -> Parser ByteString (Maybe ())
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (ByteString -> Parser ByteString ByteString
A.string ByteString
key Parser ByteString ByteString
-> Parser ByteString () -> Parser ByteString ()
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ByteString ()
A.endOfLine) Parser ByteString (Maybe ())
-> (Maybe () -> Parser ByteString ProxyStatsData)
-> Parser ByteString ProxyStatsData
forall a b.
Parser ByteString a
-> (a -> Parser ByteString b) -> Parser ByteString b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
          Just ()
_ -> Parser ByteString ProxyStatsData
forall a. StrEncoding a => Parser a
strP Parser ByteString ProxyStatsData
-> Parser ByteString (Maybe ()) -> Parser ByteString ProxyStatsData
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString () -> Parser ByteString (Maybe ())
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser ByteString ()
A.endOfLine
          Maybe ()
_ -> ProxyStatsData -> Parser ByteString ProxyStatsData
forall a. a -> Parser ByteString a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ProxyStatsData
newProxyStatsData
      serviceStatsP :: ByteString -> Parser ByteString ServiceStatsData
serviceStatsP ByteString
key =
        Parser ByteString () -> Parser ByteString (Maybe ())
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (ByteString -> Parser ByteString ByteString
A.string ByteString
key Parser ByteString ByteString
-> Parser ByteString () -> Parser ByteString ()
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser ByteString ()
A.endOfLine) Parser ByteString (Maybe ())
-> (Maybe () -> Parser ByteString ServiceStatsData)
-> Parser ByteString ServiceStatsData
forall a b.
Parser ByteString a
-> (a -> Parser ByteString b) -> Parser ByteString b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
          Just ()
_ -> Parser ByteString ServiceStatsData
forall a. StrEncoding a => Parser a
strP Parser ByteString ServiceStatsData
-> Parser ByteString (Maybe ())
-> Parser ByteString ServiceStatsData
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString () -> Parser ByteString (Maybe ())
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser ByteString ()
A.endOfLine
          Maybe ()
_ -> ServiceStatsData -> Parser ByteString ServiceStatsData
forall a. a -> Parser ByteString a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ServiceStatsData
newServiceStatsData

data PeriodStats = PeriodStats
  { PeriodStats -> IORef IntSet
day :: IORef IntSet,
    PeriodStats -> IORef IntSet
week :: IORef IntSet,
    PeriodStats -> IORef IntSet
month :: IORef IntSet
  }

newPeriodStats :: IO PeriodStats
newPeriodStats :: IO PeriodStats
newPeriodStats = do
  IORef IntSet
day <- IntSet -> IO (IORef IntSet)
forall a. a -> IO (IORef a)
newIORef IntSet
IS.empty
  IORef IntSet
week <- IntSet -> IO (IORef IntSet)
forall a. a -> IO (IORef a)
newIORef IntSet
IS.empty
  IORef IntSet
month <- IntSet -> IO (IORef IntSet)
forall a. a -> IO (IORef a)
newIORef IntSet
IS.empty
  PeriodStats -> IO PeriodStats
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PeriodStats {IORef IntSet
day :: IORef IntSet
day :: IORef IntSet
day, IORef IntSet
week :: IORef IntSet
week :: IORef IntSet
week, IORef IntSet
month :: IORef IntSet
month :: IORef IntSet
month}

data PeriodStatsData = PeriodStatsData
  { PeriodStatsData -> IntSet
_day :: IntSet,
    PeriodStatsData -> IntSet
_week :: IntSet,
    PeriodStatsData -> IntSet
_month :: IntSet
  }
  deriving (Int -> PeriodStatsData -> ShowS
[PeriodStatsData] -> ShowS
PeriodStatsData -> String
(Int -> PeriodStatsData -> ShowS)
-> (PeriodStatsData -> String)
-> ([PeriodStatsData] -> ShowS)
-> Show PeriodStatsData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PeriodStatsData -> ShowS
showsPrec :: Int -> PeriodStatsData -> ShowS
$cshow :: PeriodStatsData -> String
show :: PeriodStatsData -> String
$cshowList :: [PeriodStatsData] -> ShowS
showList :: [PeriodStatsData] -> ShowS
Show)

newPeriodStatsData :: PeriodStatsData
newPeriodStatsData :: PeriodStatsData
newPeriodStatsData = PeriodStatsData {_day :: IntSet
_day = IntSet
IS.empty, _week :: IntSet
_week = IntSet
IS.empty, _month :: IntSet
_month = IntSet
IS.empty}

getPeriodStatsData :: PeriodStats -> IO PeriodStatsData
getPeriodStatsData :: PeriodStats -> IO PeriodStatsData
getPeriodStatsData PeriodStats
s = do
  IntSet
_day <- IORef IntSet -> IO IntSet
forall a. IORef a -> IO a
readIORef (IORef IntSet -> IO IntSet) -> IORef IntSet -> IO IntSet
forall a b. (a -> b) -> a -> b
$ PeriodStats -> IORef IntSet
day PeriodStats
s
  IntSet
_week <- IORef IntSet -> IO IntSet
forall a. IORef a -> IO a
readIORef (IORef IntSet -> IO IntSet) -> IORef IntSet -> IO IntSet
forall a b. (a -> b) -> a -> b
$ PeriodStats -> IORef IntSet
week PeriodStats
s
  IntSet
_month <- IORef IntSet -> IO IntSet
forall a. IORef a -> IO a
readIORef (IORef IntSet -> IO IntSet) -> IORef IntSet -> IO IntSet
forall a b. (a -> b) -> a -> b
$ PeriodStats -> IORef IntSet
month PeriodStats
s
  PeriodStatsData -> IO PeriodStatsData
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PeriodStatsData {IntSet
_day :: IntSet
_day :: IntSet
_day, IntSet
_week :: IntSet
_week :: IntSet
_week, IntSet
_month :: IntSet
_month :: IntSet
_month}

-- this function is not thread safe, it is used on server start only
setPeriodStats :: PeriodStats -> PeriodStatsData -> IO ()
setPeriodStats :: PeriodStats -> PeriodStatsData -> IO ()
setPeriodStats PeriodStats
s PeriodStatsData
d = do
  IORef IntSet -> IntSet -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (PeriodStats -> IORef IntSet
day PeriodStats
s) (IntSet -> IO ()) -> IntSet -> IO ()
forall a b. (a -> b) -> a -> b
$! PeriodStatsData -> IntSet
_day PeriodStatsData
d
  IORef IntSet -> IntSet -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (PeriodStats -> IORef IntSet
week PeriodStats
s) (IntSet -> IO ()) -> IntSet -> IO ()
forall a b. (a -> b) -> a -> b
$! PeriodStatsData -> IntSet
_week PeriodStatsData
d
  IORef IntSet -> IntSet -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (PeriodStats -> IORef IntSet
month PeriodStats
s) (IntSet -> IO ()) -> IntSet -> IO ()
forall a b. (a -> b) -> a -> b
$! PeriodStatsData -> IntSet
_month PeriodStatsData
d

instance StrEncoding PeriodStatsData where
  strEncode :: PeriodStatsData -> ByteString
strEncode PeriodStatsData {IntSet
_day :: PeriodStatsData -> IntSet
_day :: IntSet
_day, IntSet
_week :: PeriodStatsData -> IntSet
_week :: IntSet
_week, IntSet
_month :: PeriodStatsData -> IntSet
_month :: IntSet
_month} =
    ByteString
"dayHashes=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> IntSet -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode IntSet
_day ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"\nweekHashes=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> IntSet -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode IntSet
_week ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"\nmonthHashes=" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> IntSet -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode IntSet
_month
  strP :: Parser ByteString PeriodStatsData
strP = do
    IntSet
_day <- (Parser ByteString ByteString
"day=" Parser ByteString ByteString
-> Parser ByteString IntSet -> Parser ByteString IntSet
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString IntSet
bsSetP Parser ByteString IntSet
-> Parser ByteString IntSet -> Parser ByteString IntSet
forall a.
Parser ByteString a -> Parser ByteString a -> Parser ByteString a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser ByteString ByteString
"dayHashes=" Parser ByteString ByteString
-> Parser ByteString IntSet -> Parser ByteString IntSet
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString IntSet
forall a. StrEncoding a => Parser a
strP) Parser ByteString IntSet
-> Parser ByteString () -> Parser ByteString IntSet
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine
    IntSet
_week <- (Parser ByteString ByteString
"week=" Parser ByteString ByteString
-> Parser ByteString IntSet -> Parser ByteString IntSet
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString IntSet
bsSetP Parser ByteString IntSet
-> Parser ByteString IntSet -> Parser ByteString IntSet
forall a.
Parser ByteString a -> Parser ByteString a -> Parser ByteString a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser ByteString ByteString
"weekHashes=" Parser ByteString ByteString
-> Parser ByteString IntSet -> Parser ByteString IntSet
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString IntSet
forall a. StrEncoding a => Parser a
strP) Parser ByteString IntSet
-> Parser ByteString () -> Parser ByteString IntSet
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine
    IntSet
_month <- Parser ByteString ByteString
"month=" Parser ByteString ByteString
-> Parser ByteString IntSet -> Parser ByteString IntSet
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString IntSet
bsSetP Parser ByteString IntSet
-> Parser ByteString IntSet -> Parser ByteString IntSet
forall a.
Parser ByteString a -> Parser ByteString a -> Parser ByteString a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser ByteString ByteString
"monthHashes=" Parser ByteString ByteString
-> Parser ByteString IntSet -> Parser ByteString IntSet
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString IntSet
forall a. StrEncoding a => Parser a
strP
    PeriodStatsData -> Parser ByteString PeriodStatsData
forall a. a -> Parser ByteString a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PeriodStatsData {IntSet
_day :: IntSet
_day :: IntSet
_day, IntSet
_week :: IntSet
_week :: IntSet
_week, IntSet
_month :: IntSet
_month :: IntSet
_month}
    where
      bsSetP :: Parser ByteString IntSet
bsSetP = (IntSet -> ByteString -> IntSet)
-> IntSet -> Set ByteString -> IntSet
forall a b. (a -> b -> a) -> a -> Set b -> a
S.foldl' (\IntSet
s -> (Int -> IntSet -> IntSet
`IS.insert` IntSet
s) (Int -> IntSet) -> (ByteString -> Int) -> ByteString -> IntSet
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Int
forall a. Hashable a => a -> Int
hash) IntSet
IS.empty (Set ByteString -> IntSet)
-> Parser ByteString (Set ByteString) -> Parser ByteString IntSet
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. StrEncoding a => Parser a
strP @(Set ByteString)

data PeriodStatCounts = PeriodStatCounts
  { PeriodStatCounts -> Text
dayCount :: Text,
    PeriodStatCounts -> Text
weekCount :: Text,
    PeriodStatCounts -> Text
monthCount :: Text
  }

periodStatDataCounts :: PeriodStatsData -> PeriodStatCounts
periodStatDataCounts :: PeriodStatsData -> PeriodStatCounts
periodStatDataCounts PeriodStatsData {IntSet
_day :: PeriodStatsData -> IntSet
_day :: IntSet
_day, IntSet
_week :: PeriodStatsData -> IntSet
_week :: IntSet
_week, IntSet
_month :: PeriodStatsData -> IntSet
_month :: IntSet
_month} =
  PeriodStatCounts
    { dayCount :: Text
dayCount = Int -> Text
forall a. Show a => a -> Text
tshow (Int -> Text) -> Int -> Text
forall a b. (a -> b) -> a -> b
$ IntSet -> Int
IS.size IntSet
_day,
      weekCount :: Text
weekCount = Int -> Text
forall a. Show a => a -> Text
tshow (Int -> Text) -> Int -> Text
forall a b. (a -> b) -> a -> b
$ IntSet -> Int
IS.size IntSet
_week,
      monthCount :: Text
monthCount = Int -> Text
forall a. Show a => a -> Text
tshow (Int -> Text) -> Int -> Text
forall a b. (a -> b) -> a -> b
$ IntSet -> Int
IS.size IntSet
_month
    }

periodStatCounts :: PeriodStats -> UTCTime -> IO PeriodStatCounts
periodStatCounts :: PeriodStats -> UTCTime -> IO PeriodStatCounts
periodStatCounts PeriodStats
ps UTCTime
ts = do
  let d :: Day
d = UTCTime -> Day
utctDay UTCTime
ts
      (Int
_, Int
wDay) = Day -> (Int, Int)
mondayStartWeek Day
d
      MonthDay Month
_ Int
mDay = Day
d
  Text
dayCount <- Int -> IORef IntSet -> IO Text
periodCount Int
1 (IORef IntSet -> IO Text) -> IORef IntSet -> IO Text
forall a b. (a -> b) -> a -> b
$ PeriodStats -> IORef IntSet
day PeriodStats
ps
  Text
weekCount <- Int -> IORef IntSet -> IO Text
periodCount Int
wDay (IORef IntSet -> IO Text) -> IORef IntSet -> IO Text
forall a b. (a -> b) -> a -> b
$ PeriodStats -> IORef IntSet
week PeriodStats
ps
  Text
monthCount <- Int -> IORef IntSet -> IO Text
periodCount Int
mDay (IORef IntSet -> IO Text) -> IORef IntSet -> IO Text
forall a b. (a -> b) -> a -> b
$ PeriodStats -> IORef IntSet
month PeriodStats
ps
  PeriodStatCounts -> IO PeriodStatCounts
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PeriodStatCounts {Text
dayCount :: Text
dayCount :: Text
dayCount, Text
weekCount :: Text
weekCount :: Text
weekCount, Text
monthCount :: Text
monthCount :: Text
monthCount}
  where
    periodCount :: Int -> IORef IntSet -> IO Text
    periodCount :: Int -> IORef IntSet -> IO Text
periodCount Int
1 IORef IntSet
ref = Int -> Text
forall a. Show a => a -> Text
tshow (Int -> Text) -> (IntSet -> Int) -> IntSet -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntSet -> Int
IS.size (IntSet -> Text) -> IO IntSet -> IO Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IORef IntSet -> IntSet -> IO IntSet
forall a. IORef a -> a -> IO a
atomicSwapIORef IORef IntSet
ref IntSet
IS.empty
    periodCount Int
_ IORef IntSet
_ = Text -> IO Text
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
""

updatePeriodStats :: PeriodStats -> EntityId -> IO ()
updatePeriodStats :: PeriodStats -> EntityId -> IO ()
updatePeriodStats PeriodStats
ps (EntityId ByteString
pId) = do
  IORef IntSet -> IO ()
updatePeriod (IORef IntSet -> IO ()) -> IORef IntSet -> IO ()
forall a b. (a -> b) -> a -> b
$ PeriodStats -> IORef IntSet
day PeriodStats
ps
  IORef IntSet -> IO ()
updatePeriod (IORef IntSet -> IO ()) -> IORef IntSet -> IO ()
forall a b. (a -> b) -> a -> b
$ PeriodStats -> IORef IntSet
week PeriodStats
ps
  IORef IntSet -> IO ()
updatePeriod (IORef IntSet -> IO ()) -> IORef IntSet -> IO ()
forall a b. (a -> b) -> a -> b
$ PeriodStats -> IORef IntSet
month PeriodStats
ps
  where
    ph :: Int
ph = ByteString -> Int
forall a. Hashable a => a -> Int
hash ByteString
pId
    updatePeriod :: IORef IntSet -> IO ()
updatePeriod IORef IntSet
ref = IO Bool -> IO () -> IO ()
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
unlessM (Int -> IntSet -> Bool
IS.member Int
ph (IntSet -> Bool) -> IO IntSet -> IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IORef IntSet -> IO IntSet
forall a. IORef a -> IO a
readIORef IORef IntSet
ref) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ IORef IntSet -> (IntSet -> IntSet) -> IO ()
forall a. IORef a -> (a -> a) -> IO ()
atomicModifyIORef'_ IORef IntSet
ref ((IntSet -> IntSet) -> IO ()) -> (IntSet -> IntSet) -> IO ()
forall a b. (a -> b) -> a -> b
$ Int -> IntSet -> IntSet
IS.insert Int
ph

data ProxyStats = ProxyStats
  { ProxyStats -> IORef Int
pRequests :: IORef Int,
    ProxyStats -> IORef Int
pSuccesses :: IORef Int, -- includes destination server error responses that will be forwarded to the client
    ProxyStats -> IORef Int
pErrorsConnect :: IORef Int,
    ProxyStats -> IORef Int
pErrorsCompat :: IORef Int,
    ProxyStats -> IORef Int
pErrorsOther :: IORef Int
  }

newProxyStats :: IO ProxyStats
newProxyStats :: IO ProxyStats
newProxyStats = do
  IORef Int
pRequests <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
pSuccesses <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
pErrorsConnect <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
pErrorsCompat <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
pErrorsOther <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  ProxyStats -> IO ProxyStats
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ProxyStats {IORef Int
pRequests :: IORef Int
pRequests :: IORef Int
pRequests, IORef Int
pSuccesses :: IORef Int
pSuccesses :: IORef Int
pSuccesses, IORef Int
pErrorsConnect :: IORef Int
pErrorsConnect :: IORef Int
pErrorsConnect, IORef Int
pErrorsCompat :: IORef Int
pErrorsCompat :: IORef Int
pErrorsCompat, IORef Int
pErrorsOther :: IORef Int
pErrorsOther :: IORef Int
pErrorsOther}

data ProxyStatsData = ProxyStatsData
  { ProxyStatsData -> Int
_pRequests :: Int,
    ProxyStatsData -> Int
_pSuccesses :: Int,
    ProxyStatsData -> Int
_pErrorsConnect :: Int,
    ProxyStatsData -> Int
_pErrorsCompat :: Int,
    ProxyStatsData -> Int
_pErrorsOther :: Int
  }
  deriving (Int -> ProxyStatsData -> ShowS
[ProxyStatsData] -> ShowS
ProxyStatsData -> String
(Int -> ProxyStatsData -> ShowS)
-> (ProxyStatsData -> String)
-> ([ProxyStatsData] -> ShowS)
-> Show ProxyStatsData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ProxyStatsData -> ShowS
showsPrec :: Int -> ProxyStatsData -> ShowS
$cshow :: ProxyStatsData -> String
show :: ProxyStatsData -> String
$cshowList :: [ProxyStatsData] -> ShowS
showList :: [ProxyStatsData] -> ShowS
Show)

newProxyStatsData :: ProxyStatsData
newProxyStatsData :: ProxyStatsData
newProxyStatsData = ProxyStatsData {_pRequests :: Int
_pRequests = Int
0, _pSuccesses :: Int
_pSuccesses = Int
0, _pErrorsConnect :: Int
_pErrorsConnect = Int
0, _pErrorsCompat :: Int
_pErrorsCompat = Int
0, _pErrorsOther :: Int
_pErrorsOther = Int
0}

getProxyStatsData :: ProxyStats -> IO ProxyStatsData
getProxyStatsData :: ProxyStats -> IO ProxyStatsData
getProxyStatsData ProxyStats
s = do
  Int
_pRequests <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ProxyStats -> IORef Int
pRequests ProxyStats
s
  Int
_pSuccesses <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ProxyStats -> IORef Int
pSuccesses ProxyStats
s
  Int
_pErrorsConnect <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ProxyStats -> IORef Int
pErrorsConnect ProxyStats
s
  Int
_pErrorsCompat <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ProxyStats -> IORef Int
pErrorsCompat ProxyStats
s
  Int
_pErrorsOther <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ProxyStats -> IORef Int
pErrorsOther ProxyStats
s
  ProxyStatsData -> IO ProxyStatsData
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ProxyStatsData {Int
_pRequests :: Int
_pRequests :: Int
_pRequests, Int
_pSuccesses :: Int
_pSuccesses :: Int
_pSuccesses, Int
_pErrorsConnect :: Int
_pErrorsConnect :: Int
_pErrorsConnect, Int
_pErrorsCompat :: Int
_pErrorsCompat :: Int
_pErrorsCompat, Int
_pErrorsOther :: Int
_pErrorsOther :: Int
_pErrorsOther}

getResetProxyStatsData :: ProxyStats -> IO ProxyStatsData
getResetProxyStatsData :: ProxyStats -> IO ProxyStatsData
getResetProxyStatsData ProxyStats
s = do
  Int
_pRequests <- IORef Int -> Int -> IO Int
forall a. IORef a -> a -> IO a
atomicSwapIORef (ProxyStats -> IORef Int
pRequests ProxyStats
s) Int
0
  Int
_pSuccesses <- IORef Int -> Int -> IO Int
forall a. IORef a -> a -> IO a
atomicSwapIORef (ProxyStats -> IORef Int
pSuccesses ProxyStats
s) Int
0
  Int
_pErrorsConnect <- IORef Int -> Int -> IO Int
forall a. IORef a -> a -> IO a
atomicSwapIORef (ProxyStats -> IORef Int
pErrorsConnect ProxyStats
s) Int
0
  Int
_pErrorsCompat <- IORef Int -> Int -> IO Int
forall a. IORef a -> a -> IO a
atomicSwapIORef (ProxyStats -> IORef Int
pErrorsCompat ProxyStats
s) Int
0
  Int
_pErrorsOther <- IORef Int -> Int -> IO Int
forall a. IORef a -> a -> IO a
atomicSwapIORef (ProxyStats -> IORef Int
pErrorsOther ProxyStats
s) Int
0
  ProxyStatsData -> IO ProxyStatsData
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ProxyStatsData {Int
_pRequests :: Int
_pRequests :: Int
_pRequests, Int
_pSuccesses :: Int
_pSuccesses :: Int
_pSuccesses, Int
_pErrorsConnect :: Int
_pErrorsConnect :: Int
_pErrorsConnect, Int
_pErrorsCompat :: Int
_pErrorsCompat :: Int
_pErrorsCompat, Int
_pErrorsOther :: Int
_pErrorsOther :: Int
_pErrorsOther}

-- this function is not thread safe, it is used on server start only
setProxyStats :: ProxyStats -> ProxyStatsData -> IO ()
setProxyStats :: ProxyStats -> ProxyStatsData -> IO ()
setProxyStats ProxyStats
s ProxyStatsData
d = do
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ProxyStats -> IORef Int
pRequests ProxyStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ProxyStatsData -> Int
_pRequests ProxyStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ProxyStats -> IORef Int
pSuccesses ProxyStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ProxyStatsData -> Int
_pSuccesses ProxyStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ProxyStats -> IORef Int
pErrorsConnect ProxyStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ProxyStatsData -> Int
_pErrorsConnect ProxyStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ProxyStats -> IORef Int
pErrorsCompat ProxyStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ProxyStatsData -> Int
_pErrorsCompat ProxyStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ProxyStats -> IORef Int
pErrorsOther ProxyStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ProxyStatsData -> Int
_pErrorsOther ProxyStatsData
d

instance StrEncoding ProxyStatsData where
  strEncode :: ProxyStatsData -> ByteString
strEncode ProxyStatsData {Int
_pRequests :: ProxyStatsData -> Int
_pRequests :: Int
_pRequests, Int
_pSuccesses :: ProxyStatsData -> Int
_pSuccesses :: Int
_pSuccesses, Int
_pErrorsConnect :: ProxyStatsData -> Int
_pErrorsConnect :: Int
_pErrorsConnect, Int
_pErrorsCompat :: ProxyStatsData -> Int
_pErrorsCompat :: Int
_pErrorsCompat, Int
_pErrorsOther :: ProxyStatsData -> Int
_pErrorsOther :: Int
_pErrorsOther} =
    ByteString
"requests="
      ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode Int
_pRequests
      ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"\nsuccesses="
      ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode Int
_pSuccesses
      ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"\nerrorsConnect="
      ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode Int
_pErrorsConnect
      ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"\nerrorsCompat="
      ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode Int
_pErrorsCompat
      ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"\nerrorsOther="
      ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode Int
_pErrorsOther
  strP :: Parser ByteString ProxyStatsData
strP = do
    Int
_pRequests <- Parser ByteString ByteString
"requests=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP Parser ByteString Int
-> Parser ByteString () -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine
    Int
_pSuccesses <- Parser ByteString ByteString
"successes=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP Parser ByteString Int
-> Parser ByteString () -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine
    Int
_pErrorsConnect <- Parser ByteString ByteString
"errorsConnect=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP Parser ByteString Int
-> Parser ByteString () -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine
    Int
_pErrorsCompat <- Parser ByteString ByteString
"errorsCompat=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP Parser ByteString Int
-> Parser ByteString () -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine
    Int
_pErrorsOther <- Parser ByteString ByteString
"errorsOther=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP
    ProxyStatsData -> Parser ByteString ProxyStatsData
forall a. a -> Parser ByteString a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ProxyStatsData {Int
_pRequests :: Int
_pRequests :: Int
_pRequests, Int
_pSuccesses :: Int
_pSuccesses :: Int
_pSuccesses, Int
_pErrorsConnect :: Int
_pErrorsConnect :: Int
_pErrorsConnect, Int
_pErrorsCompat :: Int
_pErrorsCompat :: Int
_pErrorsCompat, Int
_pErrorsOther :: Int
_pErrorsOther :: Int
_pErrorsOther}

data ServiceStats = ServiceStats
  { ServiceStats -> IORef Int
srvAssocNew :: IORef Int,
    ServiceStats -> IORef Int
srvAssocDuplicate :: IORef Int,
    ServiceStats -> IORef Int
srvAssocUpdated :: IORef Int,
    ServiceStats -> IORef Int
srvAssocRemoved :: IORef Int,
    ServiceStats -> IORef Int
srvSubCount :: IORef Int,
    ServiceStats -> IORef Int
srvSubDuplicate :: IORef Int,
    ServiceStats -> IORef Int
srvSubQueues :: IORef Int,
    ServiceStats -> IORef Int
srvSubEnd :: IORef Int
  }

data ServiceStatsData = ServiceStatsData
  { ServiceStatsData -> Int
_srvAssocNew :: Int,
    ServiceStatsData -> Int
_srvAssocDuplicate :: Int,
    ServiceStatsData -> Int
_srvAssocUpdated :: Int,
    ServiceStatsData -> Int
_srvAssocRemoved :: Int,
    ServiceStatsData -> Int
_srvSubCount :: Int,
    ServiceStatsData -> Int
_srvSubDuplicate :: Int,
    ServiceStatsData -> Int
_srvSubQueues :: Int,
    ServiceStatsData -> Int
_srvSubEnd :: Int
  }
  deriving (Int -> ServiceStatsData -> ShowS
[ServiceStatsData] -> ShowS
ServiceStatsData -> String
(Int -> ServiceStatsData -> ShowS)
-> (ServiceStatsData -> String)
-> ([ServiceStatsData] -> ShowS)
-> Show ServiceStatsData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ServiceStatsData -> ShowS
showsPrec :: Int -> ServiceStatsData -> ShowS
$cshow :: ServiceStatsData -> String
show :: ServiceStatsData -> String
$cshowList :: [ServiceStatsData] -> ShowS
showList :: [ServiceStatsData] -> ShowS
Show)

newServiceStatsData :: ServiceStatsData
newServiceStatsData :: ServiceStatsData
newServiceStatsData =
  ServiceStatsData
    { _srvAssocNew :: Int
_srvAssocNew = Int
0,
      _srvAssocDuplicate :: Int
_srvAssocDuplicate = Int
0,
      _srvAssocUpdated :: Int
_srvAssocUpdated = Int
0,
      _srvAssocRemoved :: Int
_srvAssocRemoved = Int
0,
      _srvSubCount :: Int
_srvSubCount = Int
0,
      _srvSubDuplicate :: Int
_srvSubDuplicate = Int
0,
      _srvSubQueues :: Int
_srvSubQueues = Int
0,
      _srvSubEnd :: Int
_srvSubEnd = Int
0
    }

newServiceStats :: IO ServiceStats
newServiceStats :: IO ServiceStats
newServiceStats = do
  IORef Int
srvAssocNew <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
srvAssocDuplicate <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
srvAssocUpdated <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
srvAssocRemoved <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
srvSubCount <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
srvSubDuplicate <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
srvSubQueues <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  IORef Int
srvSubEnd <- Int -> IO (IORef Int)
forall a. a -> IO (IORef a)
newIORef Int
0
  ServiceStats -> IO ServiceStats
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
    ServiceStats
      { IORef Int
srvAssocNew :: IORef Int
srvAssocNew :: IORef Int
srvAssocNew,
        IORef Int
srvAssocDuplicate :: IORef Int
srvAssocDuplicate :: IORef Int
srvAssocDuplicate,
        IORef Int
srvAssocUpdated :: IORef Int
srvAssocUpdated :: IORef Int
srvAssocUpdated,
        IORef Int
srvAssocRemoved :: IORef Int
srvAssocRemoved :: IORef Int
srvAssocRemoved,
        IORef Int
srvSubCount :: IORef Int
srvSubCount :: IORef Int
srvSubCount,
        IORef Int
srvSubDuplicate :: IORef Int
srvSubDuplicate :: IORef Int
srvSubDuplicate,
        IORef Int
srvSubQueues :: IORef Int
srvSubQueues :: IORef Int
srvSubQueues,
        IORef Int
srvSubEnd :: IORef Int
srvSubEnd :: IORef Int
srvSubEnd
      }

getServiceStatsData :: ServiceStats -> IO ServiceStatsData
getServiceStatsData :: ServiceStats -> IO ServiceStatsData
getServiceStatsData ServiceStats
s = do
  Int
_srvAssocNew <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServiceStats -> IORef Int
srvAssocNew ServiceStats
s
  Int
_srvAssocDuplicate <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServiceStats -> IORef Int
srvAssocDuplicate ServiceStats
s
  Int
_srvAssocUpdated <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServiceStats -> IORef Int
srvAssocUpdated ServiceStats
s
  Int
_srvAssocRemoved <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServiceStats -> IORef Int
srvAssocRemoved ServiceStats
s
  Int
_srvSubCount <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServiceStats -> IORef Int
srvSubCount ServiceStats
s
  Int
_srvSubDuplicate <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServiceStats -> IORef Int
srvSubDuplicate ServiceStats
s
  Int
_srvSubQueues <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServiceStats -> IORef Int
srvSubQueues ServiceStats
s
  Int
_srvSubEnd <- IORef Int -> IO Int
forall a. IORef a -> IO a
readIORef (IORef Int -> IO Int) -> IORef Int -> IO Int
forall a b. (a -> b) -> a -> b
$ ServiceStats -> IORef Int
srvSubEnd ServiceStats
s
  ServiceStatsData -> IO ServiceStatsData
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
    ServiceStatsData
      { Int
_srvAssocNew :: Int
_srvAssocNew :: Int
_srvAssocNew,
        Int
_srvAssocDuplicate :: Int
_srvAssocDuplicate :: Int
_srvAssocDuplicate,
        Int
_srvAssocUpdated :: Int
_srvAssocUpdated :: Int
_srvAssocUpdated,
        Int
_srvAssocRemoved :: Int
_srvAssocRemoved :: Int
_srvAssocRemoved,
        Int
_srvSubCount :: Int
_srvSubCount :: Int
_srvSubCount,
        Int
_srvSubDuplicate :: Int
_srvSubDuplicate :: Int
_srvSubDuplicate,
        Int
_srvSubQueues :: Int
_srvSubQueues :: Int
_srvSubQueues,
        Int
_srvSubEnd :: Int
_srvSubEnd :: Int
_srvSubEnd
      }

getResetServiceStatsData :: ServiceStats -> IO ServiceStatsData
getResetServiceStatsData :: ServiceStats -> IO ServiceStatsData
getResetServiceStatsData ServiceStats
s = do
  Int
_srvAssocNew <- IORef Int -> Int -> IO Int
forall a. IORef a -> a -> IO a
atomicSwapIORef (ServiceStats -> IORef Int
srvAssocNew ServiceStats
s) Int
0
  Int
_srvAssocDuplicate <- IORef Int -> Int -> IO Int
forall a. IORef a -> a -> IO a
atomicSwapIORef (ServiceStats -> IORef Int
srvAssocDuplicate ServiceStats
s) Int
0
  Int
_srvAssocUpdated <- IORef Int -> Int -> IO Int
forall a. IORef a -> a -> IO a
atomicSwapIORef (ServiceStats -> IORef Int
srvAssocUpdated ServiceStats
s) Int
0
  Int
_srvAssocRemoved <- IORef Int -> Int -> IO Int
forall a. IORef a -> a -> IO a
atomicSwapIORef (ServiceStats -> IORef Int
srvAssocRemoved ServiceStats
s) Int
0
  Int
_srvSubCount <- IORef Int -> Int -> IO Int
forall a. IORef a -> a -> IO a
atomicSwapIORef (ServiceStats -> IORef Int
srvSubCount ServiceStats
s) Int
0
  Int
_srvSubDuplicate <- IORef Int -> Int -> IO Int
forall a. IORef a -> a -> IO a
atomicSwapIORef (ServiceStats -> IORef Int
srvSubDuplicate ServiceStats
s) Int
0
  Int
_srvSubQueues <- IORef Int -> Int -> IO Int
forall a. IORef a -> a -> IO a
atomicSwapIORef (ServiceStats -> IORef Int
srvSubQueues ServiceStats
s) Int
0
  Int
_srvSubEnd <- IORef Int -> Int -> IO Int
forall a. IORef a -> a -> IO a
atomicSwapIORef (ServiceStats -> IORef Int
srvSubEnd ServiceStats
s) Int
0
  ServiceStatsData -> IO ServiceStatsData
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
    ServiceStatsData
      { Int
_srvAssocNew :: Int
_srvAssocNew :: Int
_srvAssocNew,
        Int
_srvAssocDuplicate :: Int
_srvAssocDuplicate :: Int
_srvAssocDuplicate,
        Int
_srvAssocUpdated :: Int
_srvAssocUpdated :: Int
_srvAssocUpdated,
        Int
_srvAssocRemoved :: Int
_srvAssocRemoved :: Int
_srvAssocRemoved,
        Int
_srvSubCount :: Int
_srvSubCount :: Int
_srvSubCount,
        Int
_srvSubDuplicate :: Int
_srvSubDuplicate :: Int
_srvSubDuplicate,
        Int
_srvSubQueues :: Int
_srvSubQueues :: Int
_srvSubQueues,
        Int
_srvSubEnd :: Int
_srvSubEnd :: Int
_srvSubEnd
      }

-- this function is not thread safe, it is used on server start only
setServiceStats :: ServiceStats -> ServiceStatsData -> IO ()
setServiceStats :: ServiceStats -> ServiceStatsData -> IO ()
setServiceStats ServiceStats
s ServiceStatsData
d = do
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServiceStats -> IORef Int
srvAssocNew ServiceStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServiceStatsData -> Int
_srvAssocNew ServiceStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServiceStats -> IORef Int
srvAssocDuplicate ServiceStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServiceStatsData -> Int
_srvAssocDuplicate ServiceStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServiceStats -> IORef Int
srvAssocUpdated ServiceStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServiceStatsData -> Int
_srvAssocUpdated ServiceStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServiceStats -> IORef Int
srvAssocRemoved ServiceStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServiceStatsData -> Int
_srvAssocRemoved ServiceStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServiceStats -> IORef Int
srvSubCount ServiceStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServiceStatsData -> Int
_srvSubCount ServiceStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServiceStats -> IORef Int
srvSubDuplicate ServiceStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServiceStatsData -> Int
_srvSubDuplicate ServiceStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServiceStats -> IORef Int
srvSubQueues ServiceStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServiceStatsData -> Int
_srvSubQueues ServiceStatsData
d
  IORef Int -> Int -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (ServiceStats -> IORef Int
srvSubEnd ServiceStats
s) (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$! ServiceStatsData -> Int
_srvSubEnd ServiceStatsData
d

instance StrEncoding ServiceStatsData where
  strEncode :: ServiceStatsData -> ByteString
strEncode ServiceStatsData {Int
_srvAssocNew :: ServiceStatsData -> Int
_srvAssocNew :: Int
_srvAssocNew, Int
_srvAssocDuplicate :: ServiceStatsData -> Int
_srvAssocDuplicate :: Int
_srvAssocDuplicate, Int
_srvAssocUpdated :: ServiceStatsData -> Int
_srvAssocUpdated :: Int
_srvAssocUpdated, Int
_srvAssocRemoved :: ServiceStatsData -> Int
_srvAssocRemoved :: Int
_srvAssocRemoved, Int
_srvSubCount :: ServiceStatsData -> Int
_srvSubCount :: Int
_srvSubCount, Int
_srvSubDuplicate :: ServiceStatsData -> Int
_srvSubDuplicate :: Int
_srvSubDuplicate, Int
_srvSubQueues :: ServiceStatsData -> Int
_srvSubQueues :: Int
_srvSubQueues, Int
_srvSubEnd :: ServiceStatsData -> Int
_srvSubEnd :: Int
_srvSubEnd} =
    ByteString
"assocNew="
      ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode Int
_srvAssocNew
      ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"\nassocDuplicate="
      ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode Int
_srvAssocDuplicate
      ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"\nassocUpdatedt="
      ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode Int
_srvAssocUpdated
      ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"\nassocRemoved="
      ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode Int
_srvAssocRemoved
      ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"\nsubCount="
      ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode Int
_srvSubCount
      ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"\nsubDuplicate="
      ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode Int
_srvSubDuplicate
      ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"\nsubQueues="
      ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode Int
_srvSubQueues
      ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"\nsubEnd="
      ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode Int
_srvSubEnd
  strP :: Parser ByteString ServiceStatsData
strP = do
    Int
_srvAssocNew <- Parser ByteString ByteString
"assocNew=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP Parser ByteString Int
-> Parser ByteString () -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine
    Int
_srvAssocDuplicate <- Parser ByteString ByteString
"assocDuplicate=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP Parser ByteString Int
-> Parser ByteString () -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine
    Int
_srvAssocUpdated <- Parser ByteString ByteString
"assocUpdatedt=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP Parser ByteString Int
-> Parser ByteString () -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine
    Int
_srvAssocRemoved <- Parser ByteString ByteString
"assocRemoved=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP Parser ByteString Int
-> Parser ByteString () -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine
    Int
_srvSubCount <- Parser ByteString ByteString
"subCount=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP Parser ByteString Int
-> Parser ByteString () -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine
    Int
_srvSubDuplicate <- Parser ByteString ByteString
"subDuplicate=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP Parser ByteString Int
-> Parser ByteString () -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine
    Int
_srvSubQueues <- Parser ByteString ByteString
"subQueues=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP Parser ByteString Int
-> Parser ByteString () -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
A.endOfLine
    Int
_srvSubEnd <- Parser ByteString ByteString
"subEnd=" Parser ByteString ByteString
-> Parser ByteString Int -> Parser ByteString Int
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString Int
forall a. StrEncoding a => Parser a
strP
    ServiceStatsData -> Parser ByteString ServiceStatsData
forall a. a -> Parser ByteString a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
      ServiceStatsData
        { Int
_srvAssocNew :: Int
_srvAssocNew :: Int
_srvAssocNew,
          Int
_srvAssocDuplicate :: Int
_srvAssocDuplicate :: Int
_srvAssocDuplicate,
          Int
_srvAssocUpdated :: Int
_srvAssocUpdated :: Int
_srvAssocUpdated,
          Int
_srvAssocRemoved :: Int
_srvAssocRemoved :: Int
_srvAssocRemoved,
          Int
_srvSubCount :: Int
_srvSubCount :: Int
_srvSubCount,
          Int
_srvSubDuplicate :: Int
_srvSubDuplicate :: Int
_srvSubDuplicate,
          Int
_srvSubQueues :: Int
_srvSubQueues :: Int
_srvSubQueues,
          Int
_srvSubEnd :: Int
_srvSubEnd :: Int
_srvSubEnd
        }

data TimeBuckets = TimeBuckets
  { TimeBuckets -> Int64
sumTime :: Int64,
    TimeBuckets -> Int64
maxTime :: Int64,
    TimeBuckets -> IntMap Int
timeBuckets :: IM.IntMap Int
  }
  deriving (Int -> TimeBuckets -> ShowS
[TimeBuckets] -> ShowS
TimeBuckets -> String
(Int -> TimeBuckets -> ShowS)
-> (TimeBuckets -> String)
-> ([TimeBuckets] -> ShowS)
-> Show TimeBuckets
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TimeBuckets -> ShowS
showsPrec :: Int -> TimeBuckets -> ShowS
$cshow :: TimeBuckets -> String
show :: TimeBuckets -> String
$cshowList :: [TimeBuckets] -> ShowS
showList :: [TimeBuckets] -> ShowS
Show)

emptyTimeBuckets :: TimeBuckets
emptyTimeBuckets :: TimeBuckets
emptyTimeBuckets = Int64 -> Int64 -> IntMap Int -> TimeBuckets
TimeBuckets Int64
0 Int64
0 IntMap Int
forall a. IntMap a
IM.empty

updateTimeBuckets :: SystemSeconds -> SystemSeconds -> TimeBuckets -> TimeBuckets
updateTimeBuckets :: SystemSeconds -> SystemSeconds -> TimeBuckets -> TimeBuckets
updateTimeBuckets
  (RoundedSystemTime Int64
deliveryTime)
  (RoundedSystemTime Int64
currTime)
  TimeBuckets {Int64
sumTime :: TimeBuckets -> Int64
sumTime :: Int64
sumTime, Int64
maxTime :: TimeBuckets -> Int64
maxTime :: Int64
maxTime, IntMap Int
timeBuckets :: TimeBuckets -> IntMap Int
timeBuckets :: IntMap Int
timeBuckets} =
    TimeBuckets
      { sumTime :: Int64
sumTime = Int64
sumTime Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+ Int64
t,
        maxTime :: Int64
maxTime = Int64 -> Int64 -> Int64
forall a. Ord a => a -> a -> a
max Int64
maxTime Int64
t,
        timeBuckets :: IntMap Int
timeBuckets = (Maybe Int -> Maybe Int) -> Int -> IntMap Int -> IntMap Int
forall a. (Maybe a -> Maybe a) -> Int -> IntMap a -> IntMap a
IM.alter (Int -> Maybe Int
forall a. a -> Maybe a
Just (Int -> Maybe Int) -> (Maybe Int -> Int) -> Maybe Int -> Maybe Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> (Int -> Int) -> Maybe Int -> Int
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Int
1 (Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)) Int
seconds IntMap Int
timeBuckets
      }
  where
    t :: Int64
t = Int64
currTime Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
- Int64
deliveryTime
    seconds :: Int
seconds
      | Int64
t Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
<= Int64
5 = Int64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
t
      | Int64
t Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
<= Int64
30 = Int64
t Int64 -> Int64 -> Int
forall {a} {a}. (Integral a, Num a) => a -> a -> a
`toBucket` Int64
5
      | Int64
t Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
<= Int64
60 = Int64
t Int64 -> Int64 -> Int
forall {a} {a}. (Integral a, Num a) => a -> a -> a
`toBucket` Int64
10
      | Int64
t Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
<= Int64
180 = Int64
t Int64 -> Int64 -> Int
forall {a} {a}. (Integral a, Num a) => a -> a -> a
`toBucket` Int64
30
      | Bool
otherwise = Int64
t Int64 -> Int64 -> Int
forall {a} {a}. (Integral a, Num a) => a -> a -> a
`toBucket` Int64
60
    toBucket :: a -> a -> a
toBucket a
n a
m = - a -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral (((- a
n) a -> a -> a
forall a. Integral a => a -> a -> a
`div` a
m) a -> a -> a
forall a. Num a => a -> a -> a
* a
m) -- round up