Monitoring Django apps on Heroku

July 31 Bullet_white By Derek Bullet_white Comments Comments

I don't know of an easier way to deploy a Django app than letting Heroku do the work. That said, how do you stay on top of your app's performance, errors, and stability post-launch? Running an app on Heroku is a blissful experience, but it presents some monitoring challenges that aren't present when you control the hardware.

In this post, I'll walk through a free-to-start, low-effort approach that gives you great visibility of the health of your Django app on Heroku. All of the services below either have Django-specific support or don't require a significant time investment to work with a Django app.

Focus Service
UptimeUptime Robot
Application Performance MonitoringScout
LoggingLogDNA
Exception MonitoringRollbar
Custom MetricsHostedGraphite
Resource usageHeroku Application Metrics

Monitoring coverage areas

Here's the primary areas you'll want to monitor on a production Django app:

  • Uptime - is the app reachable from around the globe?
  • Application Performance Monitoring - when performance goes bad, dive to the the line-of-code causing the issue.
  • Logging - view your application and Heroku logs.
  • Exception Monitoring - aggregate, view, and close exceptions.
  • Custom Metrics - track key performance indicators that are specific to your app.
  • Resource usage - track memory usage and CPU load.

I'll cover each area in detail below.

Uptime

Is my Django app up? Whether you are hosting a personal blog or on the stability team for Netflix, you need this. I don't believe there is a free Heroku addon for uptime monitoring, so I'd suggest Uptime Robot. Uptime Robot has a free plan that checks if your site is up every five minutes.

Application Performance Monitoring

When it comes to tracking down performance issues, application performance monitoring (APM) gives the most value with the least effort. These services have libraries that trace the execution of your code, SQL queries, external HTTP requests and more, pointing to the line-of-code when there is a performance problem. Adding this instrumentation yourself would be painful.

The Scout Heroku Addon is an easy-to-configure APM option for Django apps. Once the addon is provisioned and the scout-apm package is installed, Scout traces each web request and breaks down time spent in Python code, SQL queries, HTTP requests, Redis queries, and more. Scout automatically identifies problems like N+1 database queries which are hard to reproduce in development.

Logging

Heroku’s log history only goes back 1500 lines, which could just be a couple of seconds of logs for a production Django app. This means you have to send your log stream somewhere for meaningful data retention and querying. LogDNA is an easy option on Heroku that requires virtually no configuration.

Exception Monitoring

Exception Monitoring tools make it easy to track exceptions down to a line-of-code, saving you valuable development time hunting down bugs. They also aggregate similar errors together to decrease noise when things are going wrong.

Rollbar is an easy-to-configure, reliable option for monitoring Django exceptions. Scout also integrates with Rollbar, giving you a single pane of glass for both performance and errors.

Custom Metrics

Your app has personal indicators that indicate its health (and the health of your business). For example, a shopping cart app may track the number of times an item has been added to its cart.

If you aren't on Heroku, StatsD is a great generic option. While it is possible to configure StatsD on Heroku, it is involved. A simpler option for custom metrics is HostedGraphite.

Resource Usage

There's no need to use another service to monitor basic metrics like memory usage and CPU load. If you are using Hobby dynos or higher, you get high-level resource usage metrics and alerting for free within your Heroku dashboard. Just enable application metrics.

Get notified of new posts.

Once a month, we'll deliver a finely-curated selection of optimization tips to your inbox.

Comments

comments powered by Disqus