简体   繁体   中英

Creating a separate log for each Passenger process in a Rails app

I'm trying to determine the cause of high app server instance memory usage and to do so I need a separate log for each running Passenger process (eg, production_18204.log). Is there a simple way to configure this in a Rails app? Thanks.

To log memory used by process in each request use the following code.

def log_memory_usage
  mem_usage = `ps -o rss= -p #{ Process.pid }`.to_i
  if logger
    logger.info("[MEMORY USAGE]: #{ number_to_human_size(mem_usage) } | PID: #{ Process.pid } | CONTROLLER: #{ controller_name } | ACTION: #{ action_name }")
  end
end

Use this as before action in your base or application controller. Do include ActionView::Helpers::NumberHelper to make number_to_human_size work.

Courtesy: https://github.com/binarylogic/memorylogic

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM