Expose Prometheus metrics and instrument an application with some basic metrics (e.g. request latency).
Modulewai-middleware-prometheus-1.0.0.1Haskell2010
Network.Wai.Middleware.Prometheus
This module provides Network.Wai middlware for exporting Prometheus metrics and for instrumenting WAI applications.
- 1 type
- 8 values
- Packagewai-middleware-prometheus-1.0.0.1
- Exports10
- LanguageHaskell2010
- LicenceApache-2.0
- SourcePrometheus.hs
Settings that control the behavior of the Prometheus middleware.
Constructors
PrometheusSettingsprometheusEndPoint :: [Text]The path that will be used for exporting metrics. The default value is ["metrics"] which corresponds to the path /metrics.
prometheusInstrumentApp :: BoolWhether the default instrumentation should be applied to the application. If this is set to false the application can still be instrumented using the instrumentApp function. The default value is True.
prometheusInstrumentPrometheus :: BoolWhether the default instrumentation should be applied to the middleware that serves the metrics endpoint. The default value is True.
Instances1Default
Default PrometheusSettingsDefined in wai-middleware-prometheus-1.0.0.1 · Network.Wai.Middleware.Prometheus
The default value for this type.
instrumentHandlerValue :: (Request -> Text)The function used to derive the "handler" value in Prometheus
-> ApplicationThe app to instrument
-> ApplicationThe instrumented app
This function is used to populate the handler label of all Prometheus metrics recorded by this library.
If you use this function you will likely want to override the default value of prometheusInstrumentApp to be false so that your app does not get double instrumented.
WARNING: If you have ResponseRaw values in your API, consider using
instrumentHandlerValueWithFilter ignoreRawResponses instead.
instrumentHandlerValueWithFilter :: (Response -> Maybe Response)Response filter
-> (Request -> Text)The function used to derive the "handler" value in Prometheus
-> ApplicationThe app to instrument
-> ApplicationThe instrumented app
A more flexible variant of instrumentHandlerValue. The filter can change some responses, or drop others entirely.
ResponseRaw values have two parts: an action that can be executed to construct a Response, and a pure "backup" Response in case the computation fails. Since the pure selectors like responseStatus are pure and it makes no sense for them to call the action, they just go to the backup response and pull the value from that:
responseStatus (ResponseRaw ...
(ResponseBuilder (Status 500 "blargh") ... ...))
== Status {statusCode = 500, statusMessage = "blargh"}
This is often not what you want. For example, if you have an end-point for establishing websocket connections that has a backup response with status 5xx, every websocket connection request, whether successful or not, will register as an internal server error.
This helper therefore filters out all raw requests so they won't create any metrics. Use together with instrumentHandlerValueWithFilter.
instrumentApp :: TextThe label used to identify this app
-> ApplicationThe app to instrument
-> ApplicationThe instrumented app
Instrument a WAI app with the default WAI metrics.
If you use this function you will likely want to override the default value of prometheusInstrumentApp to be false so that your app does not get double instrumented.
instrumentIO Instrument an IO action with timing metrics. This function can be used if you would like to get more fine grained metrics, for instance this can be used to instrument individual end points.
If you use this function you will likely want to override the default value of prometheusInstrumentApp to be false so that your app does not get double instrumented.
observeSeconds Record an event to the middleware metric.
WAI Application that serves the Prometheus metrics page regardless of what the request is.