Docs/Rails

Rails

Add monitoring to your Rails app. Health check route, recurring ActiveJob heartbeats, and status badge.

1

Health endpoint

config/routes.rb

get "/api/health", to: "health#show"

app/controllers/health_controller.rb

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

  def show
    render json: { status: "ok" }
  end
end
2

Heartbeat push (optional)

Use a recurring job with Sidekiq or GoodJob. This example uses Sidekiq with sidekiq-cron.

gem "sidekiq-cron"

app/jobs/heartbeat_job.rb

class HeartbeatJob < ApplicationJob
  queue_as :default

  def perform
    checks = {}

    # Database check
    db_start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
    begin
      ActiveRecord::Base.connection.execute("SELECT 1")
      checks[:database] = {
        status: "ok",
        latency: ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - db_start) * 1000).round
      }
    rescue => e
      checks[:database] = {
        status: "error",
        latency: ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - db_start) * 1000).round,
        message: e.message
      }
    end

    # Redis check
    redis_start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
    begin
      Redis.current.ping
      checks[:redis] = {
        status: "ok",
        latency: ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - redis_start) * 1000).round
      }
    rescue => e
      checks[:redis] = {
        status: "error",
        latency: ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - redis_start) * 1000).round
      }
    end

    has_error = checks.values.any? { |c| c[:status] == "error" }

    uri = URI("https://www.bluemonitor.org/api/v1/heartbeat")
    Net::HTTP.post(
      uri,
      {
        domain: "yourapp.com",
        status: has_error ? "error" : "ok",
        timestamp: Time.now.utc.iso8601,
        checks: checks
      }.to_json,
      "Authorization" => "Bearer #{ENV['BLUEMONITOR_API_KEY']}",
      "Content-Type" => "application/json"
    )
  end
end

config/initializers/sidekiq_cron.rb

Sidekiq::Cron::Job.create(
  name: "BlueMonitor heartbeat",
  cron: "*/5 * * * *",
  class: "HeartbeatJob"
)
3

Status badge

ERB template

<a href="https://www.bluemonitor.org/status/your-domain-com">
  <img
    src="https://www.bluemonitor.org/api/badge/your-domain-com"
    alt="Status on BlueMonitor"
    height="36"
  />
</a>

Markdown (README.md)

[![Status](https://www.bluemonitor.org/api/badge/your-domain-com)](https://www.bluemonitor.org/status/your-domain-com)
4

Bot tracking

PRO

Track which search engines, AI crawlers, and social bots visit your app. Add bot detection middleware to report visits to BlueMonitor. Requires a Pro plan.

app/middleware/bot_tracking_middleware.rb

class BotTrackingMiddleware
  BOT_PATTERNS = [
    [/Googlebot/i, "googlebot", "search_engine"],
    [/bingbot/i, "bingbot", "search_engine"],
    [/GPTBot/i, "gptbot", "ai_crawler"],
    [/ClaudeBot/i, "claudebot", "ai_crawler"],
    [/PerplexityBot/i, "perplexitybot", "ai_crawler"],
    [/Twitterbot/i, "twitterbot", "social"],
    [/facebookexternalhit/i, "facebookbot", "social"],
    [/AhrefsBot/i, "ahrefsbot", "seo"],
  ].freeze

  def initialize(app)
    @app = app
  end

  def call(env)
    ua = env["HTTP_USER_AGENT"] || ""
    bot = identify_bot(ua)
    if bot
      Thread.new do
        uri = URI("https://www.bluemonitor.org/api/v1/bot-visits")
        Net::HTTP.post(uri, {
          domain: "yourapp.com",
          visits: [{
            bot_name: bot[:name],
            bot_category: bot[:category],
            path: env["PATH_INFO"],
            user_agent: ua,
          }]
        }.to_json,
          "Authorization" => "Bearer #{ENV['BLUEMONITOR_API_KEY']}",
          "Content-Type" => "application/json"
        )
      rescue StandardError
      end
    end
    @app.call(env)
  end

  private

  def identify_bot(ua)
    BOT_PATTERNS.each do |pattern, name, category|
      return { name: name, category: category } if ua.match?(pattern)
    end
    nil
  end
end

# config/application.rb
# config.middleware.use BotTrackingMiddleware

View results in your dashboard under Bot Tracking.

Using an AI coding tool?

Paste this URL in Claude, Cursor, or Copilot and it will set up monitoring for your Rails app automatically.

https://www.bluemonitor.org/llm-rails.txt

Next steps