mirror of
https://github.com/haskell-servant/servant-ekg.git
synced 2024-11-23 03:29:43 +01:00
use monotonic clock instead of system clock
This commit is contained in:
parent
bda075f8f5
commit
d9387b6ef7
2 changed files with 7 additions and 6 deletions
|
@ -13,7 +13,7 @@ import Data.Monoid
|
|||
import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
import qualified Data.Text.Encoding as T
|
||||
import Data.Time.Clock
|
||||
import GHC.Clock (getMonotonicTime)
|
||||
import GHC.Generics (Generic)
|
||||
import Network.HTTP.Types (Method, Status (..))
|
||||
import Network.Wai (Middleware, responseStatus)
|
||||
|
@ -58,12 +58,14 @@ countResponseCodes (c2XX, c4XX, c5XX, cXXX) application request respond =
|
|||
|
||||
responseTimeDistribution :: Distribution.Distribution -> Middleware
|
||||
responseTimeDistribution dist application request respond =
|
||||
bracket getCurrentTime stop $ const $ application request respond
|
||||
bracket getMonotonicTime stop $ const $ application request respond
|
||||
where
|
||||
stop t1 = do
|
||||
t2 <- getCurrentTime
|
||||
let dt = diffUTCTime t2 t1
|
||||
Distribution.add dist $ fromRational $ (*1000) $ toRational dt
|
||||
t2 <- getMonotonicTime
|
||||
let
|
||||
dt = t2 - t1
|
||||
milliseconds = dt * 1000
|
||||
Distribution.add dist milliseconds
|
||||
|
||||
initializeMeters :: Store -> APIEndpoint -> IO Meters
|
||||
initializeMeters store APIEndpoint{..} = do
|
||||
|
|
|
@ -31,7 +31,6 @@ library
|
|||
, hashable >=1.2.7.0 && <1.4
|
||||
, servant >=0.14 && <0.19
|
||||
, text >=1.2.3.0 && <1.3
|
||||
, time >=1.6.0.1 && <1.12
|
||||
, unordered-containers >=0.2.9.0 && <0.3
|
||||
, wai >=3.2.0 && <3.3
|
||||
|
||||
|
|
Loading…
Reference in a new issue