Package: mbq.metrics
Installation$pipinstallmbq.metrics🚀✨Guaranteed fresh.Getting startedInitialize mbq.metrics in yoursettings.pylike this:frommbqimportenv,metricsENV=env.get_environment("ENV_NAME")SERVICE_NAME='service-name'metrics.init(SERVICE_NAME,ENV,constant_tags={'env':ENV_NAME})HTTP Metrics with Django MiddlewareThis library also contains a piece of Django middleware you can use to create an awesomeHTTP Datadog dashboardfor your service! The middleware reports the following metrics to Datadog:Request duration in millisecondsStatus codes (200, 404, 503 etc)Status ranges (2xx, 4xx, 5xx, etc)Response content lengthRequest pathAdding the middleware to your Django project and configuring the Datadog dashboard is quick and easy: just includembq.metrics.contrib.django.middleware.timing.TimingMiddlewarein theMIDDLEWAREconstant in yoursettings.pyfile.Tada!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.Seethe implementation in Isengardfor an example.TestingTests are automatically inTravis CIbut you can also run tests locally usingdocker-compose.
We now usetoxfor local testing across multiple python environments. Before this usepyenvto install the following python interpreters: cpython{2.7, 3.5, 3.6} and pypy3install and run tox:$docker-composebuildpy36Buildingpy36Step1/5:ARGIMAGEStep2/5:FROM$IMAGE--->60cd00be8967Step3/5:WORKDIR/tox--->Runninginf55aee265e33Removingintermediatecontainerf55aee265e33--->2b31757df863Step4/5:WORKDIR/app--->Runningina1bc5e661ca3Removingintermediatecontainera1bc5e661ca3--->6f1f17a29a8eStep5/5:COPY..--->55eef13da5e6Successfullybuilt55eef13da5e6Successfullytaggedmbqmetrics_py36:latest$docker-composeuppy36Recreatingmbqmetrics_py36_1...doneAttachingtombqmetrics_py36_1py36_1|Requirementalreadyup-to-date:pipin/usr/local/lib/python3.6/site-packages(18.0)py36_1|Collectingtoxpy36_1|Downloadinghttps://files.pythonhosted.org/packages/df/53/13660f04ef09ece4aefcce6b8f79c1586fc34dee1cbedd7c153e02f93489/tox-3.2.1-py2.py3-none-any.whl(62kB)py36_1|Collectingtox-venvpy36_1|Downloadinghttps://files.pythonhosted.org/packages/bd/bd/f981a5bcd5b90b65fbfd3e6d6d93d592721e2e946eaa08e9ea5d325a4077/tox_venv-0.3.1-py2.py3-none-any.whlpy36_1|Collectingtox-travispy36_1|Downloadinghttps://files.pythonhosted.org/packages/a0/f0/55a0d561161ceac9da512d221547cd0405f0cbf5dfba7352cd36d7bfdace/tox_travis-0.10-py2.py3-none-any.whlpy36_1|Collectingpy<2,>=1.4.17(fromtox)py36_1|Downloadinghttps://files.pythonhosted.org/packages/c8/47/d179b80ab1dc1bfd46a0c87e391be47e6c7ef5831a9c138c5c49d1756288/py-1.6.0-py2.py3-none-any.whl(83kB)py36_1|Collectingsix<2,>=1.0.0(fromtox)py36_1|Downloadinghttps://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whlpy36_1|Requirementalreadysatisfied,skippingupgrade:setuptools>=30.0.0in/usr/local/lib/python3.6/site-packages(fromtox)(40.0.0)py36_1|Collectingpluggy<1,>=0.3.0(fromtox)py36_1|Downloadinghttps://files.pythonhosted.org/packages/f5/f1/5a93c118663896d83f7bcbfb7f657ce1d0c0d617e6b4a443a53abcc658ca/pluggy-0.7.1-py2.py3-none-any.whlpy36_1|Collectingvirtualenv>=1.11.2(fromtox)py36_1|Downloadinghttps://files.pythonhosted.org/packages/b6/30/96a02b2287098b23b875bc8c2f58071c35d2efe84f747b64d523721dc2b5/virtualenv-16.0.0-py2.py3-none-any.whl(1.9MB)py36_1|Installingcollectedpackages:py,six,pluggy,virtualenv,tox,tox-venv,tox-travispy36_1|Successfullyinstalledpluggy-0.7.1py-1.6.0six-1.11.0tox-3.2.1tox-travis-0.10tox-venv-0.3.1virtualenv-16.0.0py36_1|GLOBsdist-make:/app/setup.pypy36_1|py36-django111create:/tox/py36-django111py36_1|py36-django111installdeps:.,Django>=1.11,<2.0py36_1|py36-django111inst:/tox/dist/mbq.metrics-0.4.0.zippy36_1|py36-django111installed:Youareusingpipversion10.0.1,howeverversion18.0isavailable.,Youshouldconsiderupgradingviathe'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.23py36_1|py36-django111runtests:PYTHONHASHSEED='2612051782'py36_1|py36-django111runtests:commands[0]|python-Wall-munittestdiscovertestspy36_1|/tox/py36-django111/lib/python3.6/site-packages/datadog/dogstatsd/base.py:306:DeprecationWarning:invalidescapesequence\:py36_1|returnstring.replace('\n','\\n').replace('m:','m\:')py36_1|................py36_1|----------------------------------------------------------------------py36_1|Ran16testsin0.094spy36_1|py36_1|OK# ...snip...Shipping a New ReleaseBump the version insetup.pyGo toReleasesin GitHub and “Draft a New Release”After creating a new release, Travis CI will pick up the new release and ship it to PyPiFAQsWhere do I put the DogStatsd agent configuration?You don’t!mbq.metricsis 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 thedatadogpy documentationorin the source.API ReferenceContributing