simple_apm 1.0.2 → 1.0.3

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: fef3d86f5fe835b90243b01bc335aabbc20bbfd1d581eab08e71b851790be92a
4
- data.tar.gz: 353ee2dab5eba98f1e3bbbb4bcc5c01f17bd0a049484c5dcc9c5aece426c83dc
3
+ metadata.gz: c9c10a4595dc4a7edaaea7749ff4b55e0cc81f9eed50fe50aa9682d1c196efb9
4
+ data.tar.gz: 180fa1647b8dec347d607ba8f3088b1323f7dc4ba01fbeb4d882cf09c1472dfa
5
5
  SHA512:
6
- metadata.gz: 3a5110cfae48bf65c15cbe89ed8906c67d6ca3452f1a97ebf567b72087555626dac2d8c4d643fcdb4be4c22e44ad63e357378258f9efe98a1ed1f6c4931ada36
7
- data.tar.gz: 8b6b5ac0420c57abb6e557dd1fb02690e4f4f947445fe76ad9e903df6da0b0694e09e9547e4594a8b8c0010372ec8eea84c0043f71710cda3dd54b73f0470fa1
6
+ metadata.gz: 35dfd32b5ff9456ab58e847d9193cebbe3d0e5ccaf0280af8dcbad4d42063f74d647376482da2306e9b705e4e073e5a76d83050d75adfdc5cb430b63ec348625
7
+ data.tar.gz: 524e2ed5481223458a1b238ceaf7b4e2d56e82e419362109559eca624e7cb0a1550312b0b40e4e5ed1f45c46a326866e4ca3839f21939a5c6932abdf530d41df
@@ -4,7 +4,7 @@ module SimpleApm
4
4
  attr_accessor :request_id, :action_name,
5
5
  :during, :started, :db_runtime, :view_runtime,
6
6
  :controller, :action, :format, :method,
7
- :host, :remote_addr,
7
+ :host, :remote_addr, :url,
8
8
  :exception, :status
9
9
  def initialize(h)
10
10
  h.each do |k, v|
@@ -1,4 +1,8 @@
1
1
  <h4><%= @request.action_name %>.<%= @request.format %>(<%= @request.method %>)</h4>
2
+ <p>
3
+ <label>URL:</label>
4
+ <span><%= @request.url %></span>
5
+ </p>
2
6
  <p>
3
7
  <label>开始时间:</label>
4
8
  <span><%= time_label @request.started, true %></span>
data/config/routes.rb CHANGED
@@ -7,5 +7,5 @@ SimpleApm::Engine.routes.draw do
7
7
  get 'data', to: 'apm#data'
8
8
  get 'data_delete', to: 'apm#data_delete'
9
9
  get 'set_apm_date', to: 'apm#set_apm_date'
10
-
10
+ root 'apm#dashboard'
11
11
  end
@@ -8,4 +8,6 @@ slow_actions_limit:
8
8
  # 记录每天的每个Action最慢的N个请求,默认20
9
9
  action_slow_request_limit:
10
10
  # 项目名,默认为 'app',区分项目名可以多个项目数据存于一台redis server上
11
- app_name:
11
+ app_name:
12
+ # 记录SQL的最低时间(单位:秒),小于指定数值的则不记录
13
+ sql_critical_time:
@@ -57,8 +57,10 @@ module SimpleApm
57
57
 
58
58
  def running?
59
59
  hget('status','running').to_s != 'false'
60
+ rescue
61
+ false
60
62
  end
61
-
63
+
62
64
  def rerun!
63
65
  hset('status', 'running', true)
64
66
  end
@@ -10,5 +10,7 @@ module SimpleApm
10
10
  ACTION_SLOW_REQUEST_LIMIT = ApmSettings['action_slow_request_limit'].presence || 20
11
11
  # 区分项目显示
12
12
  APP_NAME = ApmSettings['app_name'].presence || 'app'
13
+ # SQL临界值
14
+ SQL_CRITICAL_TIME = ApmSettings['sql_critical_time'].to_f
13
15
  end
14
16
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleApm
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
3
3
  end
data/lib/simple_apm.rb CHANGED
@@ -3,8 +3,11 @@ require "simple_apm/redis"
3
3
  require "simple_apm/engine"
4
4
  require 'callsite'
5
5
  module SimpleApm
6
+ # RUBY_PLATFORM darwin linux win32
7
+ # ps aux | grep -w 30057 | awk '$2==30057 {print $6}'
6
8
  ActiveSupport::Notifications.subscribe('process_action.action_controller') do |name, started, finished, unique_id, payload|
7
9
  begin
10
+ SimpleApm::RedisKey.query_date = nil
8
11
  request_id = Thread.current['action_dispatch.request_id']
9
12
  need_skip = payload[:controller] == 'SimpleApm::ApmController'
10
13
  need_skip = true if payload[:status].to_s=='302' && payload[:path].to_s=~/login/ && payload[:method].to_s.downcase=='get'
@@ -16,6 +19,7 @@ module SimpleApm
16
19
  info = {
17
20
  request_id: request_id,
18
21
  action_name: action_name,
22
+ url: payload[:path],
19
23
  during: finished - started,
20
24
  started: started.to_s,
21
25
  db_runtime: payload[:db_runtime].to_f / 1000,
@@ -47,8 +51,10 @@ module SimpleApm
47
51
 
48
52
  ActiveSupport::Notifications.subscribe 'sql.active_record' do |name, started, finished, unique_id, payload|
49
53
  begin
54
+ SimpleApm::RedisKey.query_date = nil
50
55
  request_id = Thread.current['action_dispatch.request_id'].presence || Thread.main['action_dispatch.request_id']
51
- if request_id.present?
56
+ during = finished - started
57
+ if request_id.present? || during < SimpleApm::Setting::SQL_CRITICAL_TIME
52
58
  dev_caller = caller.detect {|c| c.include? Rails.root.to_s}
53
59
  if dev_caller
54
60
  c = ::Callsite.parse(dev_caller)
@@ -59,7 +65,7 @@ module SimpleApm
59
65
  info = {
60
66
  request_id: request_id,
61
67
  name: payload[:name],
62
- during: finished - started,
68
+ during: during,
63
69
  started: started,
64
70
  sql: payload[:sql],
65
71
  value: sql_value,
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.2
4
+ version: 1.0.3
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-06 00:00:00.000000000 Z
11
+ date: 2018-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails