wai-middleware-metrics-0.2.4: A WAI middleware to collect EKG request metrics

LicenseBSD3
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Network.Wai.Metrics

Description

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

Synopsis

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.

metrics :: WaiMetrics -> Middleware Source #

Create a middleware to be added to a WAI-based webserver.