simple_apm 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8c989664fa3b8d390ac868ac144adf3f8c75114374d4843cb80c6ec36080eed
4
- data.tar.gz: fdc007de42402503a588d7775d2a410527c125c012ff5b5c56b9d3581c1379f9
3
+ metadata.gz: 7022496ba04174ad3f103383c9388b3b5203c79f22eec0381bb50f6d2d8d6f14
4
+ data.tar.gz: 2e6faa25b91f124e29c9c092cb432fcfd3593631daecc18edd61182f19a9d10b
5
5
  SHA512:
6
- metadata.gz: d0327ea89887bdc55829cbb976726b991ef836e349eedea1ee98c517d1e2e24bb86cb82950ddbfdade6c9718fb3826bbe4c2fe4261fd6158a56fb44d5acd7a49
7
- data.tar.gz: c45971ff9bf1fd1683ab5110988cf0f37e52431ae202891ab2d4345f7497ed312e01bc7074cee1b953e745deaf34cdac79383c9155e3e5713c7774545cd0b136
6
+ metadata.gz: bafd772296505aae3f057b5a6a51fed6aba84f1c31dc81245b80c989b6c9f9845b0e16d99e769e7a7f74e6e538402ff7bd0983b8817c74a6990aa29c64804e64
7
+ data.tar.gz: e8393025dec36cf4a329a10f69a4a187d5361a07f8e59d3dc1751aa931562a323cf2e3ff34e11d2808a20ef8ac721d83ed56c4e7e5983e08758092b91a31c012
@@ -1,7 +1,7 @@
1
1
  # 请求 Controller#Action
2
2
  module SimpleApm
3
3
  class Action
4
- attr_accessor :name, :click_count, :time, :slow_time, :slow_id, :fast_time, :fast_id
4
+ attr_accessor :name, :click_count, :time, :http_time, :slow_time, :slow_id, :fast_time, :fast_id
5
5
 
6
6
  def initialize(h)
7
7
  h.each do |k, v|
@@ -21,6 +21,10 @@ module SimpleApm
21
21
  @slow_requests ||= SimpleApm::SlowRequest.list_by_action(name, limit, offset)
22
22
  end
23
23
 
24
+ def avg_http_time
25
+ http_time.to_f/click_count.to_i
26
+ end
27
+
24
28
  def avg_time
25
29
  time.to_f/click_count.to_i
26
30
  end
@@ -39,6 +43,8 @@ module SimpleApm
39
43
  SimpleApm::Redis.hincrby _key, 'click_count', 1
40
44
  # 总时间
41
45
  SimpleApm::Redis.hincrbyfloat _key, 'time', h['during']
46
+ # 外部http访问时间
47
+ SimpleApm::Redis.hincrbyfloat _key, 'http_time', h['net_http_during']
42
48
  _slow = SimpleApm::Redis.hget _key, 'slow_time'
43
49
  if _slow.nil? || h['during'].to_f > _slow.to_f
44
50
  # 记录最慢访问
@@ -4,6 +4,7 @@
4
4
  <th>Name</th>
5
5
  <th>点击次数</th>
6
6
  <th>平均响应时间</th>
7
+ <th>平均http访问时间</th>
7
8
  <th>最快响应时间</th>
8
9
  <th>最慢响应时间</th>
9
10
  </tr>
@@ -14,6 +15,7 @@
14
15
  <td><%= link_to action.name, action_info_path(action_name: action.name) %></td>
15
16
  <td><%= action.click_count %></td>
16
17
  <td><%= sec_str action.avg_time %></td>
18
+ <td><%= sec_str action.avg_http_time %></td>
17
19
  <td><%= link_to sec_str(action.fast_time), show_path(id: action.fast_id) %></td>
18
20
  <td><%= link_to sec_str(action.slow_time), show_path(id: action.slow_id) %></td>
19
21
  </tr>
@@ -48,7 +48,7 @@
48
48
  </tr>
49
49
  <% @request.net_http_requests.each do |r| %>
50
50
  <tr>
51
- <td><%= r.started %></td>
51
+ <td><%= time_label r.started %></td>
52
52
  <td><%= r.url %></td>
53
53
  <td><%= sec_str r.during %></td>
54
54
  <td><%= "#{r.filename}: #{r.line}" if r.filename.present? %></td>
@@ -3,12 +3,24 @@ module SimpleApm
3
3
  class << self
4
4
  def install
5
5
  Net::HTTP.class_eval do
6
- alias orig_request request unless method_defined?(:orig_request)
6
+ alias orig_request_apm request unless method_defined?(:orig_request)
7
7
 
8
8
  def request(req, body = nil, &block)
9
- url = "http://#{@address}:#{@port}#{req.path}"
10
- ActiveSupport::Notifications.instrument "net_http.request", url: url, host: @address, path: req.path do
11
- @response = orig_request(req, body, &block)
9
+ url = if @port == '80'
10
+ "http://#{@address}#{req.path}"
11
+ elsif @port == '443'
12
+ "https://#{@address}#{req.path}"
13
+ else
14
+ "http://#{@address}:#{@port}#{req.path}"
15
+ end
16
+ # 会调用两次(HTTParty)
17
+ if started?
18
+ ActiveSupport::Notifications.instrument "net_http.request", url: url, host: @address, path: req.path do
19
+ @response = orig_request_apm(req, body, &block)
20
+ end
21
+ else
22
+ # 去connect
23
+ @response = orig_request_apm(req, body, &block)
12
24
  end
13
25
  @response
14
26
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleApm
2
- VERSION = '1.0.7'
2
+ VERSION = '1.0.8'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_apm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - yuanyin.xia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-17 00:00:00.000000000 Z
11
+ date: 2018-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails