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 +4 -4
- data/app/controllers/simple_apm/apm_controller.rb +2 -2
- data/app/models/simple_apm/request.rb +1 -1
- data/app/models/simple_apm/summary.rb +32 -0
- data/app/views/simple_apm/apm/action_info.html.erb +4 -1
- data/app/views/simple_apm/apm/data.html.erb +2 -2
- data/lib/simple_apm/redis.rb +12 -0
- data/lib/simple_apm/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb5367e4179faa354aa59c16c8bd9f13ef706e8f
|
4
|
+
data.tar.gz: f46424a7e5257d7b29821b5b055e4e8068c51f8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
@@ -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
|
@@ -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 '
|
10
|
-
<%= link_to '
|
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">
|
data/lib/simple_apm/redis.rb
CHANGED
@@ -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
|
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: 1.0.
|
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:
|
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
|