Monitoring Your Ruby on Rails Application with Vigilmon

ruby dev.to

Monitoring Your Ruby on Rails Application with Vigilmon

Ruby on Rails powers some of the web's most important applications. When your Rails app goes down, external monitoring catches it before your users do. Vigilmon gives you multi-region uptime monitoring with smart false-alert prevention in under 5 minutes.

Adding a Health Check to Rails

Option 1: Simple Health Route

Add to config/routes.rb:

get '/health', to: proc { [200, {}, ['OK']] }
Enter fullscreen mode Exit fullscreen mode

This bypasses Rails middleware entirely for maximum simplicity.

Option 2: Health Check Controller

Create app/controllers/health_controller.rb:

class HealthController < ApplicationController
  skip_before_action :authenticate_user!, raise: false
  skip_before_action :verify_authenticity_token

  def show
    render json: { status: 'ok', timestamp: Time.current.to_i }
  end
end
Enter fullscreen mode Exit fullscreen mode

Add to config/routes.rb:

get '/health', to: 'health#show'
Enter fullscreen mode Exit fullscreen mode

Option 3: Health Check with Database Ping

class HealthController < ApplicationController
  skip_before_action :authenticate_user!, raise: false
  skip_before_action :verify_authenticity_token

  def show
    ActiveRecord::Base.connection.execute('SELECT 1')
    render json: { status: 'ok', db: 'connected' }
  rescue => e
    render json: { status: 'error', error: e.message }, status: :service_unavailable
  end
end
Enter fullscreen mode Exit fullscreen mode

Option 4: Use the health_check Gem

For more comprehensive health checking:

# Gemfile
gem 'health_check'
Enter fullscreen mode Exit fullscreen mode
bundle install
Enter fullscreen mode Exit fullscreen mode
# config/routes.rb
HealthCheck::Engine.routes.prefix = 'health'
Enter fullscreen mode Exit fullscreen mode

Now /health_check returns success or error details for DB, Redis, S3, etc.

Setting Up Vigilmon for Your Rails App

  1. Sign up at vigilmon.online
  2. Click Add Monitor
  3. URL: https://yourapp.com/health
  4. Interval: 1 or 5 minutes
  5. Alert: email + webhook
  6. Save

Vigilmon checks from multiple geographic regions. You only get an alert when 2+ regions agree your app is down — no false alerts from transient network blips.

What to Monitor in a Rails App

Add multiple monitors for comprehensive coverage:

Monitor URL What It Checks
App health /health Server up, DB connected
Homepage / Full render working
Login page /users/sign_in Devise auth not broken
API health /api/v1/health API routes working

Heroku Deployments

Vigilmon works great with Heroku Rails apps. Note that Heroku dyno sleeping (on free tier) can cause false alerts — upgrade to a paid dyno or use Vigilmon's 5-minute interval which is frequent enough to keep dynos awake while monitoring them.

Sidekiq Monitoring Note

Vigilmon monitors HTTP endpoints, not background jobs. For Sidekiq job monitoring, consider adding a /sidekiq/stats endpoint (via the Sidekiq web UI) to your monitors, or use a tool like Healthchecks.io for cron job verification.

# config/routes.rb — Sidekiq stats endpoint (protect this!)
require 'sidekiq/web'
mount Sidekiq::Web => '/sidekiq'
Enter fullscreen mode Exit fullscreen mode

Add a Vigilmon monitor to /health that checks Sidekiq connectivity:

def show
  sidekiq_ok = Sidekiq::Queue.new.latency < 60 rescue false
  render json: {
    status: 'ok',
    sidekiq: sidekiq_ok ? 'ok' : 'degraded'
  }
end
Enter fullscreen mode Exit fullscreen mode

Alert When You Are Asleep

Set up email alerts so you are notified the moment your Rails app goes down, even at 3 AM:

  1. In Vigilmon, go to Alert Channels
  2. Add your email address
  3. Set alert delay to 0 minutes (immediate) or 5 minutes (reduce noise)

For team alerting, add a webhook pointing to your Slack #incidents channel.

Conclusion

Adding a health endpoint to your Rails app takes 5 minutes. Monitoring it with Vigilmon takes 2 more. Together you get multi-region uptime monitoring that catches outages before your users do.

Start free at vigilmon.online — 5 monitors, no credit card, live in 2 minutes.

Source: dev.to

arrow_back Back to Tutorials