• Stars
    star
    793
  • Rank 57,419 (Top 2 %)
  • Language
    Ruby
  • License
    MIT License
  • Created almost 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Monitor performance of you Rails applications (self-hosted and free)

Rails Performance

Tests RailsJazz https://www.patreon.com/igorkasyanchuk Listed on OpenSource-Heroes.com

A self-hosted tool to monitor the performance of your Ruby on Rails application.

This is a simple and free alternative to the New Relic APM, Datadog or other similar services.

Demo

It allows you to track:

  • real-time monitoring on the Recent tab
  • monitor slow requests
  • throughput report (see amount of RPM (requests per minute))
  • an average response time
  • the slowest controllers & actions
  • total duration of time spent per request, views rendering, DB
  • SQL queries, rendering logs in "Recent Requests" section
  • simple 500-crashes reports
  • Sidekiq jobs
  • Delayed Job jobs
  • Grape API inside Rails app
  • Rake tasks performance
  • Custom events wrapped with RailsPerformance.measure do .. end block
  • works with Rails 4.2+ (and probably 4.1, 4.0 too) and Ruby 2.2+

All data are stored in local Redis and not sent to any 3rd party servers.

Production

Gem is production-ready. At least on my 2 applications with ~800 unique users per day it works perfectly.

Just don't forget to protect performance dashboard with http basic auth or check of current_user.

Usage

1. Add gem to the Gemfile (in appropriate group if needed)
2. Start rails server
3. Make a few requests to your app
4. open localhost:3000/rails/performance
5. Tune the configuration and deploy to production

Default configuration is listed below. But you can override it.

Create config/initializers/rails_performance.rb in your app:

RailsPerformance.setup do |config|
  config.redis    = Redis::Namespace.new("#{Rails.env}-rails-performance", redis: Redis.new)
  config.duration = 4.hours

  config.debug    = false # currently not used>
  config.enabled  = true

  # configure Recent tab (time window and limit of requests)
  # config.recent_requests_time_window = 60.minutes
  # config.recent_requests_limit = nil # or 1000

  # configure Slow Requests tab (time window, limit of requests and threshold)
  # config.slow_requests_time_window = 4.hours # time window for slow requests
  # config.slow_requests_limit = 500 # number of max rows
  # config.slow_requests_threshold = 500 # number of ms

  # default path where to mount gem,
  # alternatively you can mount the RailsPerformance::Engine in your routes.rb
  config.mount_at = '/rails/performance'

  # protect your Performance Dashboard with HTTP BASIC password
  config.http_basic_authentication_enabled   = false
  config.http_basic_authentication_user_name = 'rails_performance'
  config.http_basic_authentication_password  = 'password12'

  # if you need an additional rules to check user permissions
  config.verify_access_proc = proc { |controller| true }
  # for example when you have `current_user`
  # config.verify_access_proc = proc { |controller| controller.current_user && controller.current_user.admin? }

  # store custom data for the request
  # config.custom_data_proc = proc do |env|
  #   request = Rack::Request.new(env)
  #   {
  #     email: request.env['warden'].user&.email, # if you are using Devise for example
  #     user_agent: request.env['HTTP_USER_AGENT']
  #   }
  # end

  # config home button link
  config.home_link = '/'

  config.skipable_rake_tasks = ['webpacker:compile']
end if defined?(RailsPerformance)

Installation

Add this line to your application's Gemfile:

gem 'rails_performance'

# or

group :development, :production do
  gem 'rails_performance'
end

And then execute:

$ bundle

Create default configuration file:

$ rails generate rails_performance:install

Have a look at config/initializers/rails_performance.rb and adjust the configuration to your needs.

You must also have installed Redis server, because this gem is storing data into it.

After installation and configuration, start your Rails application, make a few requests, and open https://localhost:3000/rails/performance URL.

Alternative: Mounting the engine yourself

If you, for whatever reason (company policy, devise, ...) need to mount RailsPerformance yourself, feel free to do so by using the following snippet as inspiration. You can skip the mount_at and http_basic_authentication_* configurations then, if you like.

