packages feed

wai-middleware-prometheus 1.0.0.1 → 1.0.1.0

raw patch · 2 files changed

+26/−5 lines, 2 files

Files

src/Network/Wai/Middleware/Prometheus.hs view
@@ -9,6 +9,7 @@   , Default.def   , instrumentHandlerValue   , instrumentHandlerValueWithFilter+  , instrumentHandlerValueWithHistogramAndFilter   , ignoreRawResponses   , instrumentApp   , instrumentIO@@ -80,7 +81,16 @@   -> (Wai.Request -> Text) -- ^ The function used to derive the "handler" value in Prometheus   -> Wai.Application -- ^ The app to instrument   -> Wai.Application -- ^ The instrumented app-instrumentHandlerValueWithFilter resFilter f app req respond = do+instrumentHandlerValueWithFilter =+  instrumentHandlerValueWithHistogramAndFilter requestLatency++instrumentHandlerValueWithHistogramAndFilter ::+     Prom.Vector Prom.Label3 Prom.Histogram+  -> (Wai.Response -> Maybe Wai.Response) -- ^ Response filter+  -> (Wai.Request -> Text) -- ^ The function used to derive the "handler" value in Prometheus+  -> Wai.Application -- ^ The app to instrument+  -> Wai.Application -- ^ The instrumented app+instrumentHandlerValueWithHistogramAndFilter histogram resFilter f app req respond = do   start <- getTime Monotonic   app req $ \res -> do     case resFilter res of@@ -89,7 +99,7 @@         end <- getTime Monotonic         let method = Just $ decodeUtf8 (Wai.requestMethod req)         let status = Just $ T.pack (show (HTTP.statusCode (Wai.responseStatus res')))-        observeSeconds (f req) method status start end+        observeSecondsWithHistogram histogram (f req) method status start end     respond res  -- | 'Wai.ResponseRaw' values have two parts: an action that can be executed to construct a@@ -149,10 +159,21 @@                -> TimeSpec     -- ^ start time                -> TimeSpec     -- ^ end time                -> IO ()-observeSeconds handler method status start end = do+observeSeconds = do+  observeSecondsWithHistogram requestLatency++-- | Record an event to the middleware metric.+observeSecondsWithHistogram :: Prom.Vector Prom.Label3 Prom.Histogram+                            -> Text         -- ^ handler label+                            -> Maybe Text   -- ^ method+                            -> Maybe Text   -- ^ status+                            -> TimeSpec     -- ^ start time+                            -> TimeSpec     -- ^ end time+                            -> IO ()+observeSecondsWithHistogram histograms handler method status start end = do     let latency :: Double         latency = fromRational $ toRational (toNanoSecs (end `diffTimeSpec` start) % 1000000000)-    Prom.withLabel requestLatency+    Prom.withLabel histograms                    (handler, fromMaybe "" method, fromMaybe "" status)                    (flip Prom.observe latency) 
wai-middleware-prometheus.cabal view
@@ -1,5 +1,5 @@ name:                wai-middleware-prometheus-version:             1.0.0.1+version:             1.0.1.0 synopsis:     WAI middlware for exposing http://prometheus.io metrics. description: