Skip to content
This repository has been archived by the owner on Jan 7, 2019. It is now read-only.

Commit

Permalink
Make log directory and thresholds configurable.
Browse files Browse the repository at this point in the history
  • Loading branch information
watsonian committed Sep 4, 2012
1 parent 20ac0cb commit c2bdb3e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/mem_watcher.rb
Expand Up @@ -8,12 +8,13 @@
class MemWatcher < Sinatra::Base class MemWatcher < Sinatra::Base
set :views, File.join(File.dirname(settings.root), "/views") set :views, File.join(File.dirname(settings.root), "/views")
set :public_folder, File.join(File.dirname(settings.root), "/public") set :public_folder, File.join(File.dirname(settings.root), "/public")
set :log_dir, ENV['MEMWATCHER_LOG_DIR'] || File.join(File.dirname(settings.root), "/log/procs")


@@memory_threshold = 50000 @@memory_threshold = (ENV['MEMWATCHER_MEMORY_THRESHOLD'] || 50000).to_i
@@max_memused = @@memory_threshold @@max_memused = @@memory_threshold
@@num_checks = 0 @@num_checks = 0
@@max_checks = 6 @@max_checks = (ENV['MEMWATCHER_MAX_CHECKS'] || 6).to_i
@@logs_to_keep = 25 @@logs_to_keep = (ENV['MEMWATCHER_LOGS_TO_KEEP'] || 25).to_i


##### #####
# Actions # Actions
Expand Down Expand Up @@ -72,7 +73,7 @@ def update_max_memused!(cur_meminfo)
end end


def save_process_list!(cur_meminfo) def save_process_list!(cur_meminfo)
FileUtils.mkdir_p("./log/procs") FileUtils.mkdir_p(settings.log_dir)
system("ps auxf > log/procs/`date \"+%Y%m%d_%H%M%S-#{@@max_memused}-#{cur_meminfo.memused}\"`.snapshot.out") system("ps auxf > log/procs/`date \"+%Y%m%d_%H%M%S-#{@@max_memused}-#{cur_meminfo.memused}\"`.snapshot.out")
end end


Expand Down

0 comments on commit c2bdb3e

Please sign in to comment.