lantern-rails
Postgres health monitoring for Rails apps. Collects database metrics and sends them to Lantern — a hosted dashboard that scores your database health and surfaces actionable recommendations.
Installation
Add to your Gemfile:
gem "lantern-rails"Then run:
bundle install
Quick start
- Sign up for a free API key at uselantern.dev
- Run the installer:
rails generate lantern:install
- Add your API key to the generated initializer (
config/initializers/lantern.rb) via environment variable or Rails credentials:
LANTERN_API_KEY=lnt_your_key_here
- Deploy — Lantern starts collecting automatically.
That's it. Open uselantern.dev to see your dashboard.
Configuration
Lantern::Rails.configure do |config|
config.api_key = ENV["LANTERN_API_KEY"]
config.host = "https://uselantern.dev" # default
config.interval = 300 # seconds, default 5 min
config.collect_in_environments = %w[production staging] # default
endDeploy tracking
To correlate deploys with health score changes, call this from your deploy pipeline or a Rails initializer that runs after deploy:
Lantern::Rails.report_deployOr pass explicit values:
Lantern::Rails.report_deploy(
git_sha: ENV["GIT_SHA"],
git_author: ENV["GIT_AUTHOR"],
deployer: "github-actions"
)What gets collected
Every collection interval, the gem queries your Postgres instance for:
- Buffer and index cache hit ratios
- Unused index count and total size
- Table bloat ratio
- Long-running queries (> 30 seconds)
- Dead tuple counts and vacuum status
- Active connections vs. max_connections
- pg_stat_bgwriter stats_reset timestamp (to detect false positives)
No query text, no table data, no PII. Only aggregate pg_stat_* metrics.
Requirements
- Ruby >= 3.1
- Rails >= 7.0
- PostgreSQL (any version with pg_stat_statements)
License
MIT