Skip to content

Including child processes in CPU/memory usage #30

Closed
wants to merge 2 commits into from

3 participants

@jstepien

This changeset allows God to watch total CPU/memory usage of a process family. I use God to monitor a deamon which forks a lot and monitoring a single PID isn't sufficient. Now I can simply add a following restart rule in order to keep the whole family under control.

w.restart_if do |restart|
  restart.condition(:memory_usage) do |c| 
    c.above = 210.megabytes
    c.times = 5 
    c.family = true
  end 

  restart.condition(:cpu_usage) do |c| 
    c.above = 80.percent
    c.times = 5 
    c.family = true
  end 
end 

rake test doesn't report any regressions.

@mojombo
Owner
mojombo commented May 25, 2011

This looks really useful. Any chance you could work up a test for this, to make sure it's working properly?

@jstepien

Sure. Here's a memory usage test. I guess something similar can be written to test CPU usage. Looking forward for your opinion.

@mojombo
Owner
mojombo commented May 25, 2011

I'm getting the following error on my system (OSX):

  1) Error:
test_family_memory_usage(TestSystemProcessFamily):
TypeError: #<Mocha::Mock:0x1033f6bd8> is not a class/module
    ./test/test_system_process_family.rb:36:in `test_family_memory_usage'
    /Users/tom/.rvm/gems/ruby-1.8.7-p248/gems/mocha-0.9.12/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb:22:in `__send__'
    /Users/tom/.rvm/gems/ruby-1.8.7-p248/gems/mocha-0.9.12/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb:22:in `run'

Are you seeing this at all?

@jstepien

No, I'm not, but I also had some problems. I'm on Linux and Ruby 1.9.2. I copied the test file structure from test/test_system_process.rb. I wasn't able to run test/test_system_process.rb and the test I've added using Rake. I've managed to run them using

$ ruby -I path/to/mocha-0.9.12/lib/ -I. test/test_system_process.rb
$ ruby -I path/to/mocha-0.9.12/lib/ -I. test/test_system_process_family.rb

Without adding mocha to the load path I get a following error.

$ ruby -I. test/test_system_process.rb 
E [2011-05-26 16:44:09] ERROR: => You need the Mocha gem to run these tests.
@eric eric commented on the diff Dec 17, 2011
lib/god/system/process.rb
+ # Returns an array of PIDs of the polled process and all its children.
+ def family
@eric
Collaborator
eric added a note Dec 17, 2011

This method should be moved into the PortablePoller and an implementation should be written for the SlashProcPoller.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@jstepien jstepien closed this Nov 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.