Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module provides Network.Wai middlware for exporting Prometheus metrics and for instrumenting WAI applications.
Synopsis
- prometheus :: PrometheusSettings -> Middleware
- data PrometheusSettings = PrometheusSettings {}
- def :: Default a => a
- instrumentHandlerValue :: (Request -> Text) -> Application -> Application
- instrumentHandlerValueWithFilter :: (Response -> Maybe Response) -> (Request -> Text) -> Application -> Application
- instrumentHandlerValueWithHistogramAndFilter :: Vector Label3 Histogram -> (Response -> Maybe Response) -> (Request -> Text) -> Application -> Application
- ignoreRawResponses :: Response -> Maybe Response
- instrumentApp :: Text -> Application -> Application
- instrumentIO :: Text -> IO a -> IO a
- observeSeconds :: Text -> Maybe Text -> Maybe Text -> TimeSpec -> TimeSpec -> IO ()
- metricsApp :: Application
Documentation
prometheus :: PrometheusSettings -> Middleware Source #
Expose Prometheus metrics and instrument an application with some basic metrics (e.g. request latency).
data PrometheusSettings Source #
Settings that control the behavior of the Prometheus middleware.
PrometheusSettings | |
|
Instances
instrumentHandlerValue Source #
:: (Request -> Text) | The function used to derive the "handler" value in Prometheus |
-> Application | The app to instrument |
-> Application | The 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 Source #
:: (Response -> Maybe Response) | Response filter |
-> (Request -> Text) | The function used to derive the "handler" value in Prometheus |
-> Application | The app to instrument |
-> Application | The instrumented app |
A more flexible variant of instrumentHandlerValue
. The filter can change some
responses, or drop others entirely.
instrumentHandlerValueWithHistogramAndFilter Source #
:: Vector Label3 Histogram | |
-> (Response -> Maybe Response) | Response filter |
-> (Request -> Text) | The function used to derive the "handler" value in Prometheus |
-> Application | The app to instrument |
-> Application | The instrumented app |
ignoreRawResponses :: Response -> Maybe Response Source #
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
.
:: Text | The label used to identify this app |
-> Application | The app to instrument |
-> Application | The 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.
:: Text | The label used to identify this IO operation |
-> IO a | The IO action to instrument |
-> IO a | The instrumented app |
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.
:: Text | handler label |
-> Maybe Text | method |
-> Maybe Text | status |
-> TimeSpec | start time |
-> TimeSpec | end time |
-> IO () |
Record an event to the middleware metric.
metricsApp :: Application Source #
WAI Application that serves the Prometheus metrics page regardless of what the request is.