0.0
The project is in a healthy, maintained state
Postgres monitoring collector for Rails apps — sends health metrics to Lantern.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

>= 7.0
 Project Readme

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

  1. Sign up for a free API key at uselantern.dev
  2. Run the installer:
rails generate lantern:install
  1. 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
  1. 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
end

Deploy 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_deploy

Or 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