How to detect how many active Unicorn workers are busy?

3.6k views Asked by At

I am using Ruby unicorn, and have configured it to have 15 worker processes.

How do I tell how many workers are actually processing work (are not idle, waiting for work) at any current time?

2

There are 2 answers

2
OddEssay On

If you just need the infomation on the command line, you could check how much CPU each is using:

ps aux --sort=-pcpu | grep '%CPU\|unicorn'

ps aux --sort=-pcpu - Gets a list of all the processes running, sorted in CPU usage order reversed (Highest CPU first)

| - Pipes output of previous command to the next

grep '%CPU\|unicorn' - Returns only lines the contain %CPU (The first line) OR unicorn. \| is the OR symbol in the grep pattern.

You should get output like this, with CPU usage in the 3rd column, memory usage in the 4th:

USER       PID %CPU %MEM    VSZ   RSS TTY   STAT START   TIME  COMMAND 

vagrant   4444  33.2 45.0 349988 152892 ?   Sl   13:43   0:03 unicorn master -c /vagrant/config/unicorn.rb -E development -D   

vagrant   4449  0.0 15.9 362204 162716 ?    Sl   13:44   0:01 unicorn worker[0] -c /vagrant/config/unicorn.rb -E development -D

High CPU usage means in use, tiny or no CPU means the worker is idle and not doing any work.

0
Diego Carrion On

You can use Raindrops or New Relic' RPM.