Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Full-Stack Monitoring with django-watchman

Full-Stack Monitoring with django-watchman

My Pycon Canada 2015 presentation about the open-source project django-watchman I wrote to make it easier to monitor your application + backing services (caches, databases, etc.)

Michael Warkentin

November 08, 2015
Tweet

More Decks by Michael Warkentin

Other Decks in Technology

Transcript

  1. # requirements.txt pip install django-watchman # settings.py INSTALLED_APPS = (

    ... 'watchman', ) # urls.py url(r'^watchman/', include('watchman.urls')),
  2. HTTP://127.0.0.1:8000/WATCHMAN/ { "databases": [ { "default": { "ok": true }

    } ], "caches": [ { "default": { "ok": true } } ], "storage": { "ok": true } }
  3. DB Config Error { "databases": [ { "default": { "ok":

    false, "error": "django.db.utils.OperationalError: (1045, "Access denied for user ...")", "traceback": "<full traceback>" } } ] }
  4. $ python manage.py watchman -v 2 {"storage": {"ok": true}} {"caches":

    [{"default": {"ok": true}}]} {"databases": [{"default": {"ok": true}}]} $ echo $? 0
  5. def rabbitmq_connection_check(): try: conn_params = pika.ConnectionParameters( settings.PIKA_CONNECTION_PARAMS['hostname'], settings.PIKA_CONNECTION_PARAMS['port'], settings.PIKA_CONNECTION_PARAMS['vhost'], pika.PlainCredentials(

    settings.PIKA_CONNECTION_PARAMS['username'], settings.PIKA_CONNECTION_PARAMS['password'] ) ) connection = pika.BlockingConnection(conn_params) connection.close() return {'ok': True} except Exception as e: return { 'ok': False, 'error': unicode(e), 'stacktrace': traceback.format_exc(), }
  6. RESTRICT BY USER ID # core/watchman_auth.py def userid_is_one(view_func): @csrf_exempt @wraps(view_func)

    def _wrapped_view(request, *args, **kwargs): if request.user.id == 1: return view_func(request, *args, **kwargs) return HttpResponseForbidden() return _wrapped_view # settings.py WATCHMAN_AUTH_DECORATOR = 'core.watchman_auth.userid_is_one'
  7. SPRINTS Come hack on django-watchman during sprints, or get help

    configuring for your own site https://github.com/mwarkentin/django-watchman @mwarkentin