A Flask Extension for simple statsd integration
MIT License
This project requires Python 3.5+ and Flask 0.12. Test builds in Travis CI test 3.5 & 3.6.
To install it, simply run
pip install flask-statsdclient
If you're using Datadog(https://www.datadoghq.com/) for your metric collection, you can enable the additional functionality of dogstatsd(http://datadogpy.readthedocs.io/en/latest/#datadog-dogstatsd-module) by installing it via
pip install flask-statsdclient[Datadog]
Import it and wrap app
from flask import Flask
from flask_statsdclient import StatsDClient
app = Flask(__name__)
statsd = StatsDClient(app)
You may modify the host, port and prefix with STATSD_HOST
, STATSD_PORT
and
STATSD_PREFIX
options respectively in your Flask app config.
If you are using Datadog with a Unix socket, instead of specifying the host & port in config,
add DD_SOCKET
which is a fully qualified Unix path to the socket.
On a mac you can use the following commands to get up and running.
brew install python3
otherwise run
brew upgrade python3
to make sure you have an up to date version.
This project uses pip-tools for dependency management. Install pip-tools
pip3 install pip-tools
setup the project env
python -m venv venv
pip install -r requirements.txt -r requirements-dev.txt
Make sure the following environment variables are set
export PYTHONPATH=`pwd`
Then load your virtualenv
source venv/bin/activate
./linters.sh && coverage run --source=flask_statsdclient/ setup.py test
We have a pre-commit hook each dev needs to setup. You can symlink it to run before each commit by changing directory to the repo and running
cd .git/hooks
ln -s ../../pre-commit pre-commit