Class: SimpleApm::ApmController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- SimpleApm::ApmController
- Includes:
- ApplicationHelper
- Defined in:
- app/controllers/simple_apm/apm_controller.rb
Instance Method Summary collapse
- #action_info ⇒ Object
- #actions ⇒ Object
- #change_date ⇒ Object
- #dashboard ⇒ Object
- #data ⇒ Object
- #data_delete ⇒ Object
- #index ⇒ Object
- #set_apm_date ⇒ Object
- #show ⇒ Object
Methods included from ApplicationHelper
Methods inherited from ApplicationController
Instance Method Details
#action_info ⇒ Object
45 46 47 |
# File 'app/controllers/simple_apm/apm_controller.rb', line 45 def action_info @action = SimpleApm::Action.find(params[:action_name]) end |
#actions ⇒ Object
41 42 43 |
# File 'app/controllers/simple_apm/apm_controller.rb', line 41 def actions @actions = SimpleApm::Action.all_names.map {|n| SimpleApm::Action.find(n)} end |
#change_date ⇒ Object
49 50 51 52 |
# File 'app/controllers/simple_apm/apm_controller.rb', line 49 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 ⇒ Object
54 55 56 |
# File 'app/controllers/simple_apm/apm_controller.rb', line 54 def data @data = SimpleApm::Redis.in_apm_days.map {|x| SimpleApm::Hit.day_info(x)} end |
#data_delete ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/controllers/simple_apm/apm_controller.rb', line 58 def data_delete if params[:date].is_a?(String) r = SimpleApm::Redis.clear_data(params[:date]) flash[:notice] = r[:success] ? '删除成功!' : r[:msg] elsif params[:type]=='month' del_count = SimpleApm::Redis.clear_data_before_time(Time.now.at_beginning_of_day - 1.month) flash[:notice] = "成功删除#{del_count}条数据" elsif params[:type]=='week' del_count = SimpleApm::Redis.clear_data_before_time(Time.now.at_beginning_of_day - 1.week) flash[:notice] = "成功删除#{del_count}条数据" elsif params[:type]=='stop_data' SimpleApm::Redis.stop! flash[:notice] = '设置成功!' elsif params[:type]=='rerun_data' SimpleApm::Redis.rerun! flash[:notice] = '设置成功!' else flash[:notice] = '未知操作!' # r = params[:date].map{|d|SimpleApm::Redis.clear_data(d)} # suc, fail = r.partition{|x|x[:success]} # flash[:notice] = "成功删除#{suc.length}" # flash[:notice] << ",失败#{fail.length}" if fail.length>0 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 |
# 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 [ 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), sec_str(request.view_runtime), request.host, request.remote_addr ] end render json: {data: @slow_requests} end format.html end end |
#set_apm_date ⇒ Object
84 85 86 87 |
# File 'app/controllers/simple_apm/apm_controller.rb', line 84 def set_apm_date # set_query_date redirect_to action: :dashboard end |