Class: ReqResStatController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/generators/templates/req_res_stat_controller.rb

Overview

TODO: This controller is not fully tested yet

Instance Method Summary collapse

Instance Method Details

#get_detailsObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/generators/templates/req_res_stat_controller.rb', line 36

def get_details
  stat_key = params[:stat_key].to_sym
  start_time = parse_date_time_zone params[:start_time]
  end_time = parse_date_time_zone params[:end_time]
  granularity_in_hours = params[:granularity_in_hours].to_i.hours if params[:granularity_in_hours].present?

  details = ReqResStat.get_details(stat_key, start_time, end_time, nil, granularity_in_hours)

  return_value = {
    details: details
  }

  render json: return_value
rescue Exception => ex
  error_message = [ex.message, ex.backtrace.join("\n")].join("\n")
  render json: {error_message: error_message}
end

#get_statsObject

params format: “2009-06-24 12:39:54 09:00” params format: “2009-06-24 12:39:54 09:00” params popular choices: “request_count”, “error_count”, “min_time”, “max_time”, “avg_time”



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/generators/templates/req_res_stat_controller.rb', line 10

def get_stats
  # query conditions
  start_time = params[:start_time].present? ? parase_data_time_zone(params[:start_time]) : Time.now - 7.days
  end_time = params[:end_time].present? ? parase_data_time_zone(params[:end_time]) : Time.now
  granularity_in_hours = params[:granularity_in_hours].present? ? params[:granularity_in_hours].to_i.hours : 1.hour

  # firing the base query only once
  base_req_res_stats = ReqResStat.get_within(start_time, end_time)

  # gathering data
  @request_count_stats = fetch_stats_for(:request_count, start_time, end_time, granularity_in_hours, base_req_res_stats)
  @max_time_stats = fetch_stats_for(:max_time, start_time, end_time, granularity_in_hours, base_req_res_stats)
  @avg_time_stats = fetch_stats_for(:avg_time, start_time, end_time, granularity_in_hours, base_req_res_stats)
  @min_time_stats = fetch_stats_for(:min_time, start_time, end_time, granularity_in_hours, base_req_res_stats)

  render json: {
    request_count_stats: @request_count_stats,
    max_time_stats: @max_time_stats,
    avg_time_stats: @avg_time_stats,
    min_time_stats: @min_time_stats
  }
rescue Exception => ex
  error_message = [ex.message, ex.backtrace.join("\n")].join("\n")
  render json: {error_message: error_message}
end