module Network.Wai.Middleware.Prometheus (instrumentRequests) where
import Control.Monad.State (MonadState)
import Control.Monad.IO.Class (MonadIO)
import qualified Network.Wai as Wai
import Prometheus
instrumentRequests
:: (MonadState Registry m, MonadIO m) => m Wai.Middleware
instrumentRequests = do
httpRequestsTotal <-
register
"http_requests_total"
"Total number of HTTP requests."
mempty
counter
httpLatency <-
register
"http_latency_seconds"
"Overall HTTP transaction latency."
mempty
(histogram ioDurationBuckets)
return $ \app req res -> do
incCounter httpRequestsTotal
time httpLatency $ app req res