Class: SimpleApm::Action
- Inherits:
-
Object
- Object
- SimpleApm::Action
- Defined in:
- app/models/simple_apm/action.rb
Instance Attribute Summary collapse
-
#click_count ⇒ Object
Returns the value of attribute click_count.
-
#fast_id ⇒ Object
Returns the value of attribute fast_id.
-
#fast_time ⇒ Object
Returns the value of attribute fast_time.
-
#name ⇒ Object
Returns the value of attribute name.
-
#slow_id ⇒ Object
Returns the value of attribute slow_id.
-
#slow_time ⇒ Object
Returns the value of attribute slow_time.
-
#time ⇒ Object
Returns the value of attribute time.
Class Method Summary collapse
- .action_list_key ⇒ Object
- .all_names ⇒ Array<String>
- .find(action_name) ⇒ Object
- .info_key(action_name) ⇒ Object
- .update_by_request(h) ⇒ Object
Instance Method Summary collapse
- #avg_time ⇒ Object
- #fastest_request ⇒ Object
-
#initialize(h) ⇒ Action
constructor
A new instance of Action.
- #slow_requests(limit = 20, offset = 0) ⇒ Array<SimpleApm::SlowRequest>
- #slowest_request ⇒ Object
Constructor Details
#initialize(h) ⇒ Action
Returns a new instance of Action.
6 7 8 9 10 |
# File 'app/models/simple_apm/action.rb', line 6 def initialize(h) h.each do |k, v| send("#{k}=", v) end end |
Instance Attribute Details
#click_count ⇒ Object
Returns the value of attribute click_count.
4 5 6 |
# File 'app/models/simple_apm/action.rb', line 4 def click_count @click_count end |
#fast_id ⇒ Object
Returns the value of attribute fast_id.
4 5 6 |
# File 'app/models/simple_apm/action.rb', line 4 def fast_id @fast_id end |
#fast_time ⇒ Object
Returns the value of attribute fast_time.
4 5 6 |
# File 'app/models/simple_apm/action.rb', line 4 def fast_time @fast_time end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'app/models/simple_apm/action.rb', line 4 def name @name end |
#slow_id ⇒ Object
Returns the value of attribute slow_id.
4 5 6 |
# File 'app/models/simple_apm/action.rb', line 4 def slow_id @slow_id end |
#slow_time ⇒ Object
Returns the value of attribute slow_time.
4 5 6 |
# File 'app/models/simple_apm/action.rb', line 4 def slow_time @slow_time end |
#time ⇒ Object
Returns the value of attribute time.
4 5 6 |
# File 'app/models/simple_apm/action.rb', line 4 def time @time end |
Class Method Details
.action_list_key ⇒ Object
62 63 64 |
# File 'app/models/simple_apm/action.rb', line 62 def action_list_key SimpleApm::RedisKey['action-names'] end |
.all_names ⇒ Array<String>
58 59 60 |
# File 'app/models/simple_apm/action.rb', line 58 def all_names SimpleApm::Redis.smembers(action_list_key) end |
.find(action_name) ⇒ Object
29 30 31 |
# File 'app/models/simple_apm/action.rb', line 29 def find(action_name) SimpleApm::Action.new SimpleApm::Redis.hgetall(info_key(action_name)).merge(name: action_name) end |
.info_key(action_name) ⇒ Object
66 67 68 |
# File 'app/models/simple_apm/action.rb', line 66 def info_key(action_name) SimpleApm::RedisKey["action-info:#{action_name}"] end |
.update_by_request(h) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/models/simple_apm/action.rb', line 34 def update_by_request(h) SimpleApm::Redis.sadd(action_list_key, h['action_name']) _key = info_key h['action_name'] _request_store = false # 点击次数 SimpleApm::Redis.hincrby _key, 'click_count', 1 # 总时间 SimpleApm::Redis.hincrbyfloat _key, 'time', h['during'] _slow = SimpleApm::Redis.hget _key, 'slow_time' if _slow.nil? || h['during'].to_f > _slow.to_f # 记录最慢访问 SimpleApm::Redis.hmset _key, 'slow_time', h['during'], 'slow_id', h['request_id'] _request_store = true end _fast = SimpleApm::Redis.hget _key, 'fast_time' if _fast.nil? || h['during'].to_f < _fast.to_f # 记录最快访问 SimpleApm::Redis.hmset _key, 'fast_time', h['during'], 'fast_id', h['request_id'] _request_store = true end _request_store end |
Instance Method Details
#avg_time ⇒ Object
24 25 26 |
# File 'app/models/simple_apm/action.rb', line 24 def avg_time time.to_f/click_count.to_i end |
#fastest_request ⇒ Object
12 13 14 |
# File 'app/models/simple_apm/action.rb', line 12 def fastest_request @fastest_request ||= SimpleApm::Request.find(fast_id) end |
#slow_requests(limit = 20, offset = 0) ⇒ Array<SimpleApm::SlowRequest>
20 21 22 |
# File 'app/models/simple_apm/action.rb', line 20 def slow_requests(limit = 20, offset = 0) @slow_requests ||= SimpleApm::SlowRequest.list_by_action(name, limit, offset) end |