log_stats 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/example/log_stats +37 -2
- data/lib/log_stats/stats.rb +7 -1
- data/lib/log_stats/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c90b62a342e1c9d31e7c82ca198dc661e56a769f
|
4
|
+
data.tar.gz: e8c0bbf66c8f02989ddd4114b3e5ac74e5a318f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2115ea56f0f4c77a72dca4c9632a6348825d976785dd797a6730061b78c4005618bbc44c776d46805348b2c4293183941168d17deb34a4530cadb35e47b07033
|
7
|
+
data.tar.gz: f33e9fe59dd6128ad36e5a5dd6bb631c94ca3fc3bc2e4f11ae81f603b1580e186b69543684d0b53cffc0964d94b634acf708e375804cb64f7d375b826f486973
|
data/example/log_stats
CHANGED
@@ -11,6 +11,36 @@ require "uri"
|
|
11
11
|
|
12
12
|
parse_time = Proc.new { |line| line[/\b20\d\d-\d\d-\d\dT\d\d:\d\d:\d\d/] }
|
13
13
|
|
14
|
+
def endpoint_pattern(url)
|
15
|
+
Regexp.new('^' + url.gsub(%r{/:id/}, '/[^/]+/').gsub(%r{/:id$}, '/[^/]+') + '$')
|
16
|
+
end
|
17
|
+
|
18
|
+
ENDPOINTS = [
|
19
|
+
'restapi.example.(se|no|dk)/api/user/:id/password',
|
20
|
+
'restapi.example.(se|no|dk)/api/user/:id/password',
|
21
|
+
'restapi.example.(se|no|dk)/api/user/find/(userName|email)/:id',
|
22
|
+
'restapi.example.(se|no|dk)/api/order/extUserId/:id',
|
23
|
+
'restapi.example.(se|no|dk)/api/voucher/.+'
|
24
|
+
].map do |url|
|
25
|
+
{url: url, pattern: endpoint_pattern(url)}
|
26
|
+
end
|
27
|
+
|
28
|
+
def endpoint(api_call)
|
29
|
+
uri = URI(api_call[:url])
|
30
|
+
# NOTE: don't include digits in the path as then we will have too many unique paths
|
31
|
+
path_without_digits = uri.path.gsub(%r{/\d+}, '/:id')
|
32
|
+
url = uri.host + path_without_digits
|
33
|
+
if endpoint = ENDPOINTS.detect { |endpoint| endpoint[:pattern].match(url) }
|
34
|
+
endpoint[:url]
|
35
|
+
else
|
36
|
+
url
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def response_time_95(item)
|
41
|
+
-1 * item[:fields][:response_time][:percentiles][0.95]
|
42
|
+
end
|
43
|
+
|
14
44
|
custom_config = {
|
15
45
|
events: {
|
16
46
|
requests: {
|
@@ -31,7 +61,7 @@ custom_config = {
|
|
31
61
|
stats: false # Skip listing stats per request path to keep output size manageable
|
32
62
|
},
|
33
63
|
api_calls: {
|
34
|
-
# 2017-02-19T06:21:25.522274+00:00 app[worker.2]: [WARN] [Vac::Request] Slow response time for url=http://sumore02.
|
64
|
+
# 2017-02-19T06:21:25.522274+00:00 app[worker.2]: [WARN] [Vac::Request] Slow response time for url=http://sumore02.example.dk/api/search/categories/160145/assets/ method=get status=304 size= response_time=141
|
35
65
|
line_pattern: /\s\[Vac::Request\] Slow response time\s/,
|
36
66
|
fields: [
|
37
67
|
{name: :time, parse: parse_time},
|
@@ -41,7 +71,12 @@ custom_config = {
|
|
41
71
|
],
|
42
72
|
group_by: {
|
43
73
|
hostname: {
|
44
|
-
id: Proc.new { |api_call| URI(api_call[:url]).host }
|
74
|
+
id: Proc.new { |api_call| URI(api_call[:url]).host },
|
75
|
+
sort_by: method(:response_time_95)
|
76
|
+
},
|
77
|
+
endpoint: {
|
78
|
+
id: method(:endpoint),
|
79
|
+
sort_by: method(:response_time_95)
|
45
80
|
}
|
46
81
|
# NOTE: Grouping by HTTP method doesn't really add much at the moment, so commenting out for now
|
47
82
|
# method: {
|
data/lib/log_stats/stats.rb
CHANGED
@@ -46,7 +46,7 @@ module LogStats
|
|
46
46
|
def self.group_by_stats(events, group_by, event_config)
|
47
47
|
total_count = events.size
|
48
48
|
events_by_group = events.group_by { |event| group_by[:id].call(event) }.select { |key, _| !key.nil? }
|
49
|
-
events_by_group.reduce({}) do |acc, (key, group_events)|
|
49
|
+
grouped = events_by_group.reduce({}) do |acc, (key, group_events)|
|
50
50
|
group_count = group_events.size
|
51
51
|
percent = (group_count.to_f*100/total_count).round(4)
|
52
52
|
acc[key] = {
|
@@ -56,6 +56,12 @@ module LogStats
|
|
56
56
|
}
|
57
57
|
acc
|
58
58
|
end
|
59
|
+
keys = if sort_by = group_by[:sort_by]
|
60
|
+
grouped.keys.sort_by { |key| sort_by.call(grouped[key]) }
|
61
|
+
else
|
62
|
+
grouped.keys
|
63
|
+
end
|
64
|
+
keys.map { |key| {key: key, data: grouped[key]} }
|
59
65
|
end
|
60
66
|
|
61
67
|
def self.avg(events, field_name)
|
data/lib/log_stats/version.rb
CHANGED