Crate iota_metrics
source ·Re-exports§
pub use scopeguard;
Modules§
- Provides wrappers to tokio mpsc channels, with metrics on total items sent, received and inflight.
Macros§
Structs§
- A future that runs within a monitored scope. This struct wraps a pinned future and holds an optional
MonitoredScopeGuard
to measure and monitor the execution of the future. It forwards polling operations to the underlying future while maintaining the monitoring scope. - Increments gauge when acquired, decrements when guard drops
- A struct that wraps a future (
f
) with aGaugeGuard
. TheGaugeGuardFuture
is used to manage the lifecycle of a future while ensuring the associatedGaugeGuard
properly tracks the resource usage during the future’s execution. The guard increments the gauge when the future starts and decrements it when theGaugeGuardFuture
is dropped. - A future that runs within a monitored scope. This struct wraps a pinned future and holds an optional
MonitoredScopeGuard
to measure and monitor the execution of the future. It forwards polling operations to the underlying future while maintaining the monitoring scope. - A service to manage the prometheus registries. This service allow us to create a new Registry on demand and keep it accessible for processing/polling. The service can be freely cloned/shared across threads.
Constants§
Traits§
- MonitorCancellation records a cancelled = true span attribute if the future it is decorating is dropped before completion. The cancelled attribute must be added at span creation, as you cannot add new attributes after the span is created.
- A trait extension for
Future
to allow monitoring the execution of the future within a specific scope. Provides thein_monitored_scope
method to wrap the future in aMonitoredScopeFuture
, which tracks the future’s execution using aMonitoredScopeGuard
for monitoring purposes.
Functions§
- Add a new entry to the ServerTiming header. If the caller is not currently in a ServerTiming context (created with
with_new_server_timing
), an error is logged. - Retrieves the global
METRICS
instance if it has been initialized. - Get the currently active ServerTiming context. Only intended for use by macros within this module.
- Initializes the global
METRICS
instance by setting it to a newMetrics
object registered with the providedRegistry
. IfMETRICS
is already set, a warning is logged indicating that the metrics registry was overwritten. This function is intended to be called once during initialization to set up metrics collection. - Handles a request to retrieve metrics, using the provided
RegistryService
to gather all registered metric families. The metrics are then encoded to a text format for easy consumption by monitoring systems. If successful, it returns the metrics string with anOK
status. If an error occurs during encoding, it returns anINTERNAL_SERVER_ERROR
status along with an error message. Returns a tuple containing the status code and either the metrics data or an error description. - This function creates a named scoped object, that keeps track of
- Create a metric that measures the uptime from when this metric was constructed. The metric is labeled with:
- Create a new task-local ServerTiming context and run the provided future within it. Should be used at the top-most level of a request handler. Can be added to an axum router as a layer by using iota_service::server_timing_middleware.
- Create a new task-local ServerTiming context and run the provided future within it. Only intended for use by macros within this module.