Using oink gem with heroku

后端 未结 7 2130
猫巷女王i
猫巷女王i 2020-12-28 18:01

I\'ve installed oink gem for monitoring the memory usage of my rails application. In order to see oink report I need to run this command in the terminal:

oin         


        
相关标签:
7条回答
  • 2020-12-28 18:20

    Got it working with hiattp's answer, but needed to add --text to the grep.

    cat log/production.log | cut -c 46- | grep 'rails\[' > log/production-oink.log
    
    0 讨论(0)
  • 2020-12-28 18:21

    If you are using a log archive downloaded from Papertrail, you can use this one-liner to format your output:

    cat log/production.log | cut -f 10- | grep 'rails\[' > log/production-oink.log
    
    0 讨论(0)
  • 2020-12-28 18:24

    You need to set up a drain for your heroku logs in order to run the oink command. For example, I have my heroku logs draining onto a local linux rsyslog server.

    0 讨论(0)
  • 2020-12-28 18:33

    Instead of switching the logger to Hodel3000Compliant you could also modify slightly your heroku logs with vim, for example, by using the following commands:

    :%s/2013-01-25T/Jan 25 /
    :%s/+00:00//
    :%s/app\[web.1\]/rails\[1\]/
    :%s/app\[web.2\]/rails\[2\]/
    

    your original heroku logs like those:

    2013-01-25T15:05:58+00:00 app[web.1]: Oink Action: tools#some_tool
    2013-01-25T15:05:58+00:00 app[web.1]: Memory usage: 303444 | PID: 2
    2013-01-25T15:05:58+00:00 app[web.1]: Oink Log Entry Complete
    

    become:

    Jan 25 15:05:58 rails[1]: Oink Action: tools#some_tool
    Jan 25 15:05:58 rails[1]: Memory usage: 303444 | PID: 2
    Jan 25 15:05:58 rails[1]: Oink Log Entry Complete
    

    and Oink likes them ;) Of course, first narrow the time where possible problem occured in the log by using NewRelic.

    UPDATE:

    Another set of vim commands to fix Papertrail logs for oink:

    :%s/\v^\d+\t//
    :%s/2013-01-27T/Jan 27 /
    

    And go to the first line, use CTRL-V to mark few other columns that are left, then type G to select those columns to the end of file. Make adjustments in your selection with 'left'/'right' arrows and then press 'c' to remove them.

    0 讨论(0)
  • 2020-12-28 18:37

    I got oink working on heroku doing this:

    You have to change your log_level to info for the oink logs to show up:

    heroku config:add LOG_LEVEL=info
    

    Add oink middleware to production.rb with a custom stdout logger

    config.middleware.use( Oink::Middleware, :logger => Hodel3000CompliantLogger.new(STDOUT))
    

    When you want to parse your logs, tail them to a local file, then remove heroku's prefix and filter to only the oink lines.

    heroku logs --tail > log/production.log
    cat log/production.log | cut -c 46- | grep 'Oink\|Memory\|Instantiation' > log/production-oink.log
    

    Then run oink on your new local log

    oink --threshold=0 log/production-oink.log
    

    You could also download logs from logentries or paperclip

    0 讨论(0)
  • 2020-12-28 18:39

    Unfortunately I can't comment yet but in case someone else has this issue a few things seem to have changed since Gabe Coyne's (super helpful) answer above. I didn't need to change my heroku log_level, so to start generating the logs you can just use an initializer config/initializers/oink.rb like so:

    YourApp::Application.middleware.use( Oink::Middleware, :logger => Hodel3000CompliantLogger.new(STDOUT))
    

    Or put that line in production.rb if you only want the oink logs in production. Then you need to get the logs into a local log file, also mentioned in the previous answer:

    heroku logs n500 --app app_name > log/production.log
    

    Or you can grab them from Papertrail or your favorite log archiver. The local logs need to be updated to the format that oink expects, but I found that grep 'Oink|Memory|Instantiation' didn't work as that string seems to have been removed from the logs, so I used this instead:

    cat log/production.log | cut -c 46- | grep 'rails\[' > log/production-oink.log
    

    Then you can use oink --threshold=0 log/production-oink.log and it will work.

    The only other thing that caught me up was the number of preceding characters to cut. Whereas cut -c 39- seems to have worked before, I had to use cut -c 46-. Obviously this varies, so in case its not obvious, you are just trying to get the lines in the raw logs that look like this:

    2013-07-19T18:47:09.494475+00:00 app[web.1]: Jul 19 18:47:09 24ab5d5s-g46c-2d44-dss2-233sdfa99852wd rails[5]: Oink Action: welcome#about
    

    To look like this:

    Jul 19 18:47:09 24ab5d5s-g46c-2d44-dss2-233sdfa99852wd rails[5]: Oink Action: welcome#about
    

    With the front part removed. Hope this helps!

    0 讨论(0)
提交回复
热议问题