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 server errors (counter
wai.server_error_count
) - 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
- data WaiMetrics = WaiMetrics {}
- metrics :: WaiMetrics -> Middleware
Documentation
registerWaiMetrics :: Store -> IO WaiMetrics Source
Register in EKG a number of metrics related to web server activity.
wai.request_count
wai.server_error_count
wai.latency_distribution
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.