Librato is a great platform to track metrics and has a really simple gem to track your rack based apps, but what if yours is not one? And if you're on Heroku you can't use StatsD... So what do you do?

It turns out that Librato can get metrics from the application's log so by adding a drain to your Heroku app you'll have the simplest metrics tracking library ever:

class Metrics
  def self.increment(metric, amount = 1) "count##{metric}=#{amount}"

  def self.time(metric, **options, &block)
    if block_given?
      start_time =
      total = ( - start_time) * 1000
      total = options[:time]
    end "measure##{metric}=#{total.round}ms" if total

  def self.gauge(metric, amount) "sample##{metric}=#{amount}"

  def self.logger
    @logger ||=
  private_class_method :logger

And now getting metrics from your application is really, really simple:

Metrics.gauge('queue_size', 1)
Metrics.time('expensive_operation') { # do some work }

You can check out all the things you can do with Librato and log metrics at the Heroku DevCenter.

Metrics in your logs

Probably the thing I like the most about this approach is having your metrics in your application log waiting for them to be can be consumed and analyzed from any service... Your application is a producer, Librato is just a consumer.

You could add Kibana with its powerful queries to get stuff out from the metrics (and other data), or have multiple teams consume the metrics and build different applications.

Setting up alerts based on metrics becomes trivial with services like Papertrail

Bottom line, logs are awesome, and you should take advantage of that!