How to monitor passenger / mod_rails processes? - ruby-on-rails

I searched the site already but couldn't find any suitable information. As there is always some expert around I'm sure one of guys knows exactly what I'm searching for :-)
We're on a balanced system:
Machine 1: HAProxy load balancer
Machine 2 & 3: Apache mod_rails and (of course) our Rails applications
Those were the days when we were able to monitor all Mongrel processes using monit (or other monitoring tools).
Is there any way to do an easy and clever monitoring of passenger processes with monit (or other tools), too? How can I dynamically get all pids of the running processes and pass them to monitoring?
Matt

There are various options available. Here are some of them:
The passenger-status tool lets you inspect its internal status
FiveRuns Manage can monitor a Passenger installation
Scout can also monitor Passenger

I made a plugin which make Passenger processes monitorable by Monit:
https://github.com/romanbsd/passenger_monit

Its a little ghetto but run these commands
watch passenger-status
watch passenger-memory-stats
then install and run htop

I did a quick search and I think I found the thing your looking for. He uses a script which runs off "passenger-status" as John Topley said.
http://blog.slowb.ro/2013/06/18/add-passenger-status-to-monitoring-on-zenoss/

Related

Ruby on rails with unicorn

What is the best deployment environment for a RoR app? Someone has suggested Unicorn but am not sure. Any suggestions?
Update:
well, i have a small app with just 3-4 pages and will be accessed by not more than 25-50 concurrent users. "best" here means, ease of deployment of the app and ease of maintenance of the environment itself. Obviously stability of the solution matters as well
You should try passenger standalone, it uses nginx under the hoods and is lightning fast with little configuration. Especially when you use many apps on one server, with different gemsets and ruby versions.
Even using nginx under the hoods, you can still choose apache or nginx to maintain your webservers domains using sockets.
read this article:
http://blog.phusion.nl/2010/09/21/phusion-passenger-running-multiple-ruby-versions/
In terms of ease of deployment and maintenance.
Then its hard to beat Phusion Passenger.
It appears as an apache or nginx mod.
I always go for the apache mod
as I prefer to have apache installed from apt,
and I find it easier to do version upgrade.
It can be installed as simply as;
gem install passenger
passenger-install-apache2-module
And from then on the install process will tell you exactly what to do.

Foreman auto restart

In my production server, I'm using ruby foreman to run multiple processes, I just want my application to keep working, even if one of the processes down, I want my processes to keep working even if one down , is there any tricky way to restart the process or even not to stop all the processes in case one went down ? I mean in production level I want the solution to be stable enough, is that possible without Upstart ? thanks in advance
You should not be using foreman itself for production - it is only intended as a development tool. Instead, you can use something like god with my foreman_god gem in production.
Alternatively, you can use foreman to export config files for other process monitoring systems, for example upstart.
You can monitor your foreman process with another program like http://mmonit.com/monit/. But somehow you'll find that monitoring a process which monitor other processes is kinda strange.

Monitoring ROR server (thin or mongrel) for resources and availability in WINDOWS and re-spawn

First thing I would like to say is, i know deploying ror applications in windows is not recommended, but in this case i have no choice due to some client restrictions.
I am looking for a tool like Upstart for windows which will moniter my instance of Thin or Mongrel and will 're-spawn' in case of crashes or availability.
Now I looked around quite a bit and most solutions like UpStart, or Passenger server are only available for Unix environments.
Any known tools for windows? and how to use them?
I am also open to any alternative ror servers for windows that can do this automatically like passenger does.
Thanks
Shaunak
Maybe a bat script as a scheduled task to run wmic process, scan to find Mongrel, and if it's not found to run it?
Sorry, I'd do it in bash, or I'd have a code example for you.
This would also make a good python script, in my opinion.

many instances of apache get spawned with Passenger/Rails

I have a Debian Linux VPS server for my production website (512MB).
I'm using Phusion Passenger with Apache to service my Rails 2.3.4 application with Ruby 1.9. I'm limiting the pool of Phusion passenger instances to 3
Although the traffic is relatively low, the server crashes at times and I notice (when using 'top' command) that there are many instances of apache (/usr/sbin/apache2 -k start) maybe like 20 of them taking up all the memory I have and the website become un-responsive.
I'm not sure what to do about this, where to start digging for potential issues or how to spot or limit the number of apache instances.
Thanks,
Tam
If you want to limit the number of Apache processes, look at the documentation for the Multi-Processing Modules. But if you don't have that much traffic (it depends on what you call "relatively low"), it should work out of the box.
Have you tried asking your question over at Server Fault ? You might get better answers there.

modrails - rogue ruby processes consuming 100% cpu

I'm having ruby instances from mod_rails go "rogue" -- these processes are no longer listed in passenger-status and utilize 100% cpu.
Other than installing god/monit to kill the instance, can anyone give me some advice on how to prevent this? I haven't been able to find anything in the logs that helps.
If you're using Linux, you can install the "strace" utility to see what the Ruby process is doing that's consuming all the CPU. That will give you a good low-level view. It should be available in your package manager. Then you can:
$ sudo strace -p 22710
Process 22710 attached - interrupt to quit
...lots of stuff...
(press Ctrl+C)
Then, if you want to stop the process in the middle and dump a stack trace, you can follow the guide on using GDB in Ruby at http://eigenclass.org/hiki.rb?ruby+live+process+introspection, specifically doing:
gdb --pid=(ruby process)
session-ruby
stdout_redirect
(in other terminal) tail -f /tmp/ruby_debug.(pid)
eval "caller"
You can also use the ruby-debug Gem to remotely connect to debug sockets you open up, described in http://duckpunching.com/passenger-mod_rails-for-development-now-with-debugger
There also seems to be a project on Github concerned with debugging Passenger instances that looks interesting, but the documentation is lacking:
http://github.com/ddollar/socket-debugger/tree/master
I had a ruby process related to Phusion Passenger, which consumed lots of CPU, even though it should have been idle.
The problem went away after I ran
date -s "`date`"
as suggested in this thread. (That was on Debian Squeeze)
Apparently, the problem was related to a leap second, and could affect many other applications like MySQL, Java, etc. More info in this thread on lklm.
We saw something similar to this with very long running SQL queries.
MySQL would kill the queries because they exceeded the long running limit and the thread never realized that the query was dead.
You may want to check the database logs.
This is a recurring issue with passenger. I've seen this problem many times helping people that ran ruby on rails with passenger. I don't have a fix but you might want to try this http://www.modrails.com/documentation/Users%20guide%20Apache.html#debugging_frozen

Resources