Class: ReqResStatController

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

Overview

TODO: This controller is yet to be tested

Instance Method Summary collapse

Instance Method Details

#get_detailsObject



35
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 35

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”



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

def get_stats
  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?

  min_values = ReqResStat.get_min(stat_key, start_time, end_time, granularity_in_hours)
  max_values = ReqResStat.get_max(stat_key, start_time, end_time, granularity_in_hours)
  avg_values = ReqResStat.get_avg(stat_key, start_time, end_time, granularity_in_hours)

  return_value = {
    start_time: start_time,
    end_time: end_time,
    granularity_in_hours: granularity_in_hours,
    min_values: min_values,
    max_values: max_values,
    avg_values: avg_values,
  }

  render json: return_value

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