Class: SimpleApm::Action
- Inherits:
-
Object
- Object
- SimpleApm::Action
- Defined in:
- app/models/simple_apm/action.rb
Instance Attribute Summary collapse
-
#cached_queries_count ⇒ Object
Returns the value of attribute cached_queries_count.
-
#click_count ⇒ Object
Returns the value of attribute click_count.
-
#db_time ⇒ Object
Returns the value of attribute db_time.
-
#fast_id ⇒ Object
Returns the value of attribute fast_id.
-
#fast_time ⇒ Object
Returns the value of attribute fast_time.
-
#http_time ⇒ Object
Returns the value of attribute http_time.
-
#name ⇒ Object
Returns the value of attribute name.
-
#queries_count ⇒ Object
Returns the value of attribute queries_count.
-
#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_cached_queries_count ⇒ Object
- #avg_db_time ⇒ Object
- #avg_http_time ⇒ Object
- #avg_queries_count ⇒ Object
- #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.
7 8 9 10 11 |
# File 'app/models/simple_apm/action.rb', line 7 def initialize(h) h.each do |k, v| send("#{k}=", v) end end |
Instance Attribute Details
#cached_queries_count ⇒ Object
Returns the value of attribute cached_queries_count.
4 5 6 |
# File 'app/models/simple_apm/action.rb', line 4 def cached_queries_count @cached_queries_count end |
#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 |
#db_time ⇒ Object
Returns the value of attribute db_time.
4 5 6 |
# File 'app/models/simple_apm/action.rb', line 4 def db_time @db_time 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 |
#http_time ⇒ Object
Returns the value of attribute http_time.
4 5 6 |
# File 'app/models/simple_apm/action.rb', line 4 def http_time @http_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 |
#queries_count ⇒ Object
Returns the value of attribute queries_count.
4 5 6 |
# File 'app/models/simple_apm/action.rb', line 4 def queries_count @queries_count 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
87 88 89 |
# File 'app/models/simple_apm/action.rb', line 87 def action_list_key SimpleApm::RedisKey['action-names'] end |
.all_names ⇒ Array<String>
83 84 85 |
# File 'app/models/simple_apm/action.rb', line 83 def all_names SimpleApm::Redis.smembers(action_list_key) end |
.find(action_name) ⇒ Object
46 47 48 |
# File 'app/models/simple_apm/action.rb', line 46 def find(action_name) SimpleApm::Action.new SimpleApm::Redis.hgetall(info_key(action_name)).merge(name: action_name) end |
.info_key(action_name) ⇒ Object
91 92 93 |
# File 'app/models/simple_apm/action.rb', line 91 def info_key(action_name) SimpleApm::RedisKey["action-info:#{action_name}"] end |
.update_by_request(h) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/models/simple_apm/action.rb', line 51 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'] # 数据库访问时间 SimpleApm::Redis.hincrbyfloat _key, 'db_time', h['db_runtime'] # SQL执行次数 SimpleApm::Redis.hincrby _key, 'queries_count', h['queries_count'].to_i # SQL缓存命中次数 SimpleApm::Redis.hincrby _key, 'cached_queries_count', h['cached_queries_count'].to_i # 外部http访问时间 SimpleApm::Redis.hincrbyfloat _key, 'http_time', h['net_http_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_cached_queries_count ⇒ Object
37 38 39 |
# File 'app/models/simple_apm/action.rb', line 37 def avg_cached_queries_count cached_queries_count.to_f/click_count.to_i end |
#avg_db_time ⇒ Object
29 30 31 |
# File 'app/models/simple_apm/action.rb', line 29 def avg_db_time db_time.to_f/click_count.to_i end |
#avg_http_time ⇒ Object
25 26 27 |
# File 'app/models/simple_apm/action.rb', line 25 def avg_http_time http_time.to_f/click_count.to_i end |
#avg_queries_count ⇒ Object
33 34 35 |
# File 'app/models/simple_apm/action.rb', line 33 def avg_queries_count queries_count.to_f/click_count.to_i end |
#avg_time ⇒ Object
41 42 43 |
# File 'app/models/simple_apm/action.rb', line 41 def avg_time time.to_f/click_count.to_i end |
#fastest_request ⇒ Object
13 14 15 |
# File 'app/models/simple_apm/action.rb', line 13 def fastest_request @fastest_request ||= SimpleApm::Request.find(fast_id) end |
#slow_requests(limit = 20, offset = 0) ⇒ Array<SimpleApm::SlowRequest>
21 22 23 |
# File 'app/models/simple_apm/action.rb', line 21 def slow_requests(limit = 20, offset = 0) @slow_requests ||= SimpleApm::SlowRequest.list_by_action(name, limit, offset) end |