log_sense 2.4.0 → 2.5.1

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: 01b7c715a9aac207ec39985ba5791c307e64784ae1c5c3f5f5a4e0b124a796af
4
- data.tar.gz: 7f1881b1a621ea2d1b2f3f29052d4a82016d23bcb6c0d702712b249308bbf2cc
3
+ metadata.gz: 8f8391c34a76ec3e73970663c4636b30b357a0393b37d226cf11b28cf280e690
4
+ data.tar.gz: edf38e10347cee43dd31ca77bc4631da40c3dd1504949eba04806533914ee048
5
5
  SHA512:
6
- metadata.gz: 0e8ccec75c78ca240320c3be45cf47779879eef0cd7033fee0e623647b29c744794e19e9f4b4f2e444e9b474b90b017ab10b60bea6661f92aaf156923aff839e
7
- data.tar.gz: b70eb6964f19f0e7272b3953a4df5b124ea95c1d75ea6fd1a33f9ffe0ad04f6ddb2c7e9e177ccd19dded06a94ae159b3333fca9fadb1e85c279b87cccf78717c
6
+ metadata.gz: d54dd1a3014112cb2065d359e8309821321af2aa8dfd60effccf36f03735c796035be41e66f9a52f16809ea9fb3e0a179d70c7952554714b799cc74b18604ca1
7
+ data.tar.gz: e499045dbe77afb688b56ba01108a6d9bcbb2033c59df0c568d12c5807218f8f62579cdebc7fe35356271c51f8b86ba8aad7b72084025ec5ac6969d2b8afcf15
data/CHANGELOG.org CHANGED
@@ -2,6 +2,14 @@
2
2
  #+AUTHOR: Adolfo Villafiorita
3
3
  #+STARTUP: showall
4
4
 
5
+ * 2.5.1
6
+
7
+ - Add number of events in SQL queries
8
+
9
+ * 2.5.0
10
+
11
+ - Add query reports
12
+
5
13
  * 2.4.0
6
14
 
7
15
  - Updates log_parser to match changes in log lines introduced from Rails 7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- log_sense (2.3.1)
4
+ log_sense (2.5.1)
5
5
  browser (~> 6.0.0)
6
6
  csv
7
7
  ipaddr (~> 1.2.0)
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LogSense
4
+ module FormattingUtil
5
+ ##
6
+ # Number with thousand separator
7
+ #
8
+ def self.with_thousands(number, separator: ",", comma: ".")
9
+ return unless number
10
+
11
+ decimal, fraction = number.to_s.split(comma)
12
+ with_thousands = decimal.reverse.gsub(/(\d\d\d)/, "\\1#{separator}")
13
+
14
+ "#{with_thousands.reverse}#{comma if fraction}#{fraction}"
15
+ end
16
+ end
17
+ end
@@ -16,53 +16,43 @@ module LogSense
16
16
  def parse(streams, options = {})
17
17
  db = SQLite3::Database.new ":memory:"
18
18
 
19
+ event_table = {
20
+ exit_status: "TEXT",
21
+ started_at: "TEXT",
22
+ ended_at: "TEXT",
23
+ log_id: "TEXT",
24
+ ip: "TEXT",
25
+ unique_visitor: "TEXT",
26
+ url: "TEXT",
27
+ controller: "TEXT",
28
+ html_verb: "TEXT",
29
+ status: "INTEGER",
30
+ duration_total_ms: "FLOAT",
31
+ duration_views_ms: "FLOAT",
32
+ duration_ar_ms: "FLOAT",
33
+ allocations: "INTEGER",
34
+ queries: "INTEGER",
35
+ cached_queries: "INTEGER",
36
+ gc_duration: "FLOAT",
37
+ comment: "TEXT",
38
+ source_file: "TEXT",
39
+ line_number: "INTEGER"
40
+ }
41
+
42
+ table_declaration = event_table.map { |k, v| "#{k} #{v}" }.join(",")
19
43
  db.execute <<-EOS
20
- CREATE TABLE IF NOT EXISTS Event(
21
- id INTEGER PRIMARY KEY AUTOINCREMENT,
22
- exit_status TEXT,
23
- started_at TEXT,
24
- ended_at TEXT,
25
- log_id TEXT,
26
- ip TEXT,
27
- unique_visitor TEXT,
28
- url TEXT,
29
- controller TEXT,
30
- html_verb TEXT,
31
- status INTEGER,
32
- duration_total_ms FLOAT,
33
- duration_views_ms FLOAT,
34
- duration_ar_ms FLOAT,
35
- allocations INTEGER,
36
- queries INTEGER,
37
- cached_queries INTEGER,
38
- gc_duration INTEGER,
39
- comment TEXT,
40
- source_file TEXT,
41
- line_number INTEGER
42
- )
44
+ CREATE TABLE IF NOT EXISTS Event(
45
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
46
+ #{table_declaration}
47
+ )
43
48
  EOS
