What's the best way to monitor the boot time for a rails app

I want to monitor the boot time for various rails apps so I can tweak load-balancer health-checks and Kubernetes readiness probes, and know when a change created a large increase in boot time.

What’s the best way to achieve this?

Currently I made a change to bin/rails to create a global variable at the beginning of that script.

#!/usr/bin/env ruby
RAIL_START_TIME = (Time.now.to_f * 1000).to_i

I also made some changes to the end of config/puma.rb to calculate the boot time.

puma_ready_at = (Time.now.to_f * 1000).to_i
app_boot_time = puma_ready_at - RAIL_START_TIME
Rails.logger.info "Puma booted in #{app_boot_time} ms"

Those changes result in the following output in my log, which I think is close enough, and I can later extract and monitor over time but is there a better way to achieve this?

bundle exec rails server -p 3000

=> Booting Puma
=> Rails 7.1.2 application starting in development 
=> Run `bin/rails server --help` for more startup options
Puma booted in 12697 ms
Puma starting in single mode...
* Puma version: 6.4.0 (ruby 3.2.2-p53) ("The Eagle of Durango")
*  Min threads: 5
*  Max threads: 5
*  Environment: development
*          PID: 99906
* Listening on http://127.0.0.1:3000
* Listening on http://[::1]:3000
Use Ctrl-C to stop

Currently looking for the best approach, but I’m thinking about setting the readiness probe rate very high. Log very early in the starting of the container and log on healthcheck. Then you can compare the timestamps. Boot time depends pretty much on the environment. It will not be the same of development.

Hi. Did you get the way you want for monitoring the boot time of rails app? I am trying to run the rails app with puma. and I use kubernetes. the Problem is, I tried to run puma with preload option. So make the rails app start automatically after puma start. The problem is, after puma start, the rails app is not starting. only when get the first request, it starts the rails app. Therefore, I have a problem with readinessProbe check in kubernetes. The readinessProbe check always failed because the rails app is not automatically starting after puma start. Please let me know if you have any thoughts. Thanks