Module: RailsObservatory::ApplicationHelper

Defined in:
app/helpers/rails_observatory/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#format_event_value(value) ⇒ Object



42
43
44
45
46
47
48
# File 'app/helpers/rails_observatory/application_helper.rb', line 42

def format_event_value(value)
  if value.is_a?(Numeric)
    value.round(2)
  else
    value
  end
end

#highlight_source_extract(source_extract) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'app/helpers/rails_observatory/application_helper.rb', line 5

def highlight_source_extract(source_extract)
  source_extract.symbolize_keys => {code:, line_number:}
  fmt = Rouge::Formatters::HTMLLineTable.new(Rouge::Formatters::HTML.new, start_line: code.keys.first.to_s.to_i)
  html = Nokogiri::HTML4(Rouge.highlight(code.values.flatten.join(""), 'ruby', fmt))
  html.css("#line-#{line_number}").add_class('hll')
  line = code[line_number.to_s]
  if line.length > 1
    html.css("#line-#{line_number}").attr('data-highlight-start', line[0].length).attr('data-highlight-length', line[1].length)
  end
  html.to_html
end

#pretty_backtrace_location(backtrace_line) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/helpers/rails_observatory/application_helper.rb', line 50

def pretty_backtrace_location(backtrace_line)
  path, lineno, method = backtrace_line.split(':')
  path = path.sub(Gem.paths.home, '')
  # remove 'in ' from method name
  method = method.match(/in `([^']+) (:?in .*)'/)
  method = method[1] if method
  tag.div(class: 'backtrace-line') do
    tag.span(path, class: '_path') +
      ' in ' +
      tag.span(method, class: '_method') +
      ' at line ' +
      tag.span(lineno, class: '_lineno')

  end
end

#preview_mail_path(message_id) ⇒ Object



66
67
68
# File 'app/helpers/rails_observatory/application_helper.rb', line 66

def preview_mail_path(message_id)
  "/rails/mailers/delivered_mail/preview?message_id=#{message_id}"
end

#redis_mem_infoObject

"used_memory_human"=>"44.42M",
"used_memory_rss"=>"70778880",
"used_memory_rss_human"=>"67.50M",
"used_memory_peak"=>"49028032",
"used_memory_peak_human"=>"46.76M",
"used_memory_peak_perc"=>"94.99%",
"used_memory_overhead"=>"2195208",
"used_memory_startup"=>"1118008",
"used_memory_dataset"=>"44378544",
"used_memory_dataset_perc"=>"97.63%",
"allocator_allocated"=>"46540912",
"allocator_active"=>"70693888",
"allocator_resident"=>"70693888",
"total_system_memory"=>"8225423360",
"total_system_memory_human"=>"7.66G",
"used_memory_lua"=>"84992",
"used_memory_lua_human"=>"83.00K",
"used_memory_scripts"=>"4768",
"used_memory_scripts_human"=>"4.66K",
"number_of_cached_scripts"=>"2",
"maxmemory"=>"0",
"maxmemory_human"=>"0B",
"maxmemory_policy"=>"noeviction",
"allocator_frag_ratio"=>"1.52",
"allocator_frag_bytes"=>"24152976",
"allocator_rss_ratio"=>"1.00",
"allocator_rss_bytes"=>"0",
"rss_overhead_ratio"=>"1.00",
"rss_overhead_bytes"=>"84992",
"mem_fragmentation_ratio"=>"1.52",
"mem_fragmentation_bytes"=>"24237968",
"mem_not_counted_for_evict"=>"0",
"mem_replication_backlog"=>"0",
"mem_clients_slaves"=>"0",
"mem_clients_normal"=>"51176",
"mem_aof_buffer"=>"0",
"mem_allocator"=>"libc",
"active_defrag_running"=>"0",
"lazyfree_pending_objects"=>"0",
"lazyfreed_objects"=>"0"


111
112
113
# File 'app/helpers/rails_observatory/application_helper.rb', line 111

def redis_mem_info
  @info ||= Rails.configuration.rails_observatory.redis.call('info', 'memory').split("\r\n").slice(1..).map { _1.split(":") }.to_h
end

#series_for(name:, aggregate_using:, time_range: nil, downsample: 60, children: false, **opts) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/rails_observatory/application_helper.rb', line 17

def series_for(name:, aggregate_using:, time_range: nil, downsample: 60, children: false,  **opts)
  if children
    series = TimeSeries.where(parent: name, **opts)
  else
    series = TimeSeries.where(name:, **opts)
  end
  series = series.downsample(downsample, using: aggregate_using)
  series = series.slice(time_range) if time_range
  series
end

#series_value(name:, aggregate_using:) ⇒ Object



28
29
30
31
# File 'app/helpers/rails_observatory/application_helper.rb', line 28

def series_value(name:, aggregate_using:)
  series = series_for(name:, aggregate_using: aggregate_using, downsample: 1)
  series.first&.value
end

#time_slice_endObject



37
38
39
40
# File 'app/helpers/rails_observatory/application_helper.rb', line 37

def time_slice_end
  time = @time_range.end.nil? ? Time.now.to_i : @time_range.end.to_i
  time * 1000
end

#time_slice_startObject



33
34
35
# File 'app/helpers/rails_observatory/application_helper.rb', line 33

def time_slice_start
  @time_range.begin.to_i * 1000
end