Class: QaServer::PerformanceGraphDataService

Inherits:
Object
  • Object
show all
Extended by:
PerformanceHistoryDataKeys
Defined in:
app/services/qa_server/performance_graph_data_service.rb

Constant Summary

Constants included from PerformanceHistoryDataKeys

QaServer::PerformanceHistoryDataKeys::ALL_ACTIONS, QaServer::PerformanceHistoryDataKeys::ALL_AUTH, QaServer::PerformanceHistoryDataKeys::AVG_ACTN, QaServer::PerformanceHistoryDataKeys::AVG_FULL, QaServer::PerformanceHistoryDataKeys::AVG_GRPH, QaServer::PerformanceHistoryDataKeys::AVG_LOAD, QaServer::PerformanceHistoryDataKeys::AVG_NORM, QaServer::PerformanceHistoryDataKeys::AVG_RETR, QaServer::PerformanceHistoryDataKeys::BY_DAY, QaServer::PerformanceHistoryDataKeys::BY_HOUR, QaServer::PerformanceHistoryDataKeys::BY_MONTH, QaServer::PerformanceHistoryDataKeys::FETCH, QaServer::PerformanceHistoryDataKeys::FOR_DATATABLE, QaServer::PerformanceHistoryDataKeys::FOR_DAY, QaServer::PerformanceHistoryDataKeys::FOR_MONTH, QaServer::PerformanceHistoryDataKeys::FOR_YEAR, QaServer::PerformanceHistoryDataKeys::HIGH_ACTN, QaServer::PerformanceHistoryDataKeys::HIGH_FULL, QaServer::PerformanceHistoryDataKeys::HIGH_GRPH, QaServer::PerformanceHistoryDataKeys::HIGH_LOAD, QaServer::PerformanceHistoryDataKeys::HIGH_NORM, QaServer::PerformanceHistoryDataKeys::HIGH_RETR, QaServer::PerformanceHistoryDataKeys::LOW_ACTN, QaServer::PerformanceHistoryDataKeys::LOW_FULL, QaServer::PerformanceHistoryDataKeys::LOW_GRPH, QaServer::PerformanceHistoryDataKeys::LOW_LOAD, QaServer::PerformanceHistoryDataKeys::LOW_NORM, QaServer::PerformanceHistoryDataKeys::LOW_RETR, QaServer::PerformanceHistoryDataKeys::SEARCH, QaServer::PerformanceHistoryDataKeys::STATS

Class Method Summary collapse

Class Method Details

.average_last_12_months(authority_name: nil, action: nil) ⇒ Object

Get daily average for the past 12 months.

Examples:

{ 0: { month: '09-2019', stats: { load_avg_ms: 12.3, normalization_avg_ms: 4.2, full_request_avg_ms: 16.5, etc. }},
  1: { month: '10-2019', stats: { load_avg_ms: 12.3, normalization_avg_ms: 4.2, full_request_avg_ms: 16.5, etc. }},
  2: { month: '11-2019', stats: { load_avg_ms: 12.3, normalization_avg_ms: 4.2, full_request_avg_ms: 16.5, etc. }},
  ...,
  11: { month: '08-2019', stats: { load_avg_ms: 12.3, normalization_avg_ms: 4.2, full_request_avg_ms: 16.5, etc. }}
}


69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/services/qa_server/performance_graph_data_service.rb', line 69

def average_last_12_months(authority_name: nil, action: nil)
  start_month = Time.now.getlocal.beginning_of_month - 11.months
  avgs = {}
  0.upto(11).each do |idx|
    records = records_by(authority_name, action, start_month..start_month.end_of_month)
    stats = stats_calculator_class.new(records).calculate_stats(avg: true, full: false)
    data = {}
    data[BY_MONTH] = start_month.strftime("%m-%Y")
    data[STATS] = stats
    avgs[idx] = data
    start_month += 1.month
  end
  avgs
end

.average_last_24_hours(authority_name: nil, action: nil) ⇒ Object

Get hourly average for the past 24 hours.

Examples:

{ 0: { hour: '1400', stats: { load_avg_ms: 12.3, normalization_avg_ms: 4.2, full_request_avg_ms: 16.5, etc. }},
  1: { hour: '1500', stats: { load_avg_ms: 12.3, normalization_avg_ms: 4.2, full_request_avg_ms: 16.5, etc. }},
  2: { hour: '1600', stats: { load_avg_ms: 12.3, normalization_avg_ms: 4.2, full_request_avg_ms: 16.5, etc. }},
  ...,
  23: { hour: 'NOW', stats: { load_avg_ms: 12.3, normalization_avg_ms: 4.2, full_request_avg_ms: 16.5, etc. }}
}


21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/services/qa_server/performance_graph_data_service.rb', line 21

def average_last_24_hours(authority_name: nil, action: nil)
  start_hour = Time.now.getlocal.beginning_of_hour - 23.hours
  avgs = {}
  0.upto(23).each do |idx|
    records = records_by(authority_name, action, start_hour..start_hour.end_of_hour)
    stats = stats_calculator_class.new(records).calculate_stats(avg: true, full: false)
    data = {}
    data[BY_HOUR] = performance_by_hour_label(idx, start_hour)
    data[STATS] = stats
    avgs[idx] = data
    start_hour += 1.hour
  end
  avgs
end

.average_last_30_days(authority_name: nil, action: nil) ⇒ Object

Get daily average for the past 30 days.

Examples:

{ 0: { day: '07-15-2019', stats: { load_avg_ms: 12.3, normalization_avg_ms: 4.2, full_request_avg_ms: 16.5, etc. }},
  1: { day: '07-16-2019', stats: { load_avg_ms: 12.3, normalization_avg_ms: 4.2, full_request_avg_ms: 16.5, etc. }},
  2: { day: '07-17-2019', stats: { load_avg_ms: 12.3, normalization_avg_ms: 4.2, full_request_avg_ms: 16.5, etc. }},
  ...,
  29: { day: 'TODAY', stats: { load_avg_ms: 12.3, normalization_avg_ms: 4.2, full_request_avg_ms: 16.5, etc. }}
}


45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/services/qa_server/performance_graph_data_service.rb', line 45

def average_last_30_days(authority_name: nil, action: nil)
  start_day = Time.now.getlocal.beginning_of_day - 29.days
  avgs = {}
  0.upto(29).each do |idx|
    records = records_by(authority_name, action, start_day..start_day.end_of_day)
    stats = stats_calculator_class.new(records).calculate_stats(avg: true, full: false)
    data = {}
    data[BY_DAY] = performance_by_day_label(idx, start_day)
    data[STATS] = stats
    avgs[idx] = data
    start_day += 1.day
  end
  avgs
end