swh.storage.metrics module#

swh.storage.metrics.timed(f)[source]#

Time that function!

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 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_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 running run_pre_processing and run_post_processing, use:

with DifferentialTimer("metric_seconds") as t:
    run_pre_processing()
    with t.inner():
        run_inner_method()
    run_post_processing()
inner()[source]#

Add the duration of this block to the inner elapsed time counter.

swh.storage.metrics.send_metric(metric, count, method_name)[source]#

Send statsd metric with count for method method_name

If count is 0, the metric is discarded. If the metric is not parseable, the metric is discarded with a log message.

Parameters:
  • metric (str) – Metric’s name (e.g content:add, content:add:bytes)

  • count (int) – Associated value for the metric

  • method_name (str) – Method’s name

Returns:

Bool to explicit if metric has been set or not

swh.storage.metrics.process_metrics(f)[source]#

Increment object counters for the decorated function.