class Crometheus::Middleware::HttpCollector
- Crometheus::Middleware::HttpCollector
- Reference
- Object
Overview
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.
Included Modules
- HTTP::Handler
Defined in:
crometheus/middleware/http_collector.crConstant Summary
-
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.
Instance Method Summary
-
#path_cleaner : String -> String
Transforms request paths before labeling metrics, so that multiple paths may be tracked in the same time series.
-
#path_cleaner=(path_cleaner : String -> String)
Transforms request paths before labeling metrics, so that multiple paths may be tracked in the same time series.
Constructor Detail
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.
Instance Method Detail
Transforms request paths before labeling metrics, so that multiple paths may be tracked in the same time series.
Transforms request paths before labeling metrics, so that multiple paths may be tracked in the same time series.