simple_apm 1.0.13 → 1.0.14

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
  SHA1:
3
- metadata.gz: ecd24daac047cea581ed0cd225bb608550647c8d
4
- data.tar.gz: f764040b48e07fd37534db07ca32706aa4478045
3
+ metadata.gz: eb5367e4179faa354aa59c16c8bd9f13ef706e8f
4
+ data.tar.gz: f46424a7e5257d7b29821b5b055e4e8068c51f8d
5
5
  SHA512:
6
- metadata.gz: 96975b1996ce11aa43f172b5dcc623fafb97e4cba30e3f0c2699d19cf5654ca7bd52470efe21472f59b8ad424882a2ebbc8f6b484222510949627422e7d87676
7
- data.tar.gz: bfdaf971ad55fe4144b9c5c5f0f37d087f523804b236838fa64d02e5a895a75ef1ddf0f488435f03d54bbc478e3e51390d05cfd58a5816aec99de46d930057a8
6
+ metadata.gz: 0d3f3a4be257b6148bf1baa872f39774166e021a3926333c372cd9122f735e2e0271b24d5d091d6dfd1262306800dcd3b9ebf76d49c17a825884a9be9b4db647
7
+ data.tar.gz: ac480c8f99332d9fe00b3c82bc14d685589633754d96ac4e6703722ab2c8e6d85d3d5e3d60da4cae3fbe1a773ed48be5b3d88c057dcca1b8e443158d8fc8628f
@@ -17,7 +17,7 @@ module SimpleApm
17
17
  respond_to do |format|
18
18
  format.json do
19
19
  @slow_requests = SimpleApm::SlowRequest.list(params[:count] || 200).map do |r|
20
- request = r.request
20
+ request = r.request rescue next
21
21
  [
22
22
  link_to(time_label(request.started), show_path(id: request.request_id)),
23
23
  link_to(request.action_name, action_info_path(action_name: request.action_name)),
@@ -29,7 +29,7 @@ module SimpleApm
29
29
  request.host,
30
30
  request.remote_addr
31
31
  ]
32
- end
32
+ end.compact
33
33
  render json: {data: @slow_requests}
34
34
  end
35
35
  format.html
@@ -24,7 +24,7 @@ module SimpleApm
24
24
  class << self
25
25
 
26
26
  def find(id)
27
- SimpleApm::Request.new JSON.parse(SimpleApm::Redis.hget(key, id))
27
+ SimpleApm::Request.new JSON.parse(SimpleApm::Redis.hget(key, id)) rescue nil
28
28
  end
29
29
 
30
30
  def create(h)
@@ -0,0 +1,32 @@
1
+ module SimpleApm
2
+ class Summary
3
+ @@results = {}
4
+
5
+ def initialize(date)
6
+ @date = date
7
+ end
8
+
9
+ def result
10
+ return @@results[@date] if @@results[@date] && Time.parse(@date) < Date.today
11
+ @@results[@date] = SimpleApm::RedisKey.set_query_date(@date) do
12
+ res = SimpleApm::Hit.day_info(@date)
13
+ actions = SimpleApm::Action.all_names.map{|n|SimpleApm::Action.find(n)}
14
+ most_hits_5 = actions.sort_by{|x|x.click_count.to_i}.reverse.take(5)
15
+ most_hits_5.map! do |action|
16
+ {
17
+ name: action.name,
18
+ avg_time: action.avg_time,
19
+ hits: action.click_count.to_i,
20
+ slow_avg_time: action.slow_requests.sum(&:during)/action.slow_requests.length
21
+ }
22
+ end
23
+ {
24
+ hits: res[:hits],
25
+ avg_time: res[:avg_time],
26
+ actions: most_hits_5
27
+ }
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -26,7 +26,10 @@
26
26
  <th>server</th>
27
27
  </tr>
28
28
  <% @action.slow_requests.each do |slow_request| %>
29
- <% r = slow_request.request %>
29
+ <%
30
+ r = slow_request.request
31
+ next if r.blank?
32
+ %>
30
33
  <tr>
31
34
  <td>
32
35
  <%= sec_str r.during %>
@@ -6,8 +6,8 @@
6
6
  <%= link_to '', data_delete_path(type: ''), class: 'btn' %>
7
7
  <p class="pull-right">
8
8
  <span class="text-danger">删除数据:</span>
9
- <%= link_to '保留进一周数据', data_delete_path(type: 'week'), class: 'btn btn-danger', 'data-confirm' => '确定删除所有一周以前的数据?' %>
10
- <%= link_to '保留进一个月数据', data_delete_path(type: 'month'), class: 'btn btn-danger', 'data-confirm' => '确定删除所有一个月以前的数据?' %>
9
+ <%= link_to '保留一周数据', data_delete_path(type: 'week'), class: 'btn btn-danger', 'data-confirm' => '确定删除所有一周以前的数据?' %>
10
+ <%= link_to '保留一个月数据', data_delete_path(type: 'month'), class: 'btn btn-danger', 'data-confirm' => '确定删除所有一个月以前的数据?' %>
11
11
  </p>
12
12
 
13
13
  <table class="table table-bordered">
@@ -80,6 +80,18 @@ module SimpleApm
80
80
 
81
81
  class RedisKey
82
82
  class << self
83
+ def set_query_date(d = nil)
84
+ if block_given?
85
+ _ = query_date
86
+ Thread.current['apm_query_date'] = d
87
+ res = yield
88
+ Thread.current['apm_query_date'] = _
89
+ res
90
+ else
91
+ Thread.current['apm_query_date'] = d
92
+ end
93
+ end
94
+
83
95
  def query_date=(d = nil)
84
96
  Thread.current['apm_query_date'] = d
85
97
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleApm
2
- VERSION = '1.0.13'
2
+ VERSION = '1.0.14'
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.13
4
+ version: 1.0.14
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-10-15 00:00:00.000000000 Z
11
+ date: 2019-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -91,6 +91,7 @@ files:
91
91
  - app/models/simple_apm/request.rb
92
92
  - app/models/simple_apm/slow_request.rb
93
93
  - app/models/simple_apm/sql.rb
94
+ - app/models/simple_apm/summary.rb
94
95
  - app/views/layouts/simple_apm/application.html.erb
95
96
  - app/views/simple_apm/apm/action_info.html.erb
96
97
  - app/views/simple_apm/apm/actions.html.erb