Skip to content

Sending Dokku Container Logs to Papertrail

Tags: devops • Categories: Software

Table of Contents

I’m a huge fan of Heroku. Although it’s expensive compared to a raw DigitalOcean droplet or EC2 instance, it’s so easy and it just works.

However, there are some use-cases that Heroku doesn’t handle well. Business integration systems (eCommerce NetSuite integration, for example) often require handling requests that may take longer than the 30 second request timeout.

Dokku is the next-best alternative to using heroku (if you don’t have enormous scaling needs: dokku apps are restricted to a single host). Here’s how to push your dokku app logs running to PaperTrail, or another syslog-compatible cloud hosting provider (I’m sure this approach would work for Loggly or CloudWatch).

  1. Install dokku-logspout: dokku plugin:install https://github.com/michaelshobbs/dokku-logspout.git
  2. Point logspout to your PaperTrail syslog endpoint: dokku logspout:server syslog+tls://logs.papertrailapp.com:12345. Make sure your PaperTrail endpoint is configured to accept TLS connections.
  3. Install dokku-hostname: dokku plugin:install https://github.com/michaelshobbs/dokku-hostname.git dokku-hostname. This will ensure that the host in your PaperTrail logs use the heroku-like name of your worker instead of the docker container ID.
  4. Run dokku logspout:start and use logspout:stream to ensure that your logs are being aggregated properly.

The resulting log output should look something like:

Apr 15 14:49:28 host.com pipeline.worker.1:  /app/vendor/bundle/ruby/2.3.0/gems/sidekiq-4.1.1/lib/sidekiq/processor.rb:167:in `stats'
Apr 15 14:49:28 host.com pipeline.worker.1:  /app/vendor/bundle/ruby/2.3.0/gems/sidekiq-4.1.1/lib/sidekiq/processor.rb:127:in `process'
Apr 15 14:49:28 host.com pipeline.worker.1:  /app/vendor/bundle/ruby/2.3.0/gems/sidekiq-4.1.1/lib/sidekiq/processor.rb:79:in `process_one'
Apr 15 14:49:28 host.com pipeline.worker.1:  /app/vendor/bundle/ruby/2.3.0/gems/sidekiq-4.1.1/lib/sidekiq/processor.rb:67:in `run'
Apr 15 14:49:28 host.com pipeline.worker.1:  /app/vendor/bundle/ruby/2.3.0/gems/sidekiq-4.1.1/lib/sidekiq/util.rb:16:in `watchdog'
Apr 15 14:49:28 host.com pipeline.worker.1:  /app/vendor/bundle/ruby/2.3.0/gems/sidekiq-4.1.1/lib/sidekiq/util.rb:24:in `block in safe_thread'
Apr 15 14:49:28 host.com pipeline.worker.1:  11 TID-os97lykxo INFO: [Rollbar] Scheduling payload

Here’s a couple issues you may run into:

  • You may need to rebuild your apps for them to start piping to logspout. dokku ps:rebuildall
  • When you re-deploy your apps, the heroku-like program names will be lost. To fix this run dokku logspout:stop && dokku logspout:start. Hopefully this issue will be fixed soon.
  • docker ps returns a daemon error. Run sudo usermod -aG docker ubuntu && sudo reboot as ubuntu.

Keep in Touch

Subscribe to my email list to keep in touch. I’ll send you new blog posts and other thoughts.