Table Of Contents

This Page



uwsgi_metrics is a port of the Dropwizard Metrics package to the uWSGI stack. It allows you to use functions such as uwsgi_metrics.timing() to gather application-level metrics:

with timing(__name__, 'my_timer'):

You can then invoke the uwsgi_metrics.view() function to get a dictionary of metrics information:

  "version": "1.1.1",
  "counters": {},
  "gauges": {},
  "histograms": {},
  "meters": {},
  "timers": {
    "my_module.my_timer": {
      "count": 22,
      "p98": 4.8198699951171875,
      "m15_rate": 1.0033118138834103,
      "p75": 1.9915103912353516,
      "p99": 4.8198699951171875,
      "min": 1.4159679412841797,
      "max": 4.8198699951171875,
      "m5_rate": 1.0098078505715211,
      "p95": 4.7961950302124023,
      "m1_rate": 1.0454161929696191,
      "duration_units": "milliseconds",
      "stddev": 0.92399302814991413,
      "mean_rate": 1.2074971885928811,
      "rate_units": "calls/second",
      "p999": 4.8198699951171875,
      "p50": 1.649022102355957,
      "mean": 1.9796761599454014

You can wire up uwsgi_metrics.view() to an HTTP endpoint so that you can interactively monitor the performance of your production code.


There are a couple of steps required before you can use uwsgi_metrics:

  1. uWSGI must be started with a mule process; this is done by passing the --mule option to the uWSGI executable.
  2. The uwsgi_metrics.initialize() method must invoked in the master process prior to forking.


It takes approximately 30us to log a metric on a 2.3GHz Xeon E5. The uwsgi_metrics.timing() context manager adds a further 20us, to give a total of approximately 50us.

As a very rough guideline, you’re probably not going to notice the overhead of logging 10 metrics (0.5ms) during a service call, but you will start to notice the overhead of logging 100 metrics (5ms).


uwsgi_metrics.initialize(signal_number=42, update_period_s=5)

Initialize metrics, must be invoked at least once prior to invoking any other method.


Get a dictionary representation of current metrics.

uwsgi_metrics.counter(module, name, count=1)

Record an event’s occurence in a counter:

counter(__name__, 'my_counter')
uwsgi_metrics.histogram(module, name, value)

Record a value in a histogram:

histogram(__name__, 'my_histogram', len(queue))
uwsgi_metrics.meter(module, name, count=1)

Record an event rate:

meter(__name__, 'my_meter', 'event_type')
uwsgi_metrics.timer(module, name, delta, duration_units='milliseconds')

Record a timing delta:

start_time_s = time.time()
end_time_s = time.time()
delta_s = end_time_s - start_time_s
delta_ms = delta_s * 1000
timer(__name__, 'my_timer', delta_ms)
uwsgi_metrics.timing(module, name)

Context manager to time a section of code:

with timing(__name__, 'my_timer'):


Copyright (c) 2010-2015 Coda Hale,

Copyright (c) 2015, Yelp, Inc.

Published under Apache Software License 2.0, see LICENSE.