License | BSD3 |
---|---|
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
A WAI middleware to collect the following EKG metrics from compatible web servers:
- number of requests (counter
wai.request_count
) - number of response by status code, broken down class (count
wai.response_status_xxx
) - latency distribution (distribution
wai.latency_distribution
)
Here's an example of reading these metrics from a Scotty server, and displaying them with EKG.
-- Compile with GHC option `-with-rtsopts=-T` for GC metrics import Web.Scotty import Control.Applicative import System.Remote.Monitoring (serverMetricStore, forkServer) import Network.Wai.Metrics main :: IO() main = do store <- serverMetricStore <$> forkServer "localhost" 8000 waiMetrics <- registerWaiMetrics store scotty 3000 $ do middleware (metrics waiMetrics) get "/" $ html "Ping"
Now have a look at your local EKG instance and display the request count by clicking on 'wai.request_count'.
WAI metrics can also be stored in a bare EKG store, with no UI and no GC metrics. Use ekg-core's newStore function.
Compatible web servers include the following:
- Yesod
- Scotty
- Spock
- Servant
- Warp
- registerWaiMetrics :: Store -> IO WaiMetrics
- registerNamedWaiMetrics :: Text -> Store -> IO WaiMetrics
- data WaiMetrics = WaiMetrics {}
- metrics :: WaiMetrics -> Middleware
Documentation
registerWaiMetrics :: Store -> IO WaiMetrics Source #
Register in EKG a number of metrics related to web server activity using empty namespace.
wai.request_count
wai.response_status_1xx
wai.response_status_2xx
wai.response_status_3xx
wai.response_status_4xx
wai.response_status_5xx
wai.latency_distribution
registerNamedWaiMetrics :: Text -> Store -> IO WaiMetrics Source #
Register in EKG a number of metrics related to web server activity with a namespace.
data WaiMetrics Source #
The metrics to feed in WAI and register in EKG.
metrics :: WaiMetrics -> Middleware Source #
Create a middleware to be added to a WAI-based webserver.