Class: SimpleApm::Hit
- Inherits:
-
Object
- Object
- SimpleApm::Hit
- Defined in:
- app/models/simple_apm/hit.rb
Class Method Summary collapse
- .chart_data(start_time = '00:00', end_time = '23:50', per = 'minute') ⇒ Object
- .minute_key ⇒ Object
- .to_double_str(i) ⇒ Object
- .update_by_request(h) ⇒ Object
Class Method Details
.chart_data(start_time = '00:00', end_time = '23:50', per = 'minute') ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/simple_apm/hit.rb', line 7 def chart_data(start_time = '00:00', end_time = '23:50', per = 'minute') start_hour = start_time.to_s.split(':').first.to_i end_hour = [end_time.to_s.split(':').first.to_i, 23].min end_min = end_time.to_s.split(':')[1] minutes = %w[00 10 20 30 40 50] redis_result = Hash[SimpleApm::Redis.hgetall(minute_key)] result_hash = {} start_hour.upto(end_hour).each do |_hour| minutes.each do |_min| break if end_hour.to_i==_hour && end_min && _min.to_i > end_min.to_i k = "#{to_double_str _hour}:#{to_double_str _min}" _time = redis_result["#{k}:time"].to_f _hits = redis_result["#{k}:hits"].to_i if per =='minute' result_hash[k] = {time: _time, hits: _hits} else _key = to_double_str _hour result_hash[_key] ||= { time: 0.0, hits: 0 } result_hash[_key][:time] += _time result_hash[_key][:hits] += _hits end end end result_hash end |
.minute_key ⇒ Object
45 46 47 |
# File 'app/models/simple_apm/hit.rb', line 45 def minute_key SimpleApm::RedisKey['per-10-minute'] end |
.to_double_str(i) ⇒ Object
41 42 43 |
# File 'app/models/simple_apm/hit.rb', line 41 def to_double_str(i) i.to_s.size==1 ? "0#{i}" : i.to_s end |
.update_by_request(h) ⇒ Object
34 35 36 37 38 39 |
# File 'app/models/simple_apm/hit.rb', line 34 def update_by_request(h) # SimpleApm::Redis.hincrby hour_hit_key, Time.now.hour, 1 minute_base = "#{to_double_str Time.now.hour}:#{to_double_str 10 * (Time.now.min / 10)}" SimpleApm::Redis.hincrby minute_key, "#{minute_base}:hits", 1 SimpleApm::Redis.hincrbyfloat minute_key, "#{minute_base}:time", h['during'] end |