simple_apm 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0788a278666b619108511b355faf6e753efd77f91af407b9d970a6e94546e5a8'
4
- data.tar.gz: b9c74722038adf1377802becec05688efff134f87d144f5f8036b303720ffd54
3
+ metadata.gz: bd96eb80e66cb02f54e84663909f84a974ff4071b2f5d30a9c136fa3c23552b1
4
+ data.tar.gz: 4b4018dc5da34ade9b345dc58622655d9263603557f1411cf17f8affe20e2725
5
5
  SHA512:
6
- metadata.gz: 98c2ea0efdf65da918f63dd9f7e0c0e3ad5206e511aec00b695ba9509e03d4b87c7023db9361bbf458f772965edf4ffd1840942d4cd3361cae0349009d1948f2
7
- data.tar.gz: 10c7e14e85a49bfab9587b445bc8bbe5ab207ac0ff9b731eb0d499fafb800b4e23e02d4fa8b5d4c93c6ec799b4a676966572dfc3e3b3d4b63aec95945d9bf3dd
6
+ metadata.gz: bdcd065ce63b5143b915d8f288d23132da6caf4b383cdf938c5baf9347770eb90a252bc185ba70a9ddf66fdf46b3ae10103bb7aa7b9661e2674a978a7bd5813d
7
+ data.tar.gz: c734c6adf33cfb68ff94c330a1b8dea7a2be74fdee069e8ee9406f86190b23be426dbb1994ac890e391c3b4976bca1b0e320390682ac2c8ac30089a1cbb5ae06
@@ -4,62 +4,71 @@ require "simple_apm/engine"
4
4
  require 'callsite'
5
5
  module SimpleApm
6
6
  ActiveSupport::Notifications.subscribe('process_action.action_controller') do |name, started, finished, unique_id, payload|
7
- request_id = Thread.current['action_dispatch.request_id']
8
- if request_id.present?
9
- action_name = "#{payload[:controller]}##{payload[:action]}" #payload[:format]
10
- info = {
11
- request_id: request_id,
12
- action_name: action_name,
13
- during: finished - started,
14
- started: started.to_s,
15
- db_runtime: payload[:db_runtime].to_f/1000,
16
- view_runtime: payload[:view_runtime].to_f/1000,
17
- controller: payload[:controller],
18
- action: payload[:action],
19
- host: Socket.gethostname,
20
- remote_addr: payload[:headers]['REMOTE_ADDR'],
21
- method: payload[:method],
22
- format: payload[:format],
23
- exception: payload[:exception].presence.to_json
24
- }.with_indifferent_access
25
- info[:status] = '500' if payload[:exception]
26
- # 存储
27
- in_slow = SimpleApm::SlowRequest.update_by_request info
28
- in_action_info = SimpleApm::Action.update_by_request info
29
- SimpleApm::Hit.update_by_request info
30
- if in_action_info || in_slow
31
- SimpleApm::Request.create info
32
- else
33
- SimpleApm::Sql.delete_by_request_id(request_id)
7
+ begin
8
+ request_id = Thread.current['action_dispatch.request_id']
9
+ need_skip = payload[:controller] == 'SimpleApm::ApmController'
10
+ if request_id.present?
11
+ if need_skip
12
+ SimpleApm::Sql.delete_by_request_id(request_id)
13
+ else
14
+ action_name = "#{payload[:controller]}##{payload[:action]}" #payload[:format]
15
+ info = {
16
+ request_id: request_id,
17
+ action_name: action_name,
18
+ during: finished - started,
19
+ started: started.to_s,
20
+ db_runtime: payload[:db_runtime].to_f / 1000,
21
+ view_runtime: payload[:view_runtime].to_f / 1000,
22
+ controller: payload[:controller],
23
+ action: payload[:action],
24
+ host: Socket.gethostname,
25
+ remote_addr: payload[:headers]['HTTP_X_REAL_IP'],
26
+ method: payload[:method],
27
+ format: payload[:format],
28
+ exception: payload[:exception].presence.to_json
29
+ }.with_indifferent_access
30
+ info[:status] = '500' if payload[:exception]
31
+ # 存储
32
+ in_slow = SimpleApm::SlowRequest.update_by_request info
33
+ in_action_info = SimpleApm::Action.update_by_request info
34
+ SimpleApm::Hit.update_by_request info
35
+ if in_action_info || in_slow
36
+ SimpleApm::Request.create info
37
+ else
38
+ SimpleApm::Sql.delete_by_request_id(request_id)
39
+ end
40
+ end
34
41
  end
