Rails App Monitoring (APM) with StatsD

May 17 Bullet_white By Mark Bullet_white Posted in HowTo, Features Bullet_white Comments Comments

Application monitoring doesn't have to be complicated. Introducing scout_statsd_rack, a drop-in Ruby gem for monitoring key performance metrics in your Rails app.

scout_statsd_rack leverages StatsD for lightweight Rails app monitoring via Rack middleware.

Lets see how fast we can go from no monitoring to a Rails performance dashboard plus alerting.

rails app monitoring

Implementation

To make quick work of this, we are going to use Scout, our hosted monitoring service, vs. rolling our own StatsD infrastructure.

The Scout monitoring agent, Scoutd, has a statsd aggregator built in. It will send Scout any StatsD metrics you have defined in your code.

1 Make sure you've got the latest version of Scoutd installed on your application server.

2 Add scout_statsd_rack to the applications Gemfile:

gem 'scout_statsd_rack'

3 In your terminal:

$ bundle install

4 Deploy.

Browse around on your site for a few minutes - and then check your Scout account. Custom metrics will be available to you directly from the header navigation:

header

...and when creating dashboards:

sidebar

Alerting

So what good is a metric if we don't have an alert on it? Let's get notified on the most important app monitoring metric of all: the error rate.

From the Scout UI, navigate to the "All Servers" role click the button to add a trigger template to a Custom Metric:

role

We're adding this to the special "All Servers" role so that any server that reports this metric will be monitored (whether it exists now or is added later). Pretty cool, huh?

Next, setup the trigger so that it looks like this:

trigger

This will trigger an alert when the rate of errors exceeds 5 per-minute.

Do you have a way to trigger exceptions in your app? If so, go back to your app and trigger some more error messages. In a few minutes, you'll get a notification. Wait a couple more minutes, and you'll get a notification that everything has returned back to normal

Conclusion

scout_statsd_rack is a dead simple way to implement lightweight Rails app monitoring. With Scout, you've got a beautiful way to view and customize your metrics - and create robust alerting around them.

With just a few lines of code and couple minutes of work, we've got:

  • 12+ App Performance Metrics
  • Customizable Dashboard
  • Configurable Alerts

Scout makes StatsD fast & easy!

Thanks for reading, and be sure to follow us on Twitter for more on leveraging StatsD.

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