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 - metricto statsd, computing the difference between the time spent within the whole block, with the time spent within any blocks wrapped in the- inner()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) or- outer_exctag 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_secondstimed metric, recording the overhead of running- run_pre_processingand- run_post_processing, use:- with DifferentialTimer("metric_seconds") as t: run_pre_processing() with t.inner(): run_inner_method() run_post_processing()