simple_apm 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/simple_apm.rb +59 -50
- data/lib/simple_apm/redis.rb +3 -1
- data/lib/simple_apm/setting.rb +2 -0
- data/lib/simple_apm/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd96eb80e66cb02f54e84663909f84a974ff4071b2f5d30a9c136fa3c23552b1
|
4
|
+
data.tar.gz: 4b4018dc5da34ade9b345dc58622655d9263603557f1411cf17f8affe20e2725
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bdcd065ce63b5143b915d8f288d23132da6caf4b383cdf938c5baf9347770eb90a252bc185ba70a9ddf66fdf46b3ae10103bb7aa7b9661e2674a978a7bd5813d
|
7
|
+
data.tar.gz: c734c6adf33cfb68ff94c330a1b8dea7a2be74fdee069e8ee9406f86190b23be426dbb1994ac890e391c3b4976bca1b0e320390682ac2c8ac30089a1cbb5ae06
|
data/lib/simple_apm.rb
CHANGED
@@ -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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
49
|
-
|
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
|
data/lib/simple_apm/redis.rb
CHANGED
@@ -6,7 +6,7 @@ module SimpleApm
|
|
6
6
|
class << self
|
7
7
|
def instance
|
8
8
|
@current ||= ::Redis::Namespace.new(
|
9
|
-
|
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'
|
data/lib/simple_apm/setting.rb
CHANGED
@@ -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
|
data/lib/simple_apm/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2018-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|