Skip to main content

MBQ Metrics

Project description


$ pip install mbq.metrics

Guaranteed fresh.

Getting started

Initialize mbq.metrics in your like this:

from mbq import env, metrics

ENV = env.get_environment("ENV_NAME")
SERVICE_NAME = 'service-name'
metrics.init(SERVICE_NAME, ENV, constant_tags={'env': ENV_NAME})

HTTP Metrics with Django Middleware

This library also contains a piece of Django middleware you can use to create an awesome HTTP Datadog dashboard for your service! The middleware reports the following metrics to Datadog:

  • Request duration in milliseconds

  • Status codes (200, 404, 503 etc)

  • Status ranges (2xx, 4xx, 5xx, etc)

  • Response content length

  • Request path

Adding the middleware to your Django project and configuring the Datadog dashboard is quick and easy: just include mbq.metrics.contrib.django.middleware.timing.TimingMiddleware in the MIDDLEWARE constant in your file.


HTTP Metrics with WSGI Middleware (Flask)

Middleware is also included that can be easily plugged into a Flask app to generate the same sort of metrics referenced in the Django section above. Requires mbq.metrics >= 0.3.0.

See the implementation in Isengard for an example.


Tests are automatically in Travis CI but you can also run tests locally using docker-compose. We now use tox for local testing across multiple python environments. Before this use pyenv to install the following python interpreters: cpython{2.7, 3.5, 3.6} and pypy3

install and run tox:

$ docker-compose build py36
Building py36
Step 1/5 : ARG IMAGE
Step 2/5 : FROM $IMAGE
 ---> 60cd00be8967
Step 3/5 : WORKDIR /tox
 ---> Running in f55aee265e33
Removing intermediate container f55aee265e33
 ---> 2b31757df863
Step 4/5 : WORKDIR /app
 ---> Running in a1bc5e661ca3
Removing intermediate container a1bc5e661ca3
 ---> 6f1f17a29a8e
Step 5/5 : COPY . .
 ---> 55eef13da5e6
Successfully built 55eef13da5e6
Successfully tagged mbqmetrics_py36:latest
$ docker-compose up py36
Recreating mbqmetrics_py36_1 ... done
Attaching to mbqmetrics_py36_1
py36_1   | Requirement already up-to-date: pip in /usr/local/lib/python3.6/site-packages (18.0)
py36_1   | Collecting tox
py36_1   |   Downloading (62kB)
py36_1   | Collecting tox-venv
py36_1   |   Downloading
py36_1   | Collecting tox-travis
py36_1   |   Downloading
py36_1   | Collecting py<2,>=1.4.17 (from tox)
py36_1   |   Downloading (83kB)
py36_1   | Collecting six<2,>=1.0.0 (from tox)
py36_1   |   Downloading
py36_1   | Requirement already satisfied, skipping upgrade: setuptools>=30.0.0 in /usr/local/lib/python3.6/site-packages (from tox) (40.0.0)
py36_1   | Collecting pluggy<1,>=0.3.0 (from tox)
py36_1   |   Downloading
py36_1   | Collecting virtualenv>=1.11.2 (from tox)
py36_1   |   Downloading (1.9MB)
py36_1   | Installing collected packages: py, six, pluggy, virtualenv, tox, tox-venv, tox-travis
py36_1   | Successfully installed pluggy-0.7.1 py-1.6.0 six-1.11.0 tox-3.2.1 tox-travis-0.10 tox-venv-0.3.1 virtualenv-16.0.0
py36_1   | GLOB sdist-make: /app/
py36_1   | py36-django111 create: /tox/py36-django111
py36_1   | py36-django111 installdeps: ., Django>=1.11,<2.0
py36_1   | py36-django111 inst: /tox/dist/
py36_1   | py36-django111 installed: You are using pip version 10.0.1, however version 18.0 is available.,You should consider upgrading via the 'pip install --upgrade pip' command.,certifi==2018.8.24,chardet==3.0.4,datadog==0.22.0,decorator==4.3.0,Django==1.11.15,idna==2.7,mbq.metrics==0.4.0,pytz==2018.5,requests==2.19.1,simplejson==3.16.0,urllib3==1.23
py36_1   | py36-django111 runtests: PYTHONHASHSEED='2612051782'
py36_1   | py36-django111 runtests: commands[0] | python -Wall -m unittest discover tests
py36_1   | /tox/py36-django111/lib/python3.6/site-packages/datadog/dogstatsd/ DeprecationWarning: invalid escape sequence \:
py36_1   |   return string.replace('\n', '\\n').replace('m:', 'm\:')
py36_1   | ................
py36_1   | ----------------------------------------------------------------------
py36_1   | Ran 16 tests in 0.094s
py36_1   |
py36_1   | OK
# ...snip...

Shipping a New Release

  1. Bump the version in

  2. Go to Releases in GitHub and “Draft a New Release”

  3. After creating a new release, Travis CI will pick up the new release and ship it to PyPi


Where do I put the DogStatsd agent configuration?

You don’t! mbq.metrics is pre-baked with assumptions about how Q runs it’s services. Specifically, we assume that each service runs in a Docker container and that that container is running on a VM that’s running the DogStatsD agent. In that way we can automatically configure our client to reach outside of the container and easily push metrics to the agent. Read more in the datadogpy documentation or in the source.

API Reference


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mbq.metrics-1.1.7.tar.gz (13.9 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page