honkster-newrelic_rpm 2.13.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. data/CHANGELOG +462 -0
  2. data/LICENSE +37 -0
  3. data/README.rdoc +172 -0
  4. data/bin/mongrel_rpm +33 -0
  5. data/bin/newrelic +13 -0
  6. data/bin/newrelic_cmd +5 -0
  7. data/cert/cacert.pem +34 -0
  8. data/install.rb +9 -0
  9. data/lib/new_relic/agent.rb +382 -0
  10. data/lib/new_relic/agent/agent.rb +741 -0
  11. data/lib/new_relic/agent/busy_calculator.rb +91 -0
  12. data/lib/new_relic/agent/chained_call.rb +13 -0
  13. data/lib/new_relic/agent/error_collector.rb +131 -0
  14. data/lib/new_relic/agent/instrumentation/active_merchant.rb +18 -0
  15. data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +92 -0
  16. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +45 -0
  17. data/lib/new_relic/agent/instrumentation/authlogic.rb +8 -0
  18. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +409 -0
  19. data/lib/new_relic/agent/instrumentation/data_mapper.rb +58 -0
  20. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +22 -0
  21. data/lib/new_relic/agent/instrumentation/memcache.rb +40 -0
  22. data/lib/new_relic/agent/instrumentation/merb/controller.rb +26 -0
  23. data/lib/new_relic/agent/instrumentation/merb/errors.rb +9 -0
  24. data/lib/new_relic/agent/instrumentation/metric_frame.rb +319 -0
  25. data/lib/new_relic/agent/instrumentation/net.rb +17 -0
  26. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +22 -0
  27. data/lib/new_relic/agent/instrumentation/rack.rb +98 -0
  28. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +59 -0
  29. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +27 -0
  30. data/lib/new_relic/agent/instrumentation/rails/errors.rb +24 -0
  31. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +45 -0
  32. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +21 -0
  33. data/lib/new_relic/agent/instrumentation/sinatra.rb +46 -0
  34. data/lib/new_relic/agent/instrumentation/sunspot.rb +17 -0
  35. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +10 -0
  36. data/lib/new_relic/agent/method_tracer.rb +350 -0
  37. data/lib/new_relic/agent/sampler.rb +50 -0
  38. data/lib/new_relic/agent/samplers/cpu_sampler.rb +54 -0
  39. data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +37 -0
  40. data/lib/new_relic/agent/samplers/memory_sampler.rb +142 -0
  41. data/lib/new_relic/agent/samplers/object_sampler.rb +24 -0
  42. data/lib/new_relic/agent/shim_agent.rb +25 -0
  43. data/lib/new_relic/agent/stats_engine.rb +24 -0
  44. data/lib/new_relic/agent/stats_engine/metric_stats.rb +118 -0
  45. data/lib/new_relic/agent/stats_engine/samplers.rb +83 -0
  46. data/lib/new_relic/agent/stats_engine/transactions.rb +149 -0
  47. data/lib/new_relic/agent/transaction_sampler.rb +330 -0
  48. data/lib/new_relic/agent/worker_loop.rb +81 -0
  49. data/lib/new_relic/collection_helper.rb +71 -0
  50. data/lib/new_relic/command.rb +85 -0
  51. data/lib/new_relic/commands/deployments.rb +105 -0
  52. data/lib/new_relic/commands/install.rb +81 -0
  53. data/lib/new_relic/control.rb +203 -0
  54. data/lib/new_relic/control/configuration.rb +149 -0
  55. data/lib/new_relic/control/frameworks/external.rb +13 -0
  56. data/lib/new_relic/control/frameworks/merb.rb +24 -0
  57. data/lib/new_relic/control/frameworks/rails.rb +126 -0
  58. data/lib/new_relic/control/frameworks/rails3.rb +60 -0
  59. data/lib/new_relic/control/frameworks/ruby.rb +36 -0
  60. data/lib/new_relic/control/frameworks/sinatra.rb +18 -0
  61. data/lib/new_relic/control/instrumentation.rb +95 -0
  62. data/lib/new_relic/control/logging_methods.rb +74 -0
  63. data/lib/new_relic/control/profiling.rb +24 -0
  64. data/lib/new_relic/control/server_methods.rb +88 -0
  65. data/lib/new_relic/delayed_job_injection.rb +27 -0
  66. data/lib/new_relic/histogram.rb +91 -0
  67. data/lib/new_relic/local_environment.rb +333 -0
  68. data/lib/new_relic/merbtasks.rb +6 -0
  69. data/lib/new_relic/metric_data.rb +42 -0
  70. data/lib/new_relic/metric_parser.rb +136 -0
  71. data/lib/new_relic/metric_parser/action_mailer.rb +9 -0
  72. data/lib/new_relic/metric_parser/active_merchant.rb +26 -0
  73. data/lib/new_relic/metric_parser/active_record.rb +28 -0
  74. data/lib/new_relic/metric_parser/apdex.rb +88 -0
  75. data/lib/new_relic/metric_parser/controller.rb +62 -0
  76. data/lib/new_relic/metric_parser/controller_cpu.rb +38 -0
  77. data/lib/new_relic/metric_parser/errors.rb +6 -0
  78. data/lib/new_relic/metric_parser/external.rb +50 -0
  79. data/lib/new_relic/metric_parser/mem_cache.rb +50 -0
  80. data/lib/new_relic/metric_parser/other_transaction.rb +36 -0
  81. data/lib/new_relic/metric_parser/view.rb +61 -0
  82. data/lib/new_relic/metric_parser/web_frontend.rb +14 -0
  83. data/lib/new_relic/metric_parser/web_service.rb +9 -0
  84. data/lib/new_relic/metric_spec.rb +67 -0
  85. data/lib/new_relic/metrics.rb +9 -0
  86. data/lib/new_relic/noticed_error.rb +24 -0
  87. data/lib/new_relic/rack/developer_mode.rb +257 -0
  88. data/lib/new_relic/rack/metric_app.rb +64 -0
  89. data/lib/new_relic/rack/mongrel_rpm.ru +26 -0
  90. data/lib/new_relic/rack/newrelic.yml +27 -0
  91. data/lib/new_relic/rack_app.rb +6 -0
  92. data/lib/new_relic/recipes.rb +82 -0
  93. data/lib/new_relic/stats.rb +368 -0
  94. data/lib/new_relic/timer_lib.rb +27 -0
  95. data/lib/new_relic/transaction_analysis.rb +119 -0
  96. data/lib/new_relic/transaction_sample.rb +586 -0
  97. data/lib/new_relic/url_rule.rb +14 -0
  98. data/lib/new_relic/version.rb +55 -0
  99. data/lib/new_relic_api.rb +276 -0
  100. data/lib/newrelic_rpm.rb +49 -0
  101. data/lib/tasks/all.rb +4 -0
  102. data/lib/tasks/install.rake +7 -0
  103. data/lib/tasks/tests.rake +15 -0
  104. data/newrelic.yml +246 -0
  105. data/newrelic_rpm.gemspec +254 -0
  106. data/recipes/newrelic.rb +6 -0
  107. data/test/active_record_fixtures.rb +55 -0
  108. data/test/config/newrelic.yml +48 -0
  109. data/test/config/test_control.rb +36 -0
  110. data/test/new_relic/agent/active_record_instrumentation_test.rb +286 -0
  111. data/test/new_relic/agent/agent_controller_test.rb +294 -0
  112. data/test/new_relic/agent/agent_test_controller.rb +77 -0
  113. data/test/new_relic/agent/busy_calculator_test.rb +81 -0
  114. data/test/new_relic/agent/collection_helper_test.rb +125 -0
  115. data/test/new_relic/agent/error_collector_test.rb +163 -0
  116. data/test/new_relic/agent/memcache_instrumentation_test.rb +103 -0
  117. data/test/new_relic/agent/method_tracer_test.rb +340 -0
  118. data/test/new_relic/agent/metric_data_test.rb +53 -0
  119. data/test/new_relic/agent/metric_frame_test.rb +51 -0
  120. data/test/new_relic/agent/mock_scope_listener.rb +23 -0
  121. data/test/new_relic/agent/net_instrumentation_test.rb +77 -0
  122. data/test/new_relic/agent/rpm_agent_test.rb +142 -0
  123. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +79 -0
  124. data/test/new_relic/agent/stats_engine/samplers_test.rb +72 -0
  125. data/test/new_relic/agent/stats_engine/stats_engine_test.rb +184 -0
  126. data/test/new_relic/agent/task_instrumentation_test.rb +188 -0
  127. data/test/new_relic/agent/testable_agent.rb +13 -0
  128. data/test/new_relic/agent/transaction_sample_builder_test.rb +195 -0
  129. data/test/new_relic/agent/transaction_sample_test.rb +192 -0
  130. data/test/new_relic/agent/transaction_sampler_test.rb +385 -0
  131. data/test/new_relic/agent/worker_loop_test.rb +66 -0
  132. data/test/new_relic/control_test.rb +127 -0
  133. data/test/new_relic/deployments_api_test.rb +69 -0
  134. data/test/new_relic/environment_test.rb +75 -0
  135. data/test/new_relic/metric_parser_test.rb +226 -0
  136. data/test/new_relic/metric_spec_test.rb +177 -0
  137. data/test/new_relic/rack/episodes_test.rb +318 -0
  138. data/test/new_relic/shim_agent_test.rb +9 -0
  139. data/test/new_relic/stats_test.rb +312 -0
  140. data/test/new_relic/version_number_test.rb +89 -0
  141. data/test/test_contexts.rb +28 -0
  142. data/test/test_helper.rb +72 -0
  143. data/ui/helpers/developer_mode_helper.rb +359 -0
  144. data/ui/helpers/google_pie_chart.rb +49 -0
  145. data/ui/views/layouts/newrelic_default.rhtml +47 -0
  146. data/ui/views/newrelic/_explain_plans.rhtml +27 -0
  147. data/ui/views/newrelic/_sample.rhtml +20 -0
  148. data/ui/views/newrelic/_segment.rhtml +29 -0
  149. data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
  150. data/ui/views/newrelic/_segment_row.rhtml +14 -0
  151. data/ui/views/newrelic/_show_sample_detail.rhtml +24 -0
  152. data/ui/views/newrelic/_show_sample_sql.rhtml +20 -0
  153. data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
  154. data/ui/views/newrelic/_sql_row.rhtml +16 -0
  155. data/ui/views/newrelic/_stack_trace.rhtml +15 -0
  156. data/ui/views/newrelic/_table.rhtml +12 -0
  157. data/ui/views/newrelic/explain_sql.rhtml +43 -0
  158. data/ui/views/newrelic/file/images/arrow-close.png +0 -0
  159. data/ui/views/newrelic/file/images/arrow-open.png +0 -0
  160. data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
  161. data/ui/views/newrelic/file/images/file_icon.png +0 -0
  162. data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
  163. data/ui/views/newrelic/file/images/new-relic-rpm-desktop.gif +0 -0
  164. data/ui/views/newrelic/file/images/new_relic_rpm_desktop.gif +0 -0
  165. data/ui/views/newrelic/file/images/textmate.png +0 -0
  166. data/ui/views/newrelic/file/javascript/jquery-1.4.2.js +6240 -0
  167. data/ui/views/newrelic/file/javascript/transaction_sample.js +120 -0
  168. data/ui/views/newrelic/file/stylesheets/style.css +484 -0
  169. data/ui/views/newrelic/index.rhtml +59 -0
  170. data/ui/views/newrelic/sample_not_found.rhtml +2 -0
  171. data/ui/views/newrelic/show_sample.rhtml +79 -0
  172. data/ui/views/newrelic/show_source.rhtml +3 -0
  173. data/ui/views/newrelic/threads.rhtml +52 -0
  174. metadata +307 -0
