class Crometheus::Middleware::HttpCollector

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

Defined in:

crometheus/middleware/http_collector.cr

Constant 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

Instance Method Summary

Constructor Detail

def self.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.


[View source]

Instance Method Detail

def path_cleaner : String -> String #

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


[View source]
def path_cleaner=(path_cleaner : String -> String) #

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


[View source]