Class: SimpleApm::ApmController

Inherits:
ApplicationController show all
Includes:
ApplicationHelper
Defined in:
app/controllers/simple_apm/apm_controller.rb

Instance Method Summary collapse

Methods included from ApplicationHelper

#sec_str, #time_label

Methods inherited from ApplicationController

#apm_date

Instance Method Details

#action_infoObject



45
46
47
# File 'app/controllers/simple_apm/apm_controller.rb', line 45

def action_info
  @action = SimpleApm::Action.find(params[:action_name])
end

#actionsObject



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_dateObject



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

#dashboardObject



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

#indexObject



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_dateObject



54
55
56
57
# File 'app/controllers/simple_apm/apm_controller.rb', line 54

def set_apm_date
  # set_query_date
  redirect_to action: :dashboard
end

#showObject



37
38
39
# File 'app/controllers/simple_apm/apm_controller.rb', line 37

def show
  @request = SimpleApm::Request.find(params[:id])
end