class

Crometheus::Middleware::HttpCollector

Inherits HTTP::Handler / Reference / Object

This class is an HTTP::Handler that records basic statistics about every request that comes in, and passes through to the next handler without modifying the request or response. It creates the http_requests_total, http_request_duration_seconds, and http_request_exceptions_total metrics. See the custom-server example for a use case.

Constants

DEFAULT_PATH_CLEANER = ->(path : String) do path.gsub(/\/\d+(?=\/|$)/, "/:id") end

Substitutes ":id" in place of numeric path components, e.g. turning "/forum/102/thread/12" into "/forum/:id/thread/:id".

Constructors

new(registry : Nil | Crometheus::Registry = Crometheus.default_registry, path_cleaner : String -> String | Nil = DEFAULT_PATH_CLEANER)

Initializes the HttpCollector, allowing the user to set the registry to which metrics will be added and the path cleaner. Defaults to Crometheus.default_registry and DEFAULT_PATH_CLEANER. Set path_cleaner to nil to avoid mangling paths altogether.

Source

Instance methods

path_cleaner

Transforms request paths before labeling metrics, so that multiple paths may be tracked in the same time series.

Source
path_cleaner=(path_cleaner : String -> String)

Transforms request paths before labeling metrics, so that multiple paths may be tracked in the same time series.

Source

Nested types