# config/routes.rb
Rails.application.routes.draw do
  ...
  # example for usage with Devise
  authenticate :user, -> (user) { user.admin? } do
    mount RailsPerformance::Engine, at: 'rails/performance'
  end
end

Custom data

You need to configure config.custom_data_proc. And you can capture current_user, HTTP User Agent, etc. This proc is executed inside middleware, and you have access to Rack "env".

Custom Data

Custom events

RailsPerformance.measure("some label", "some namespace") do
   # your code
end

How it works

Schema

In addition it's wrapping gems internal methods and collecting performance information. See ./lib/rails_performance/gems/* for more information.

Limitations

  • it doesn't track params of POST/PUT requests
  • it doesn't track Redis/ElasticSearch or other apps
  • it can't compare historical data
  • depending on your load you may need to reduce time of for how long you store data, because all calculations are done in memory and it could take some time for high-load apps

Redis

Gem is using Redis. This is the only one dependency.

All information is stored into Redis. The default expiration time is set to config.duration from the configuration.

Development & Testing

Just clone the repo, setup dummy app (rails db:migrate).

After this:

  • rails s
  • rake test

Like a regular web development.

Please note that to simplify integration with other apps all CSS/JS are bundled inside, and delivered in body of the request. This is to avoid integration with assets pipeline or webpacker.

For UI changes you need to use Bulma CSS (https://bulma.io/documentation).

Why

The idea of this gem grew from curiosity how many RPM my app receiving per day. Later it evolved to something more powerful.

TODO

  • documentation in Readme?
  • capture stacktrace of 500 errors and show in side panel
  • time/zone config?
  • connected charts on dashboard, when zoom, when hover?
  • ability to zoom to see requests withing specific datetime range
  • better hints?
  • export to csv
  • better stats tooltip, do not show if nothing to show
  • dark mode toggle? save to the cookies?
  • integration with elastic search? or other?
  • monitor active job?
  • better logo?
  • number of requests last 24 hours, hour, etc.
  • collect deprecation.rails
  • fix misspellings?
  • show "loading banner" until jquery is loaded?
  • better UI on smaller screens? Recent requests when URL's are long? Truncate with CSS?
  • rules for highlighting durations? how many ms to show warning, alert
  • elastic search
  • searchkiq
  • sinatra?
  • tests to check what is actually stored in redis db after request

Contributing

You are welcome to contribute. I've a big list of TODO.

If "schema" how records are stored i Redis is changed, and this is a breaking change, update: RailsPerformance::SCHEMA to a newer value.

Big thanks to contributors

License

The gem is available as open source under the terms of the MIT License.

More Repositories

1

rails_db

Rails Database Viewer and SQL Query Runner
JavaScript
1,447
star
2

active_storage_validations

Do it like => validates :photos, attached: true, content_type: ['image/png', 'image/jpg', 'image/jpeg'], size: { less_than: 500.kilobytes }, limit: { min: 1, max: 3 }, aspect_ratio: :landscape, dimension: { width: { in: 800..1600 }
Ruby
959
star
3

any_login

Easy way to login as any user in system
Ruby
376
star
4

log_analyzer

Rails logs analyzer (see how fast your views are rendering)
Ruby
349
star
5

rails_pdf

A reliable way to generate PDF of any complexity in Ruby on Rails apps
HTML
175
star
6

fake_api

The fastest way to prototype API in your Rails application
Ruby
142
star
7

execution_time

How fast is your code? See it directly in Rails console.
Ruby
111
star
8

benchmark_methods

Benchmark and measure execution time your Ruby methods without an additional code changes
Ruby
89
star
9

new_google_recaptcha

reCAPTCHA v3 Ruby on Rails gem
Ruby
82
star
10

transactify

Wrap your methods in DB Transactions
Ruby
55
star
11

sql_view

Rails SQL Views made easy ;)
Ruby
49
star
12

sweet_staging

Access your Rails console, see logs, execute rake commands directly from the browser. Great addition to your Staging ENV.
JavaScript
46
star
13

execute_sql

Execute SQL inside Rails console, or app itself
Ruby
41
star
14

cache_with_locale

Easy wait to do view caching with automatically added "locale" value to the cached key.
Ruby
37
star
15

avatarro

Generate google-style avatars in your application
Ruby
37
star
16

awesome_back_url

Redirect the user to the proper "back" page
Ruby
33
star
17

records_count

See in development logs how many records your queries returns. It can help with solving performance issues.
Ruby
31
star
18

new_ckeditor

Ruby on Rails + CKEditor 5
Ruby
31
star
19

amazon_static_site

Static website using https with your own domain name using Amazon S3 and Cloudflare for FREE
Ruby
29
star
20

omg_image

Generate PNG previews for HTML snippets (html/css/js). Any complexity.
Ruby
28
star
21

wrapped_print

Easy print debug information to your console in Ruby/Rails app.
Ruby
23
star
22

calculate_in_group

Group Active Record by ranges or set of values with a single SQL query.
Ruby
22
star
23

embed_view

Embed ERB files inside another ERB files for faster performance (5-20% BOOST!!!)
HTML
21
star
24

rails_time_travel

HTML
19
star
25

sabotage

Coding & debugging must be fun. Make life a bit harder for your colleagues :)
Ruby
18
star
26

