swh.storage.metrics module#
- class swh.storage.metrics.DifferentialTimer(metric: str, tags: Dict[str, str] | None = None)[source]#
Bases:
object
Compute differential timing metrics and send them to StatsD.
The DifferentialTimer will send the
metric
to statsd, computing the difference between the time spent within the whole block, with the time spent within any blocks wrapped in theinner()
decorator.If an exception is raised,when sending the metric, the DifferentialTimer will add a
inner_exc
(when the exception is raised by an inner-timed section) orouter_exc
tag with the name of the exception class that was raised .- Parameters:
metric – name of the timing metric that is sent to StatsD when the context manager exits
tags – tags to attach to the metric when it is sent
Example
To generate a
metric_seconds
timed metric, recording the overhead of runningrun_pre_processing
andrun_post_processing
, use:with DifferentialTimer("metric_seconds") as t: run_pre_processing() with t.inner(): run_inner_method() run_post_processing()