Class: SimpleApm::ApmController
Constant Summary
SimpleApm::ApplicationController::AVAILABLE_LOCALES
Instance Method Summary
collapse
#sec_str, #time_label
#apm_date, #simple_apm_locale
Instance Method Details
#action_info ⇒ Object
48
49
50
|
# File 'app/controllers/simple_apm/apm_controller.rb', line 48
def action_info
@action = SimpleApm::Action.find(params[:action_name])
end
|
#change_date ⇒ Object
52
53
54
55
|
# File 'app/controllers/simple_apm/apm_controller.rb', line 52
def change_date
session[:apm_date] = params[:date]
redirect_to request.referer
end
|
#dashboard ⇒ Object
8
9
10
11
12
13
14
|
# File 'app/controllers/simple_apm/apm_controller.rb', line 8
def dashboard
d = SimpleApm::RedisKey.query_date == Time.now.strftime('%Y-%m-%d') ? Time.now.strftime('%H:%M') : '23:50'
data = SimpleApm::Hit.chart_data(0, d)
@x_names = data.keys.sort
@time_arr = @x_names.map {|n| data[n][:hits].to_i.zero? ? 0 : (data[n][:time].to_f / data[n][:hits].to_i).round(3)}
@hits_arr = @x_names.map {|n| data[n][:hits] rescue 0}
end
|
#data_delete ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'app/controllers/simple_apm/apm_controller.rb', line 66
def data_delete
if params[:date].is_a?(String)
r = SimpleApm::Redis.clear_data(params[:date])
flash[:notice] = r[:success] ? t("simple_apm.flash.deleted") : t("simple_apm.flash.no_data_for_day")
elsif params[:type]=='month'
del_count = SimpleApm::Redis.clear_data_before_time(Time.now.at_beginning_of_day - 1.month)
flash[:notice] = t("simple_apm.flash.deleted_count", count: del_count)
elsif params[:type]=='week'
del_count = SimpleApm::Redis.clear_data_before_time(Time.now.at_beginning_of_day - 1.week)
flash[:notice] = t("simple_apm.flash.deleted_count", count: del_count)
elsif params[:type]=='stop_data'
SimpleApm::Redis.stop!
flash[:notice] = t("simple_apm.flash.updated")
elsif params[:type]=='rerun_data'
SimpleApm::Redis.rerun!
flash[:notice] = t("simple_apm.flash.updated")
else
flash[:notice] = t("simple_apm.flash.unknown_action")
end
redirect_to action: :data
end
|
#index ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'app/controllers/simple_apm/apm_controller.rb', line 16
def index
respond_to do |format|
format.json do
@slow_requests = SimpleApm::SlowRequest.list(params[:count] || 200).map do |r|
request = r.request rescue next
[
link_to(time_label(request.started), show_path(id: request.request_id)),
link_to(request.action_name, action_info_path(action_name: request.action_name)),
sec_str(request.during),
sec_str(request.db_runtime),
request.queries_count,
sec_str(request.view_runtime),
sec_str(request.net_http_during),
request.memory_during.to_f.round(1),
request.host,
request.remote_addr
]
end.compact
render json: {data: @slow_requests}
end
format.html
end
end
|
#set_apm_date ⇒ Object
92
93
94
95
|
# File 'app/controllers/simple_apm/apm_controller.rb', line 92
def set_apm_date
redirect_to action: :dashboard
end
|
#set_locale ⇒ Object
57
58
59
60
|
# File 'app/controllers/simple_apm/apm_controller.rb', line 57
def set_locale
session[:simple_apm_locale] = params[:locale] if AVAILABLE_LOCALES.include?(params[:locale])
redirect_back fallback_location: dashboard_path
end
|
#show ⇒ Object
40
41
42
|
# File 'app/controllers/simple_apm/apm_controller.rb', line 40
def show
@request = SimpleApm::Request.find(params[:id])
end
|