RailsHealthMonitor
A comprehensive health checking gem for Ruby on Rails applications and their dependencies.
Features
- Rails Version Check: Validates Rails version compatibility
- Ruby Version Check: Ensures Ruby version is supported
- Database Connectivity: Tests database connection health
- Gem Dependencies: Analyzes gem health and outdated packages
- Security Vulnerabilities: Checks for known security issues
- HTTP Health Endpoint: Provides
/healthendpoint for monitoring - Rake Tasks: Command-line health checking tools
Installation
Add this line to your application's Gemfile:
gem 'rails-health-monitor'
And then execute:
bundle install
Or install it directly:
gem install rails-health-monitor
Usage
Programmatic Usage
# Run complete health check
results = RailsHealthMonitor.check
# Check specific components
analyzer = RailsHealthMonitor::GemAnalyzer.new
gem_health = analyzer.analyze
Rake Tasks
# Complete health check
rake health:check
# Check gem dependencies only
rake health:gems
# Check database connectivity
rake health:database
HTTP Health Dashboard
The gem automatically adds protected /health endpoints with comprehensive web dashboards:
# Main dashboard (requires authentication)
http://localhost:3000/health
Authentication:
- Default: username
admin, passwordhealth123 - Custom: Set
HEALTH_USERNAMEandHEALTH_PASSWORDenvironment variables
Dashboard Features:
- 🏥 Visual health overview with status indicators
- 📊 Real-time health score (0-100)
- 🔧 System information (Rails/Ruby versions)
- 💾 Database connectivity status
- 📦 Gem dependencies analysis
- 🔒 Security vulnerability overview with detailed list
- 🎯 Priority actions with color-coded urgency
- 🔄 Auto-refresh every 30 seconds
- 🔐 Password-protected access
Configuration
The gem works out of the box with minimal configuration. The health middleware is automatically added to your Rails application.
Authentication Configuration
# Set custom credentials (optional)
export HEALTH_USERNAME=your_username
export HEALTH_PASSWORD=your_secure_password
Default credentials:
- Username:
admin - Password:
health123
Manual Setup Options
Option 1: Middleware Setup (Recommended)
Add to config/application.rb:
require 'rails_health_monitor'
module YourAppName
class Application < Rails::Application
config.middleware.use RailsHealthMonitor::DashboardMiddleware
end
end
Option 2: Routes Setup (Alternative)
Add to config/routes.rb:
Rails.application.routes.draw do
get '/health', to: proc { |env|
results = RailsHealthMonitor.check
[200, {'Content-Type' => 'application/json'}, [results.to_json]]
}
end
Then restart your server:
rails server
Troubleshooting
"No route matches [GET] '/health'" Error
If you get this error, the middleware isn't loaded. Try:
- Manual middleware setup (see above)
- Restart your Rails server:
bash rails server - Verify gem installation:
bash bundle install bundle list | grep rails-health-monitor
Development
After checking out the repo, run:
bundle install
To run tests:
bundle exec rspec
Building and Publishing
To build the gem:
bundle exec rake build
To release a new version:
bundle exec rake release
This will:
- Build the gem
- Create a git tag for the version
- Push the tag to GitHub
- Push the gem to RubyGems.org
Links
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
License
The gem is available as open source under the terms of the MIT License.
Made with ❤️ by Arshdeep Singh