Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions lib/Servant/Ekg/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion servant-ekg.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down