44
49
 
50
+ tds = event_table.keys.size
45
51
  ins = db.prepare <<-EOS
46
- insert into Event(
47
- exit_status,
48
- started_at,
49
- ended_at,
50
- log_id,
51
- ip,
52
- unique_visitor,
53
- url,
54
- controller,
55
- html_verb,
56
- status,
57
- duration_total_ms,
58
- duration_views_ms,
59
- duration_ar_ms,
60
- allocations,
61
- comment,
62
- source_file,
63
- line_number
52
+ insert into Event(
53
+ #{event_table.keys.join(", ")}
64
54
  )
65
- values (#{Array.new(17, "?").join(", ")})
55
+ values (#{Array.new(tds, "?").join(", ")})
66
56
  EOS
67
57
 
68
58
  db.execute <<-EOS
@@ -254,6 +244,9 @@ module LogSense
254
244
  event[:duration_views_ms],
255
245
  event[:duration_ar_ms],
256
246
  event[:allocations],
247
+ event[:queries],
248
+ event[:cached_queries],
249
+ event[:gc_duration],
257
250
  event[:comment],
258
251
  filename,
259
252
  line_number
@@ -290,6 +283,9 @@ module LogSense
290
283
  event[:duration_views_ms],
291
284
  event[:duration_ar_ms],
292
285
  event[:allocations],
286
+ event[:queries],
287
+ event[:cached_queries],
288
+ event[:gc_duration],
293
289
  event[:comment],
294
290
  filename,
295
291
  line_number
@@ -494,10 +490,10 @@ module LogSense
494
490
  duration_total_ms: matchdata[:total],
495
491
  duration_views_ms: matchdata[:views],
496
492
  duration_ar_ms: matchdata[:arec],
497
- allocations: (matchdata[:alloc] || -1),
498
- queries: (matchdata[:queries] || -1),
499
- cached_queries: (matchdata[:cached_queries] || -1),
500
- gc_duration: (matchdata[:gc_duration] || -1),
493
+ allocations: matchdata[:alloc],
494
+ queries: matchdata[:queries],
495
+ cached_queries: matchdata[:cached_queries],
496
+ gc_duration: matchdata[:gc_duration],
501
497
  comment: ""
502
498
  }
503
499
  end
@@ -5,6 +5,9 @@ module LogSense
5
5
  class RailsAggregator < Aggregator
6
6
  WORDS_SEPARATOR = ' · '
7
7
 
8
+ # with thousands
9
+ include LogSense::FormattingUtil
10
+
8
11
  def initialize(db, options = { limit: 900 })
9
12
  @table = "Event"
10
13
  @date_field = "started_at"
@@ -81,6 +84,30 @@ module LogSense
81
84
  }
82
85
  end
83
86
 
87
+ queries = @db.execute %Q(
88
+ SELECT SUM(DISTINCT(id)), SUM(queries), SUM(cached_queries),
89
+ ROUND(1.0 * SUM(cached_queries) / SUM(queries), 2)
90
+ FROM Event
91
+ )
92
+
93
+ @queries = queries.map do |row|
94
+ row.map do |element|
95
+ FormattingUtil.with_thousands(element)
96
+ end
97
+ end
98
+
99
+ @queries_by_controller = @db.execute %Q(
100
+ SELECT controller,
101
+ COUNT(DISTINCT(id)),
102
+ MIN(queries), MAX(queries),
103
+ ROUND(AVG(queries), 2),
104
+ SUM(queries), SUM(cached_queries),
105
+ ROUND(1.0 * SUM(cached_queries) / SUM(queries), 2),
106
+ ROUND(SUM(gc_duration), 2)
107
+ FROM Event
108
+ GROUP BY Event.controller
109
+ )
110
+
84
111
  @controller_and_methods_by_device = @db.execute %Q(
85
112
  SELECT controller as Controller,
86
113
  method as Method,
@@ -125,7 +152,7 @@ module LogSense
125
152
  ON event.log_id == error.log_id
126
153
  WHERE #{filter} and exit_status == 'S:FAILED'
127
154
  GROUP BY strftime("%Y-%m-%d", started_at)
128
- ).gsub("\n", "") || [[]]
155
+ ) || [[]]
129
156
 
