wai-middleware-prometheus-1.0.1.0: WAI middlware for exposing http://prometheus.io metrics.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Network.Wai.Middleware.Prometheus

Description

This module provides Network.Wai middlware for exporting Prometheus metrics and for instrumenting WAI applications.

Synopsis

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.

Constructors

PrometheusSettings 

Fields

  • prometheusEndPoint :: [Text]

    The path that will be used for exporting metrics. The default value is ["metrics"] which corresponds to the path /metrics.

  • prometheusInstrumentApp :: Bool

    Whether 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 :: Bool

    Whether the default instrumentation should be applied to the middleware that serves the metrics endpoint. The default value is True.

Instances

Instances details
Default PrometheusSettings Source # 
Instance details

Defined in Network.Wai.Middleware.Prometheus

def :: Default a => a Source #

The default value for this type.

instrumentHandlerValue Source #

Arguments

:: (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 #

Arguments

:: (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 #

Arguments

:: 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.

instrumentApp Source #

Arguments

:: 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.

instrumentIO Source #

Arguments

:: 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.

observeSeconds Source #

Arguments

:: 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.