@@ -0,0 +1,359 @@
1
+ require 'pathname'
2
+ require File.expand_path('../google_pie_chart', __FILE__)
3
+ module NewRelic::DeveloperModeHelper
4
+ include NewRelic::CollectionHelper
5
+
6
+ private
7
+
8
+ # return the host that serves static content (css, metric documentation, images, etc)
9
+ # that supports the desktop edition.
10
+ def server
11
+ NewRelic::Control.instance['desktop_server'] || "http://rpm.newrelic.com"
12
+ end
13
+
14
+ # limit of how many detail/SQL rows we display - very large data sets (~10000+) crash browsers
15
+ def trace_row_display_limit
16
+ 2000
17
+ end
18
+
19
+ def trace_row_display_limit_reached
20
+ (!@detail_segment_count.nil? && @detail_segment_count > trace_row_display_limit) || @sample.sql_segments.length > trace_row_display_limit
21
+ end
22
+
23
+ # return the sample but post processed to strip out segments that normally don't show
24
+ # up in production (after the first execution, at least) such as application code loading
25
+ def stripped_sample(sample = @sample)
26
+ sample.omit_segments_with('(Rails/Application Code Loading)|(Database/.*/.+ Columns)')
27
+ end
28
+
29
+ # return the highest level in the call stack for the trace that is not rails or
30
+ # newrelic agent code
31
+ def application_caller(trace)
32
+ trace = strip_nr_from_backtrace(trace) unless params[:show_nr]
33
+ trace.each do |trace_line|
34
+ file = file_and_line(trace_line).first
35
+ unless exclude_file_from_stack_trace?(file, false)
36
+ return trace_line
37
+ end
38
+ end
39
+ trace.last
40
+ end
41
+
42
+ def application_stack_trace(trace, include_rails = false)
43
+ trace = strip_nr_from_backtrace(trace) unless params[:show_nr]
44
+ trace.reject do |trace_line|
45
+ file = file_and_line(trace_line).first
46
+ exclude_file_from_stack_trace?(file, include_rails)
47
+ end
48
+ end
49
+
50
+ def render_backtrace
51
+ if @segment[:backtrace]
52
+ content_tag('h3', 'Application Stack Trace') +
53
+ render(:partial => 'stack_trace')
54
+ end
55
+ end
56
+
57
+ def h(text)
58
+ text
59
+ end
60
+
61
+ def agent_views_path(path)
62
+ path
63
+ end
64
+
65
+ def url_for_metric_doc(metric_name)
66
+ "#{server}/metric_doc?metric=#{CGI::escape(metric_name)}"
67
+ end
68
+
69
+ def url_for_source(trace_line)
70
+ file, line = file_and_line(trace_line)
71
+
72
+ begin
73
+ file = Pathname.new(file).realpath
74
+ rescue Errno::ENOENT
75
+ # we hit this exception when Pathame.realpath fails for some reason; attempt a link to
76
+ # the file without a real path. It may also fail, only when the user clicks on this specific
77
+ # entry in the stack trace
78
+ rescue
79
+ # catch all other exceptions. We're going to create an invalid link below, but that's okay.
80
+ end
81
+
82
+ if using_textmate?
83
+ "txmt://open?url=file://#{file}&line=#{line}"
84
+ else
85
+ "show_source?file=#{file}&line=#{line}&anchor=selected_line"
86
+ end
87
+ end
88
+
89
+ def dev_name(metric_name)
90
+ NewRelic::MetricParser.parse(metric_name).developer_name
91
+ end
92
+
93
+ # write the metric label for a segment metric in the detail view
94
+ def write_segment_label(segment)
95
+ if source_available && segment[:backtrace] && (source_url = url_for_source(application_caller(segment[:backtrace])))
96
+ link_to dev_name(segment.metric_name), source_url
97
+ else
98
+ dev_name(segment.metric_name)
99
+ end
100
+ end
101
+
102
+ def source_available
103
+ true
104
+ end
105
+
106
+ # write the metric label for a segment metric in the summary table of metrics
107
+ def write_summary_segment_label(segment)
108
+ dev_name(segment.metric_name)
109
+ end
110
+
111
+ def write_stack_trace_line(trace_line)
112
+ link_to trace_line, url_for_source(trace_line)
113
+ end
114
+
115
+ # write a link to the source for a trace
116
+ def link_to_source(trace)
117
+ image_url = 'file/images/' + (using_textmate? ? "textmate.png" : "file_icon.png")
118
+
119
+ link_to "<img src=#{image_url} alt=\"View Source\" title=\"View Source\"/>", url_for_source(application_caller(trace))
120
+ end
121
+
122
+ # print the formatted timestamp for a segment
123
+ def timestamp(segment)
124
+ sprintf("%1.3f", segment.entry_timestamp)
125
+ end
126
+
127
+ def format_timestamp(time)
128
+ time.strftime("%H:%M:%S")
129
+ end
130
+
131
+ def colorize(value, yellow_threshold = 0.05, red_threshold = 0.15, s=to_ms(value))
132
+ if value > yellow_threshold
133
+ color = (value > red_threshold ? 'red' : 'orange')
134
+ "<font color=#{color}>#{s}</font>"
135
+ else
136
+ "#{s}"
137
+ end
138
+ end
139
+
140
+ def expanded_image_path()
141
+ '/newrelic/file/images/arrow-open.png'
142
+ end
143
+
144
+ def collapsed_image_path()
145
+ '/newrelic/file/images/arrow-close.png'
146
+ end
147
+
148
+ def explain_sql_url(segment)
149
+ "explain_sql?id=#{@sample.sample_id}&amp;segment=#{segment.segment_id}"
150
+ end
151
+
152
+ def segment_duration_value(segment)
153
+ link_to colorize(segment.duration, 0.05, 0.15, "#{with_delimiter(to_ms(segment.duration))} ms"), explain_sql_url(segment)
154
+ end
155
+
156
+ def line_wrap_sql(sql)
157
+ sql.gsub(/\,/,', ').squeeze(' ') if sql
158
+ end
159
+
160
+ def render_sample_details(sample)
161
+ @indentation_depth=0
162
+ # skip past the root segments to the first child, which is always the controller
163
+ first_segment = sample.root_segment.called_segments.first
164
+
165
+ # render the segments, then the css classes to indent them
166
+ render_segment_details(first_segment).to_s + render_indentation_classes(@indentation_depth).to_s
167
+ end
168
+
169
+ # the rows logger plugin disables the sql tracing functionality of the NewRelic agent -
170
+ # notify the user about this
171
+ def rows_logger_present?
172
+ File.exist?(File.join(File.dirname(__FILE__), "../../../rows_logger/init.rb"))
173
+ end
174
+
175
+ def expand_segment_image(segment, depth)
176
+ if depth > 0
177
+ if !segment.called_segments.empty?
178
+ row_class =segment_child_row_class(segment)
179
+ link_to_function("<img src=\"#{collapsed_image_path}\" id=\"image_#{row_class}\" class_for_children=\"#{row_class}\" class=\"#{(!segment.called_segments.empty?) ? 'parent_segment_image' : 'child_segment_image'}\"", "toggle_row_class(this)")
180
+ end
181
+ end
182
+ end
183
+
184
+ def segment_child_row_class(segment)
185
+ "segment#{segment.segment_id}"
186
+ end
187
+
188
+ def summary_pie_chart(sample, width, height)
189
+ pie_chart = GooglePieChart.new
190
+ pie_chart.color, pie_chart.width, pie_chart.height = '6688AA', width, height
191
+
192
+ chart_data = sample.breakdown_data(6)
193
+ chart_data.each { |s| pie_chart.add_data_point dev_name(s.metric_name), to_ms(s.exclusive_time) }
194
+
195
+ pie_chart.render
196
+ end
197
+
198
+ def segment_row_classes(segment, depth)
199
+ classes = []
200
+
201
+ classes << "segment#{segment.parent_segment.segment_id}" if depth > 1
202
+
203
+ classes << "view_segment" if segment.metric_name.index('View') == 0
204
+ classes << "summary_segment" if segment.is_a?(NewRelic::TransactionSample::CompositeSegment)
205
+
206
+ classes.join(' ')
207
+ end
208
+
209
+ # render_segment_details should be called before calling this method
210
+ def render_indentation_classes(depth)
211
+ styles = []
212
+ (1..depth).each do |d|
213
+ styles << ".segment_indent_level#{d} { display: inline-block; margin-left: #{(d-1)*20}px }"
214
+ end
215
+ content_tag("style", styles.join(' '))
216
+ end
217
+
218
+ def sql_link_mouseover_options(segment)
219
+ { :onmouseover => "sql_mouse_over(#{segment.segment_id})", :onmouseout => "sql_mouse_out(#{segment.segment_id})"}
220
+ end
221
+
222
+ def explain_sql_link(segment, child_sql = false)
223
+ link_to 'SQL', explain_sql_url(segment)+ '"' + sql_link_mouseover_options(segment).map {|k,v| "#{k}=\"#{v}\""}.join(' ')+ 'fake=\"'
224
+ end
225
+
226
+ def explain_sql_links(segment)
227
+ if segment[:sql]
228
+ explain_sql_link segment
229
+ else
230
+ links = []
231
+ segment.called_segments.each do |child|
232
+ if child[:sql]
233
+ links << explain_sql_link(child, true)
234
+ end
235
+ end
236
+ links[0..1].join(', ') + (links.length > 2?', ...':'')
237
+ end
238
+ end
239
+
240
+ private
241
+ def file_and_line(stack_trace_line)
242
+ stack_trace_line.match(/(.*):(\d+)/)[1..2]
243
+ end
244
+
245
+ def using_textmate?
246
+ NewRelic::Control.instance.use_textmate?
247
+ end
248
+
249
+
250
+ def render_segment_details(segment, depth=0)
251
+ @detail_segment_count ||= 0
252
+ @detail_segment_count += 1
253
+
254
+ return '' if @detail_segment_count > trace_row_display_limit
255
+
256
+ @indentation_depth = depth if depth > @indentation_depth
257
+ repeat = nil
258
+ if segment.is_a?(NewRelic::TransactionSample::CompositeSegment)
259
+ html = ''
260
+ else
261
+ repeat = segment.parent_segment.detail_segments.length if segment.parent_segment.is_a?(NewRelic::TransactionSample::CompositeSegment)
262
+ html = render(:partial => 'segment', :object => [segment, depth, repeat])
263
+ depth += 1
264
+ end
265
+
266
+ segment.called_segments.each do |child|
267
+ html << render_segment_details(child, depth)
268
+ end
269
+
270
+ html
271
+ end
272
+
273
+ def exclude_file_from_stack_trace?(file, include_rails)
274
+ return false if include_rails
275
+ return true if file !~ /\.(rb|java)/
276
+ %w[/actionmailer/
277
+ /activerecord
278
+ /activeresource
279
+ /activesupport
280
+ /lib/mongrel
281
+ /actionpack
282
+ /passenger/
283
+ /railties
284
+ benchmark.rb].each { |s| return true if file.include? s }
285
+ false
286
+ end
287
+
288
+ def show_view_link(title, page_name)
289
+ link_to_function("[#{title}]", "show_view('#{page_name}')");
290
+ end
291
+
292
+
293
+ def link_to(name, location)
294
+ location = "/newrelic/#{location}" unless /:\/\// =~ location
295
+ "<a href=\"#{location}\">#{name}</a>"
296
+ end
297
+
298
+ def link_to_if(predicate, text, location="")
299
+ if predicate
300
+ link_to(text, location)
301
+ else
302
+ text
303
+ end
304
+ end
305
+
306
+ def link_to_unless_current(text, hash)
307
+ unless params[hash.keys[0].to_s]
308
+ link_to(text,"?#{hash.keys[0]}=#{hash.values[0]}")
309
+ else
310
+ text
311
+ end
312
+ end
313
+
314
+ def cycle(even, odd)
315
+ @cycle ||= 'a'
316
+ if @cycle == 'a'
317
+ @cycle = 'b'
318
+ even
319
+ else
320
+ @cycle = 'a'
321
+ odd
322
+ end
323
+ end
324
+
325
+ def link_to_function(title, javascript)
326
+ "<a href=\"#\" onclick=\"#{javascript}; return false;\">#{title}</a>"
327
+ end
328
+
329
+ def mime_type_from_extension(extension)
330
+ extension = extension[/[^.]*$/].dncase
331
+ case extension
332
+ when 'png'; 'image/png'
333
+ when 'gif'; 'image/gif'
334
+ when 'jpg'; 'image/jpg'
335
+ when 'css'; 'text/css'
336
+ when 'js'; 'text/javascript'
337
+ else 'text/plain'
338
+ end
339
+ end
340
+ def to_ms(number)
341
+ (number*1000).round
342
+ end
343
+ def to_percentage(value)
344
+ (value * 100).round if value
345
+ end
346
+ def with_delimiter(val)
347
+ return '0' if val.nil?
348
+ parts = val.to_s.split('.')
349
+ parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")
350
+ parts.join '.'
351
+ end
352
+
353
+ def profile_table(profile)
354
+ out = StringIO.new
355
+ printer = RubyProf::GraphHtmlPrinter.new(profile)
356
+ printer.print(out, :min_percent=>0.5)
357
+ out.string[/<body>(.*)<\/body>/im, 0].gsub('<table>', '<table class=profile>')
358
+ end
359
+ end
@@ -0,0 +1,49 @@
1
+
2
+ # A wrapper around the google charts service.
3
+ # TODO consider making generic and open sourcing
4
+ class GooglePieChart
5
+ attr_accessor :width, :height, :color
6
+
7
+ def initialize
8
+ # an array of [label, value]
9
+ @data = []
10
+ self.width = 300
11
+ self.height = 200
12
+ end
13
+
14
+ def add_data_point(label, value)
15
+ @data << [label, value]
16
+ @max = (@max.nil? || @max < value ? value : @max)
17
+ end
18
+
19
+ # render the chart to html by creating an image object and
20
+ # placing the correct URL to the google charts api
21
+ def render
22
+ labels = []
23
+ values = []
24
+ @data.each do |label, value|
25
+ labels << CGI::escape(label)
26
+ values << (value > 0 ? value * 100 / @max : value).round.to_s
27
+ end
28
+ params = {:cht => 'p', :chs => "#{width}x#{height}", :chd => "t:#{values.join(',')}", :chl => labels.join('|') }
29
+ params['chco'] = color if color
30
+
31
+ url = "http://chart.apis.google.com/chart?#{to_query(params)}"
32
+
33
+ alt_msg = "This pie chart is generated by Google Charts. You must be connected to the Internet to view this chart."
34
+ html = "<img id=\"pie_chart_image\" src=\"#{url}\" alt=\"#{alt_msg}\"/>"
35
+ return html
36
+ end
37
+
38
+ private
39
+ # Hash#to_query is not present in all supported rails platforms, so implement
40
+ # its equivalent here.
41
+ def to_query(params)
42
+ p = []
43
+ params.each do |k,v|
44
+ p << "#{k}=#{v}"
45
+ end
46
+
47
+ p.join "&"
48
+ end
49
+ end
@@ -0,0 +1,47 @@
1
+ <html xmlns="http://www.w3.org/1999/xhtml"
2
+ xml:lang="en" lang="en">
3
+ <head>
4
+ <script type="text/javascript" src="/newrelic/file/javascript/jquery-1.4.2.js"></script>
5
+ <title>New Relic RPM Developer Mode</title>
6
+ <link href="/newrelic/file/stylesheets/style.css"
7
+ media="screen" rel="stylesheet" type="text/css" />
8
+ </head>
9
+ <body>
10
+ <div id="header">
11
+ <img width="100%" height="4" src="/newrelic/file/images/blue_bar.gif" alt="spacer"/>
12
+ <table width="100%" height="60">
13
+ <tr>
14
+ <td valign="middle">
15
+ <a href='/newrelic'><img src="/newrelic/file/images/new_relic_rpm_desktop.gif" hspace="10" alt="New Relic RPM"/></a>
16
+ </td>
17
+ <td class="top_nav" valign="bottom">
18
+ <ul id="navlist">
19
+ <li>&raquo; <a href='/newrelic'>Home</a></li>
20
+ </ul>
21
+ </td>
22
+ </tr>
23
+ </table>
24
+ <div id="page_nav">
25
+ <table width="100%" height="100%" background="/newrelic/file/images/gray_bar.gif">
26
+ <tr valign="middle">
27
+ <td>
28
+ <span class="application_title">Developer Mode</span>
29
+ </td>
30
+ <td class="title_bar_right">
31
+ Monitor your Rails Application in production. <%=link_to 'Learn more.', 'http://www.newrelic.com/dev-upgrade.html' %>
32
+ </td>
33
+ </tr>
34
+ </table>
35
+ </div>
36
+ </div>
37
+ <div id='content'>
38
+ <%= yield %>
39
+ </div>
40
+ <div id='footer'>
41
+ <img width="100%" height="4" src="/newrelic/file/images/blue_bar.gif" alt="spacer"/>
42
+ <p>
43
+ <a href="/newrelic">Home</a> | <a href="&#109;&#97;&#105;&#108;&#116;&#111;:&#x73;&#x75;&#x70;&#112;&#111;&#x72;&#116;&#x40;&#x6E;&#x65;&#119;&#114;&#x65;&#x6C;&#105;&#x63;&#x2E;&#99;&#x6F;&#109;?subject=&#70;&#101;&#x65;&#x64;&#x62;&#x61;&#x63;&#107;" title="">&#x46;&#x65;&#101;&#x64;&#98;&#97;&#x63;&#x6B;</a><br />
44
+ Monitor your Rails Application in Production. <a href="http://www.newrelic.com/dev-upgrade.html">Learn more. &raquo;</a><br />
45
+ &copy; 2008 - <%= Time.now.strftime('%Y') %> New Relic. All rights reserved.</p>
46
+ </div>
47
+ </body>