log_stats 0.4.8 → 0.4.9

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: 0fa3ba2ad1add0dd1d2afad2eaddd30170d91706
4
- data.tar.gz: 26bd2de0d76a031cd95714c52380d89747748be6
3
+ metadata.gz: 1e0ad41ee5b5d35c23a2669ac48946e99dc4f471
4
+ data.tar.gz: 2bd2d252fc83f5737ed95e270eb3d9133ce2c4bc
5
5
  SHA512:
6
- metadata.gz: e665bbab7dd4c3efa3bbbb6d589737b4bf635e3c4086e9982e9dd82a7ed3e958117dfe1ea8348816d48f868af363400514fac7e280725e5a5c0e85bb062b70b0
7
- data.tar.gz: 5784984b37e09e99c5506349f34c134c600924df70e07bc7d48a4b4ab0cd559eb1667e20e6a36d461e5175580dd286d7eb76ecd8432744d01362db5b45bd1bfe
6
+ metadata.gz: 6943a1e81fa11ef62d27c8a95f1c7d4b87e680913e8686dd4d6c862fe28ca45969c13f28278520798de06ce4c56e3067f1edd0f014d41bcf6c9e23def4621218
7
+ data.tar.gz: 1e4bc92ba0ae07c32a258f205923bd264ae628014908e64974fa4dcdb075215ff671363c1b0d8261baf6c3aeeed1bff12f777f81fba734b86457a555bd4b6639
@@ -5,4 +5,5 @@ require "log_stats/config"
5
5
 
6
6
  log_file_data = ARGF.readlines
7
7
  config = LogStats::Config.default_config.merge(LogStats::Config.env_config)
8
- LogStats.run(log_file_data, config)
8
+ stats = LogStats.get_stats(log_file_data, config)
9
+ puts JSON.pretty_generate(stats)
@@ -101,7 +101,7 @@ stats_path = File.join(dir_path, 'stats.json')
101
101
  if File.exists?(events_path)
102
102
  # NOTE: it's faster to read cached JSON events data than processing the log file
103
103
  events = LogStats::Logger.elapsed(config, "Reading and parsing #{events_path}") do
104
- JSON.parse(IO.read(events_path))
104
+ JSON.parse(IO.read(events_path), symbolize_names: true)
105
105
  end
106
106
  else
107
107
  log_file_data = LogStats::Logger.elapsed(config, "Reading log file #{file_path}") do
@@ -10,17 +10,6 @@ require "log_stats/requests/text_output"
10
10
  require "time"
11
11
 
12
12
  module LogStats
13
- def self.run(log_data, config)
14
- stats = get_stats(log_data, config)
15
- if config[:output_format] == "text" && request_config = config[:events][:requests]
16
- Requests::TextOutput.print(stats[:requests], request_config)
17
- end
18
- if config[:output_format] == "json"
19
- puts JSON.pretty_generate(stats)
20
- end
21
- stats
22
- end
23
-
24
13
  def self.get_stats(log_data, config)
25
14
  events = get_events(log_data, config)
26
15
  process_events(events, config)
@@ -1,3 +1,3 @@
1
1
  module LogStats
2
- VERSION = "0.4.8"
2
+ VERSION = "0.4.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log_stats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Marklund
@@ -75,7 +75,6 @@ files:
75
75
  - lib/log_stats/logger.rb
76
76
  - lib/log_stats/requests/kpi.rb
77
77
  - lib/log_stats/requests/stats.rb
78
- - lib/log_stats/requests/text_output.rb
79
78
  - lib/log_stats/stats.rb
80
79
  - lib/log_stats/version.rb
81
80
  - log_stats.gemspec
@@ -1,87 +0,0 @@
1
- module LogStats
2
- module Requests
3
- module TextOutput
4
- def self.print(data, event_config)
5
- print_heading("KPIs")
6
- print_kpi(data[:kpi])
7
-
8
- print_heading("STATUS CODES")
9
- print_percentages(data[:requests_count], data[:requests_by_status])
10
-
11
- print_heading("HEROKU ERROR CODES")
12
- print_percentages(data[:requests_count], data[:requests_by_code])
13
-
14
- top_list_options = {
15
- direction: 1,
16
- limit: event_config[:top_list_limit],
17
- apdex_goal: event_config[:apdex_goal]
18
- }
19
-
20
- print_heading("POPULARITY TOP LIST")
21
- print_top_list(data[:stats], Stats.method(:popularity_metric), top_list_options)
22
-
23
- print_heading("APDEX TOP LIST")
24
- print_top_list(data[:stats], Stats.method(:apdex_metric), top_list_options.merge(direction: -1))
25
-
26
- print_heading("DURATION TOP LIST")
27
- print_top_list(data[:stats], Stats.method(:duration_metric), top_list_options)
28
-
29
- print_heading("ERROR RATE TOP LIST")
30
- print_top_list(data[:stats], Stats.method(:error_rate_metric), top_list_options)
31
-
32
- print_heading("TIMEOUT TOP LIST")
33
- print_top_list(data[:stats], Stats.method(:timeout_metric), top_list_options)
34
-
35
- data[:requests_by_status].each do |status, requests|
36
- print_heading("REQUESTS - STATUS #{status}")
37
- Stats.requests_by_duration(requests).each do |request|
38
- print_request(request)
39
- end
40
- end
41
- end
42
-
43
- def self.print_request(request)
44
- parts = [(request[:method] == "GET" ? nil : request[:method]),
45
- request[:path],
46
- request[:service],
47
- request[:code]
48
- ].compact
49
- if parts.size > 1
50
- puts parts.join(" ")
51
- end
52
- end
53
-
54
- def self.print_percentages(total_lines_count, grouped_lines)
55
- grouped_lines.select { |key, _| !key.nil? }.each do |key, lines|
56
- percent = (lines.size.to_f*100/total_lines_count).round(4)
57
- puts "#{key} #{percent}%"
58
- end
59
- end
60
-
61
- def self.print_top_list(stats, metric, options = {})
62
- Stats.stats_by_metric(stats, metric, options[:direction])[0, options[:limit]].each do |stat|
63
- apdex = Stats.apdex_metric(stat).round(2)
64
- puts [stat[:id],
65
- metric.call(stat),
66
- "count=#{stat[:count]}",
67
- "apdex=#{apdex}",
68
- (apdex >= options[:apdex_goal] ? "OK" : "SLOW")
69
- ].join(' ')
70
- end
71
- end
72
-
73
- def self.print_heading(heading)
74
- puts "\n-----------------------------------------------------------"
75
- puts heading
76
- puts "-----------------------------------------------------------\n\n"
77
- end
78
-
79
-
80
- def self.print_kpi(kpi)
81
- kpi.each do |key, value|
82
- puts "#{key}: #{value}"
83
- end
84
- end
85
- end
86
- end
87
- end