mechanical

All models in a single table, new attributes without migrations. Works like regular AR model
Ruby
17
star
27

secrett11tto

Simple way to protect your content from copy-pasting
Ruby
15
star
28

rails_live

Ruby
15
star
29

mini-guard

Ruby
14
star
30

railsjazz.com

Rails Jazz (personal web site)
JavaScript
14
star
31

sidekiq_log_analyzer

SidekiqLogAnalyser gem allows to see summary of your sidekiq workers (based on log file).
Ruby
13
star
32

hasharay_ext

Painless work with complex Ruby hashes/arrays.
Ruby
13
star
33

active_storage_silent_logs

The idea of this gem is to hide as much as possible Active Storage logs from console so you can see only important information and requests
Ruby
13
star
34

rails_cached_method

Simple way to cache results of methods.
Ruby
11
star
35

with_record

Returns relations/association for soft deleted records in DB
Ruby
10
star
36

rrr

Run recent rspec files only (the only recently modified).
Ruby
9
star
37

font_awesome_file_icons

Ruby
4
star
38

unwhere

Ruby
4
star
39

travel_and_talk

JavaScript
3
star
40

lazy_mobile_tester

Rails Lazy Mobile Tester
Ruby
3
star
41

serpjazz

SERP keywords tracking
JavaScript
3
star
42

jeanappv2

JavaScript
2
star
43

slim_erb_backport

Slim 4+ and ERB friends again :)
Ruby
2
star
44

mega-simple-authorization

mega simple authorization plugin for RoR
Ruby
2
star
45

tv

eb5 tv
JavaScript
2
star
46

spring_rspec_commands_addon

rails+spring+rspec = friends :)
Ruby
2
star
47

layouts_from_db_sample

Allow store layouts to DB (Sample)
2
star
48

CheaperDrinker

CheaperDrinker web site
JavaScript
2
star
49

tell_my_env

Ruby
2
star
50

any_login_test

AnyLogin gem test application
Ruby
2
star
51

VerySimple

1
star
52

ShareT

online translations
JavaScript
1
star
53

test-ec2

test-ec2
1
star
54

sa1

1
star
55

better_tempfile

Ruby
1
star
56

ar_enumerations_test_application

ActiveRecord enumeration field type - test application
Ruby
1
star
57

tophouse.com.ua

JavaScript
1
star
58

capistranotest

1
star
59

zip_and_phone

Zips & Phones
Ruby
1
star
60

portfolio

1
star
61

tdemo

tdemo
Ruby
1
star
62

cisarska_and_frankivska

Cisarska & Frankivska
JavaScript
1
star
63

seminars

JavaScript
1
star
64

deprecations_collector

Save all Rails deprecation in log file for future investigation
Ruby
1
star
65

just_for_fun

Do you want to call 42.to_user, [42, 43, 44].to_users? Try this gem :)
Ruby
1
star
66

rails_logs

Ruby
1
star