railsでnewrelicを動かすためには
Herokuを使っているパフォーマンス測定ツールとしてよく使うのは、newrelicというサービスです。
これを使うと核処理にかかる時間やエラー発生率、SQLの処理時間、そしてブラウザの使用状況など様々な情報を見る事ができます。
今回はこれを使うための設定を書きます。
1.Gemfileに追加
gem 'newrelic_rpm'
2.bundle installを実行
$bundle install --path vendor/bundle
3.config/newrelic.ymlを作成
どのような設定でnewrelicを使うかを定義します。
Using versioncake (2.3.1) 1 2 mmon: &default_settings 3 # ============================== LICENSE KEY =============================== 4 5 # You must specify the license key associated with your New Relic 6 # account. This key binds your Agent's data to your account in the 7 # New Relic service. 8 license_key: '<%= license_key %>' 9 10 # Agent Enabled (Ruby/Rails Only) 11 # Use this setting to force the agent to run or not run. 12 # Default is 'auto' which means the agent will install and run only 13 # if a valid dispatcher such as Mongrel is running. This prevents 14 # it from running with Rake or the console. Set to false to 15 # completely turn the agent off regardless of the other settings. 16 # Valid values are true, false and auto. 17 # 18 # agent_enabled: auto 19 20 # Application Name Set this to be the name of your application as 21 # you'd like it show up in New Relic. The service will then auto-map 22 # instances of your application into an "application" on your 23 # dashboard page. If you want to map this instance into multiple 24 # apps, like "AJAX Requests" and "All UI" then specify a semicolon 25 # separated list of up to three distinct names, or a yaml list. 26 # Defaults to the capitalized RAILS_ENV or RACK_ENV (i.e., 27 # Production, Staging, etc) 28 # 29 # Example: 30 # 31 # app_name: 32 # - Ajax Service 33 # - All Services 34 # 35 app_name: <%= @app_name %> 36 37 # When "true", the agent collects performance data about your 38 # application and reports this data to the New Relic service at 39 # newrelic.com. This global switch is normally overridden for each 40 # environment below. (formerly called 'enabled') 41 monitor_mode: true 42 43 # Developer mode should be off in every environment but 44 # development as it has very high overhead in memory. 45 developer_mode: false 46 47 # The newrelic agent generates its own log file to keep its logging 48 # information separate from that of your application. Specify its 49 # log level here. 50 log_level: info 51 52 # Optionally set the path to the log file This is expanded from the 53 # root directory (may be relative or absolute, e.g. 'log/' or 54 # '/var/log/') The agent will attempt to create this directory if it 55 # does not exist. 56 # log_file_path: 'log' 57 58 # Optionally set the name of the log file, defaults to 'newrelic_agent.log' 59 # log_file_name: 'newrelic_agent.log' 60 61 # The newrelic agent communicates with the service via https by default. This 62 # prevents eavesdropping on the performance metrics transmitted by the agent. 63 # The encryption required by SSL introduces a nominal amount of CPU overhead, 64 # which is performed asynchronously in a background thread. If you'd prefer 65 # to send your metrics over http uncomment the following line. 66 # ssl: false 67 68 #============================== Browser Monitoring =============================== 69 # New Relic Real User Monitoring gives you insight into the performance real users are 70 # experiencing with your website. This is accomplished by measuring the time it takes for 71 # your users' browsers to download and render your web pages by injecting a small amount 72 # of JavaScript code into the header and footer of each page. 73 browser_monitoring: 74 # By default the agent automatically injects the monitoring JavaScript 75 # into web pages. Set this attribute to false to turn off this behavior. 76 auto_instrument: true 77 78 # Proxy settings for connecting to the New Relic server. 79 # 80 # If a proxy is used, the host setting is required. Other settings 81 # are optional. Default port is 8080. 82 # 83 # proxy_host: hostname 84 # proxy_port: 8080 85 # proxy_user: 86 # proxy_pass: 87 88 # The agent can optionally log all data it sends to New Relic servers to a 89 # separate log file for human inspection and auditing purposes. To enable this 90 # feature, change 'enabled' below to true. 91 # See: https://newrelic.com/docs/ruby/audit-log 92 audit_log: 93 enabled: false 94 95 # Tells transaction tracer and error collector (when enabled) 96 # whether or not to capture HTTP params. When true, frameworks can 97 # exclude HTTP parameters from being captured. 98 # Rails: the RoR filter_parameter_logging excludes parameters 99 # Java: create a config setting called "ignored_params" and set it to 100 # a comma separated list of HTTP parameter names. 101 # ex: ignored_params: credit_card, ssn, password 102 capture_params: false 103 104 # Transaction tracer captures deep information about slow 105 # transactions and sends this to the New Relic service once a 106 # minute. Included in the transaction is the exact call sequence of 107 # the transactions including any SQL statements issued. 108 transaction_tracer: 109 110 # Transaction tracer is enabled by default. Set this to false to 111 # turn it off. This feature is only available at the Professional 112 # and above product levels. 113 enabled: true 114 115 # Threshold in seconds for when to collect a transaction 116 # trace. When the response time of a controller action exceeds 117 # this threshold, a transaction trace will be recorded and sent to 118 # New Relic. Valid values are any float value, or (default) "apdex_f", 119 # which will use the threshold for an dissatisfying Apdex 120 # controller action - four times the Apdex T value. 121 transaction_threshold: apdex_f 122 123 # When transaction tracer is on, SQL statements can optionally be 124 # recorded. The recorder has three modes, "off" which sends no 125 # SQL, "raw" which sends the SQL statement in its original form, 126 # and "obfuscated", which strips out numeric and string literals. 127 record_sql: obfuscated 128 129 # Threshold in seconds for when to collect stack trace for a SQL 130 # call. In other words, when SQL statements exceed this threshold, 131 # then capture and send to New Relic the current stack trace. This is 132 # helpful for pinpointing where long SQL calls originate from. 133 stack_trace_threshold: 0.500 134 135 # Determines whether the agent will capture query plans for slow 136 # SQL queries. Only supported in mysql and postgres. Should be 137 # set to false when using other adapters. 138 explain_enabled: true 139 140 # Threshold for query execution time below which query plans will 141 # not be captured. Relevant only when `explain_enabled` is true. 142 explain_threshold: 0.5 143 144 # Error collector captures information about uncaught exceptions and 145 # sends them to New Relic for viewing 146 error_collector: 147 148 # Error collector is enabled by default. Set this to false to turn 149 # it off. This feature is only available at the Professional and above 150 # product levels. 151 enabled: true 152 153 # Rails Only - tells error collector whether or not to capture a 154 # source snippet around the place of the error when errors are View 155 # related. 156 capture_source: true 157 158 # To stop specific errors from reporting to New Relic, set this property 159 # to comma-separated values. Default is to ignore routing errors, 160 # which are how 404's get triggered. 161 ignore_errors: "ActionController::RoutingError,Sinatra::NotFound" 162 163 # If you're interested in capturing memcache keys as though they 164 # were SQL uncomment this flag. Note that this does increase 165 # overhead slightly on every memcached call, and can have security 166 # implications if your memcached keys are sensitive 167 # capture_memcache_keys: true 168 169 # Application Environments 170 # ------------------------------------------ 171 # Environment-specific settings are in this section. 172 # For Rails applications, RAILS_ENV is used to determine the environment. 173 # For Java applications, pass -Dnewrelic.environment <environment> to set 174 # the environment. 175 176 # NOTE if your application has other named environments, you should 177 # provide newrelic configuration settings for these environments here. 178 179 development: 180 <<: *default_settings 181 # Turn on communication to New Relic service in development mode 182 monitor_mode: true 183 app_name: <%= @app_name %> (Development) 184 185 # Rails Only - when running in Developer Mode, the New Relic Agent will 186 # present performance information on the last 100 transactions you have 187 # executed since starting the mongrel. 188 # NOTE: There is substantial overhead when running in developer mode. 189 # Do not use for production or load testing. 190 developer_mode: false 191 192 # Enable textmate links 193 # textmate: true 194 195 test: 196 <<: *default_settings 197 # It almost never makes sense to turn on the agent when running 198 # unit, functional or integration tests or the like. 199 monitor_mode: false 200 201 # Turn on the agent in production for 24x7 monitoring. NewRelic 202 # testing shows an average performance impact of < 5 ms per 203 # transaction, you can leave this on all the time without 204 # incurring any user-visible performance degradation. 205 production: 206 <<: *default_settings 207 monitor_mode: true 208 209 # Many applications have a staging environment which behaves 210 # identically to production. Support for that environment is provided 211 # here. By default, the staging environment has the agent turned on. 212 staging: 213 <<: *default_settings 214 monitor_mode: true 215 app_name: <%= @app_name %> (Staging)
以上