42
+ rescue => e
43
+ Logger.new("#{Rails.root}/log/simple_apm.log").info e.backtrace
35
44
  end
36
- rescue => e
37
- Logger.new("#{Rails.root}/log/simple_apm.log").info e.backtrace
38
45
  end
39
46
 
40
47
  ActiveSupport::Notifications.subscribe 'sql.active_record' do |name, started, finished, unique_id, payload|
41
- request_id = Thread.current['action_dispatch.request_id'].presence||Thread.main['action_dispatch.request_id']
42
- if request_id.present?
43
- dev_caller = caller.detect { |c| c.include? Rails.root.to_s }
44
- if dev_caller
45
- c = ::Callsite.parse(dev_caller)
46
- payload.merge!(:line => c.line, :filename => c.filename.to_s.gsub(Rails.root.to_s,''), :method => c.method)
48
+ begin
49
+ request_id = Thread.current['action_dispatch.request_id'].presence || Thread.main['action_dispatch.request_id']
50
+ if request_id.present?
51
+ dev_caller = caller.detect {|c| c.include? Rails.root.to_s}
52
+ if dev_caller
53
+ c = ::Callsite.parse(dev_caller)
54
+ payload.merge!(:line => c.line, :filename => c.filename.to_s.gsub(Rails.root.to_s, ''), :method => c.method)
55
+ end
56
+ # ActiveRecord::Relation::QueryAttribute
57
+ sql_value = payload[:binds].map {|q| [q.name, q.value]}
58
+ info = {
59
+ request_id: request_id,
60
+ name: payload[:name],
61
+ during: finished - started,
62
+ started: started,
63
+ sql: payload[:sql],
64
+ value: sql_value,
65
+ filename: payload[:filename],
66
+ line: payload[:line]
67
+ }.with_indifferent_access
68
+ SimpleApm::Sql.create request_id, info
47
69
  end
48
- # ActiveRecord::Relation::QueryAttribute
49
- sql_value = payload[:binds].map{|q|[q.name, q.value]}
50
- info = {
51
- request_id: request_id,
52
- name: payload[:name],
53
- during: finished - started,
54
- started: started,
55
- sql: payload[:sql],
56
- value: sql_value,
57
- filename: payload[:filename],
58
- line: payload[:line]
59
- }.with_indifferent_access
60
- SimpleApm::Sql.create request_id, info
70
+ rescue => e
71
+ Logger.new("#{Rails.root}/log/simple_apm.log").info e.backtrace
61
72
  end
62
- rescue => e
63
- Logger.new("#{Rails.root}/log/simple_apm.log").info e.backtrace
64
73
  end
65
74
  end
@@ -6,7 +6,7 @@ module SimpleApm
6
6
  class << self
7
7
  def instance
8
8
  @current ||= ::Redis::Namespace.new(
9
- :simple_apm,
9
+ "simple_apm:#{SimpleApm::Setting::APP_NAME}",
10
10
  :redis => ::Redis.new(
11
11
  url: SimpleApm::Setting::REDIS_URL,
12
12
  driver: SimpleApm::Setting::REDIS_DRIVER
@@ -20,6 +20,8 @@ module SimpleApm
20
20
  redis.info.each do |k, v|
21
21
  if k == 'total_system_memory_human'
22
22
  h['系统内存'] = v
23
+ elsif k == 'used_memory_human'
24
+ h['当前内存占用'] = v
23
25
  elsif k == 'used_memory_rss_human'
24
26
  h['当前内存占用(rss)'] = v
25
27
  elsif k == 'used_memory_peak_human'
@@ -8,5 +8,7 @@ module SimpleApm
8
8
  SLOW_ACTIONS_LIMIT = ApmSettings['slow_actions_limit'].presence || 1000
9
9
  # 每个action存最慢的请求量
10
10
  ACTION_SLOW_REQUEST_LIMIT = ApmSettings['action_slow_request_limit'].presence || 100
11
+ # 区分项目显示
12
+ APP_NAME = ApmSettings['app_name'].presence || 'app'
11
13
  end
12
14
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleApm
2
- VERSION = '0.1.7'
2
+ VERSION = '0.1.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: 0.1.7
4
+ version: 0.1.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-06-01 00:00:00.000000000 Z
11
+ date: 2018-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails