Rails Pulse 是一款全面的性能监控和调试工具,可提供有关 Rails 应用程序运行状况的详细信息。
Self-hosted performance monitoring for Rails apps
Rails Pulse is a Rails engine that monitors your app's performance from the inside. It tracks slow requests, N+1 queries, SQL performance, background jobs, and unhandled exceptions. All data stays in your own database, no third-party cloud, no SaaS subscription, no data leaving your servers.
Add to your Gemfile:
gem 'rails_pulse'Run the installer:
bundle install
rails generate rails_pulse:install
rails db:migrateMount the dashboard in config/routes.rb:
Rails.application.routes.draw do
mount RailsPulse::Engine => "/rails_pulse"
endSchedule the background jobs:
RailsPulse::SummaryJob.perform_later # cron: 5 * * * *
RailsPulse::CleanupJob.perform_later # cron: 0 1 * * *Your dashboard is now at http://localhost:3000/rails_pulse.
From 0.3.3:
bundle update rails_pulse
rails generate rails_pulse:upgrade
rails db:migrate # or: rails db:migrate:rails_pulse
rails rails_pulse:migrate_routes # required — fills Action and merges same-action pathsRestart all processes after migrate. This release changes how routes are stored (method moves off the route onto each request), so mixed old/new processes are not supported.
The upgrade generator appends new settings to config/initializers/rails_pulse.rb without rewriting what you already set. Review with git diff and keep or discard hunks.
To see where an install stands at any point — schema, unrun migration files, route backfill, initializer — run rails rails_pulse:status. It exits 1 when something needs action, so it can gate a deploy.
Exception tracking is off for existing installs. The generator inserts config.track_exceptions = false; set it to true after migrating to opt in:
config.track_exceptions = true
config.capture_exception_params = true # params are filtered via Rails' filter_parametersSeparate-database hosts: set schema_dump: false on the rails_pulse entry in config/database.yml and delete db/rails_pulse_structure.sql if that file exists.
If you previously added rails-pulse.js / rails-pulse.css to config.assets.precompile, remove those entries — the gem no longer registers dashboard assets with Sprockets (that re-minify OOMs small hosts). Production deploys that use config.asset_host or a CDN-only CSP should run assets:precompile so rails_pulse:install_assets copies digested files into public/assets.
Full install guide: railspulse.com/documentation/installation
Separate database setup: railspulse.com/documentation/database
Rails Pulse works out of the box with sensible defaults. To customise, edit config/initializers/rails_pulse.rb:
RailsPulse.configure do |config|
config.enabled = true
config.request_thresholds = {
slow: 700,
very_slow: 2000,
critical: 4000
}
config.track_jobs = true
config.capture_job_arguments = false # keep false to protect sensitive data
config.track_exceptions = true
config.capture_exception_params = true # params are filtered via Rails' filter_parameters
config.full_retention_period = 30.days
endFull configuration reference: railspulse.com/documentation/advanced
Rails Pulse has no built-in user accounts; you protect the dashboard using your app's existing auth. Authentication is on by default outside development and test, and with nothing configured it falls back to HTTP Basic against RAILS_PULSE_USERNAME / RAILS_PULSE_PASSWORD (denying everything if the password is unset).
The simplest hook is a predicate that receives the controller and returns true to allow — anything else is a 403:
RailsPulse.configure do |config|
config.authorize = ->(controller) { controller.current_user&.admin? }
endIf you need to redirect to a login page instead, use authentication_method, which runs inside the controller and denies by rendering or redirecting:
RailsPulse.configure do |config|
config.authentication_redirect_path = "/login"
config.authentication_method = proc {
unless user_signed_in? && current_user.admin?
redirect_to main_app.root_path, alert: "Access denied"
end
}
endReturning false from authentication_method without responding is also treated as a denial, but nil (what unless … end returns on success) allows the request — so keep predicate-style checks in authorize.
Authentication guide: railspulse.com/documentation/authentication
Bug reports and pull requests are welcome on GitHub.
Available as open source under the MIT License.
暂无开放 Issues,或尚未同步最近议题。