Class: Profiler::Collectors::HttpCollector
Instance Attribute Summary
#profile
Instance Method Summary
collapse
descendants, #has_data?, inherited, #name, #panel_content, #render_html, #render_mode
Constructor Details
Returns a new instance of HttpCollector.
9
10
11
12
|
# File 'lib/profiler/collectors/http_collector.rb', line 9
def initialize(profile)
super
@requests = []
end
|
Instance Method Details
#collect ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/profiler/collectors/http_collector.rb', line 40
def collect
Thread.current[:profiler_http_collector] = nil
threshold = Profiler.configuration.slow_http_threshold
store_data(
total_requests: @requests.size,
total_duration: @requests.sum { |r| r[:duration] }.round(2),
slow_requests: @requests.count { |r| r[:duration] >= threshold },
error_requests: @requests.count { |r| r[:status] >= 400 || r[:status] == 0 },
by_host: group_by_host,
by_status: group_by_status,
requests: @requests.map { |r| r.transform_keys(&:to_s) }
)
end
|
#icon ⇒ Object
14
15
16
|
# File 'lib/profiler/collectors/http_collector.rb', line 14
def icon
"🔗"
end
|
#priority ⇒ Object
18
19
20
|
# File 'lib/profiler/collectors/http_collector.rb', line 18
def priority
35
end
|
#record_request(payload) ⇒ Object
56
57
58
|
# File 'lib/profiler/collectors/http_collector.rb', line 56
def record_request(payload)
@requests << payload
end
|
#tab_config ⇒ Object
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/profiler/collectors/http_collector.rb', line 22
def tab_config
{
key: "http",
label: "Outbound HTTP",
icon: icon,
priority: priority,
enabled: true,
default_active: false
}
end
|
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/profiler/collectors/http_collector.rb', line 60
def toolbar_summary
total = @requests.size
return { text: "0 HTTP", color: "green" } if total == 0
threshold = Profiler.configuration.slow_http_threshold
errors = @requests.count { |r| r[:status] >= 400 || r[:status] == 0 }
slow = @requests.count { |r| r[:duration] >= threshold }
duration = @requests.sum { |r| r[:duration] }.round(2)
color = if errors > 0 || slow > 0
"red"
elsif total > 10
"orange"
else
"green"
end
{ text: "#{total} HTTP (#{duration}ms)", color: color }
end
|