130
157
  @fatal = @db.execute %(
131
158
  SELECT strftime("%Y-%m-%d %H:%M", started_at),
@@ -137,7 +164,7 @@ module LogSense
137
164
  FROM Event JOIN Error
138
165
  ON event.log_id == error.log_id
139
166
  WHERE #{filter} and exit_status == 'S:FAILED'
140
- ).gsub("\n", "") || [[]]
167
+ ) || [[]]
141
168
 
142
169
  @fatal_grouped = @db.execute %(
143
170
  SELECT filename,
@@ -147,7 +174,7 @@ module LogSense
147
174
  count(distinct(error.id))
148
175
  FROM Error
149
176
  GROUP BY description
150
- ).gsub("\n", "") || [[]]
177
+ ) || [[]]
151
178
 
152
179
  @job_plot = @db.execute %(
153
180
  SELECT strftime("%Y-%m-%d", ended_at) as Day,
@@ -156,7 +183,7 @@ module LogSense
156
183
  FROM Job
157
184
  WHERE #{filter}
158
185
  GROUP BY strftime("%Y-%m-%d", ended_at)
159
- ).gsub("\n", "") || [[]]
186
+ ) || [[]]
160
187
 
161
188
  # worker,
162
189
  # host,
@@ -173,7 +200,7 @@ module LogSense
173
200
  attempt
174
201
  FROM Job
175
202
  WHERE #{filter}
176
- ).gsub("\n", "") || [[]]
203
+ ) || [[]]
177
204
 
178
205
  @job_error_grouped = @db.execute %(
179
206
  SELECT worker,
@@ -188,7 +215,7 @@ module LogSense
188
215
  FROM Job
189
216
  WHERE #{filter} and (exit_status == 'S:ERROR' or exit_status == 'S:FAILED')
190
217
  GROUP BY object_id
191
- ).gsub("\n", "") || [[]]
218
+ ) || [[]]
192
219
 
193
220
  instance_vars_to_hash
194
221
  end
@@ -46,6 +46,8 @@ module LogSense
46
46
  total_statuses(data),
47
47
  daily_statuses(data),
48
48
  performance_over_time(data, col: "small-12 cell"),
49
+ queries(data),
50
+ queries_by_controller(data),
49
51
  {
50
52
  title: "Rails Performance",
51
53
  header: %w[Controller Hits Min Avg Max],
@@ -136,6 +136,30 @@ module LogSense
136
136
  }
137
137
  end
138
138
 
139
+ def queries(data, colors: [], col: "small-12 cell")
140
+ {
141
+ title: "Number of queries",
142
+ header: %w[Queries Total Cached Perc_Cached],
143
+ column_alignment: %i[center center center center],
144
+ rows: data[:queries],
145
+ col: col,
146
+ }
147
+ end
148
+
149
+ def queries_by_controller(data, colors: [], col: "small-12 cell")
150
+ {
151
+ title: "Queries by Controller",
152
+ header: ["Controller",
153
+ "Events",
154
+ "Min queries", "Max queries", "Avg Queries",
155
+ "Total queries", "Cached queries", "Perc",
156
+ "Total GC"],
157
+ column_alignment: %i[left right right right right right right right],
158
+ rows: data[:queries_by_controller],
159
+ col: col,
160
+ }
161
+ end
162
+
139
163
  #
140
164
  # Reports shared between rails and apache/nginx
141
165
  #
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LogSense
4
- VERSION = "2.4.0"
4
+ VERSION = "2.5.1"
5
5
  end
data/lib/log_sense.rb CHANGED
@@ -6,6 +6,7 @@ require "log_sense/options/checker"
6
6
  require "log_sense/apache/log_parser"
7
7
  require "log_sense/rails/log_parser"
8
8
 
9
+ require "log_sense/formatting_util"
9
10
  require "log_sense/aggregator"
10
11
  require "log_sense/apache_aggregator"
11
12
  require "log_sense/rails_aggregator"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log_sense
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adolfo Villafiorita
@@ -196,6 +196,7 @@ files:
196
196
  - lib/log_sense/apache_aggregator.rb
197
197
  - lib/log_sense/apache_report_shaper.rb
198
198
  - lib/log_sense/emitter.rb
199
+ - lib/log_sense/formatting_util.rb
199
200
  - lib/log_sense/ip_locator.rb
200
201
  - lib/log_sense/options/checker.rb
201
202
  - lib/log_sense/options/parser.rb