log_sense 2.3.1 → 2.4.0

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: 43c38b704af22a839fedec504755be79abf4307c1183efe65ee7323984c4d6bc
4
- data.tar.gz: ed1b73c4b9ccc5e6ffcae7682e67124aa82dba1d9fde9ab625764207893a11dd
3
+ metadata.gz: 01b7c715a9aac207ec39985ba5791c307e64784ae1c5c3f5f5a4e0b124a796af
4
+ data.tar.gz: 7f1881b1a621ea2d1b2f3f29052d4a82016d23bcb6c0d702712b249308bbf2cc
5
5
  SHA512:
6
- metadata.gz: 19857e10b0f5b72afdb491245101050a3348e267d6a9409416ab478e72b441ed8b559280f492f1c761753cbfd71abdafd5184f60095c53ca1bc0640a83c22f4a
7
- data.tar.gz: 3f049b2b6756bfe9ef872021f6b34263736b12eb75ec2b06f086387550fbd87efe367ccc4348070cb492f5870b286c626fe6244ab19ea01f74684d301175b32b
6
+ metadata.gz: 0e8ccec75c78ca240320c3be45cf47779879eef0cd7033fee0e623647b29c744794e19e9f4b4f2e444e9b474b90b017ab10b60bea6661f92aaf156923aff839e
7
+ data.tar.gz: b70eb6964f19f0e7272b3953a4df5b124ea95c1d75ea6fd1a33f9ffe0ad04f6ddb2c7e9e177ccd19dded06a94ae159b3333fca9fadb1e85c279b87cccf78717c
data/.gitignore CHANGED
@@ -8,3 +8,6 @@
8
8
  /tmp/
9
9
  node_modules
10
10
  *~
11
+ TAGS
12
+ sample_logs
13
+ ip_locations/dbip-country-lite-*.csv*
data/CHANGELOG.org CHANGED
@@ -2,6 +2,12 @@
2
2
  #+AUTHOR: Adolfo Villafiorita
3
3
  #+STARTUP: showall
4
4
 
5
+ * 2.4.0
6
+
7
+ - Updates log_parser to match changes in log lines introduced from Rails 7
8
+ (or, in other words, fixes a bug which caused log_sense to miss events
9
+ from logs produced by Rails >= 7 applications)
10
+
5
11
  * 2.3.1
6
12
 
7
13
  - Updates geoip db
data/Gemfile.lock CHANGED
@@ -3,8 +3,10 @@ PATH
3
3
  specs:
4
4
  log_sense (2.3.1)
5
5
  browser (~> 6.0.0)
6
+ csv
6
7
  ipaddr (~> 1.2.0)
7
8
  iso_country_codes (~> 0.7.0)
9
+ ostruct
8
10
  sqlite3 (~> 2.6.0)
9
11
  terminal-table (~> 4.0.0)
10
12
 
@@ -18,6 +20,7 @@ GEM
18
20
  bundler-audit (0.9.2)
19
21
  bundler (>= 1.2.0, < 3)
20
22
  thor (~> 1.0)
23
+ csv (3.3.4)
21
24
  date (3.4.1)
22
25
  debug (1.10.0)
23
26
  irb (~> 1.10)
@@ -34,6 +37,7 @@ GEM
34
37
  lint_roller (1.1.0)
35
38
  mini_portile2 (2.8.9)
36
39
  minitest (5.25.5)
40
+ ostruct (0.6.1)
37
41
  parallel (1.27.0)
38
42
  parser (3.3.8.0)
39
43
  ast (~> 2.4.1)
data/README.org CHANGED
@@ -4,8 +4,8 @@
4
4
 
5
5
  * Introduction
6
6
 
7
- LogSense generates reports and statistics from Ruby on Rails and Apache/Nginx
8
- log files.
7
+ LogSense analyzes Apache and Rails log files, generating reports and statistics
8
+ about usage and performace.
9
9
 
10
10
  Main features:
11
11
 
@@ -22,10 +22,11 @@ Main features:
22
22
  self polls and crawlers.
23
23
  - Reports can be generated in HTML, txt, ufw, and SQLite. HTML reports are
24
24
  responsive and come with dark and light theme.
25
+ - It works with Rails' vanilla log format (no need to format the log)
25
26
 
26
27
  LogSense is Written in Ruby, it runs from the command line, it is fast, and it
27
28
  can be installed on any system with a relatively recent version of Ruby. We
28
- use it with Ruby 3.1.4 and 3.3.0.
29
+ started using it with Ruby 3.1.4 and we are now at version 3.4.
29
30
 
30
31
  It is fast. On a ThinkPad P16, a 277M log file is parsed in 15 seconds,
31
32
  processing, that is, about 7740 events per second; a 569M log file is parsed in
@@ -33,6 +33,9 @@ module LogSense
33
33
  duration_views_ms FLOAT,
34
34
  duration_ar_ms FLOAT,
35
35
  allocations INTEGER,
36
+ queries INTEGER,
37
+ cached_queries INTEGER,
38
+ gc_duration INTEGER,
36
39
  comment TEXT,
37
40
  source_file TEXT,
38
41
  line_number INTEGER
@@ -180,9 +183,16 @@ module LogSense
180
183
  # LOG_LEVEL, [ZULU_TIMESTAMP #NUMBER] INFO --: [ID] Processing by CONTROLLER as FORMAT
181
184
  # LOG_LEVEL, [ZULU_TIMESTAMP #NUMBER] INFO --: [ID] Parameters: JSON
182
185
  # LOG_LEVEL, [ZULU_TIMESTAMP #NUMBER] INFO --: [ID] Rendered VIEW within LAYOUT (Duration: DURATION | Allocations: ALLOCATIONS)
186
+ #
187
+ # For rails_6:
188
+ #
183
189
  # LOG_LEVEL, [ZULU_TIMESTAMP #NUMBER] INFO --: [ID] Completed STATUS STATUS_STRING in DURATION (Views: DURATION | ActiveRecord: DURATION | Allocations: NUMBER)
184
190
  #
185
- # and they appears in the order shown above: started, processing, ...
191
+ # For rails_7:
192
+ #
193
+ # LOG_LEVEL, [ZULU_TIMESTAMP #NUMBER] INFO --: [ID] Completed STATUS STATUS_STRING in DURATION (Views: DURATION | ActiveRecord: DURATION (N queries, M cached) | GC: DURATION)
194
+ #
195
+ # and they appear in the order shown above: started, processing, ...
186
196
  #
187
197
  # Different requests might be interleaved, of course
188
198
  #
@@ -434,6 +444,7 @@ module LogSense
434
444
  STATUS = '(?<status>[0-9]+)'
435
445
  STATUS_IN_WORDS = '(OK|Unauthorized|Found|Internal Server Error|Bad Request|Method Not Allowed|Request Timeout|Not Implemented|Bad Gateway|Service Unavailable)'
436
446
  MSECS = '[0-9.]+'
447
+ INT = '[0-9]+'
437
448
 
438
449
  # I, [2021-10-19T08:16:34.343858 #10477] INFO -- : [67103c0d-455d-4fe8-951e-87e97628cb66] Started GET "/grow/people/471" for 217.77.80.35 at 2021-10-19 08:16:34 +0000
439
450
  STARTED_REGEXP = /I, \[#{TIMESTAMP} #[0-9]+\] INFO -- : \[#{LOG_ID}\] Started #{VERB} "#{URL}" for #{IP} at/o
@@ -455,7 +466,21 @@ module LogSense
455
466
  # I, [2021-10-19T08:16:34.712331 #10477] INFO -- : [67103c0d-455d-4fe8-951e-87e97628cb66] Completed 200 OK in 367ms (Views: 216.7ms | ActiveRecord: 141.3ms | Allocations: 168792)
456
467
  # I, [2021-12-09T16:53:52.657727 #2735058] INFO -- : [0064e403-9eb2-439d-8fe1-a334c86f5532] Completed 200 OK in 13ms (Views: 11.1ms | ActiveRecord: 1.2ms)
457
468
  # I, [2021-12-06T14:28:19.736545 #2804090] INFO -- : [34091cb5-3e7b-4042-aaf8-6c6510d3f14c] Completed 500 Internal Server Error in 66ms (ActiveRecord: 8.0ms | Allocations: 24885)
458
- COMPLETED_REGEXP = /I, \[#{TIMESTAMP} #[0-9]+\] INFO -- : \[#{LOG_ID}\] Completed #{STATUS} #{STATUS_IN_WORDS} in (?<total>#{MSECS})ms \((Views: (?<views>#{MSECS})ms \| )?ActiveRecord: (?<arec>#{MSECS})ms( \| Allocations: (?<alloc>[0-9]+))?\)/o
469
+
470
+ # REGEXP Fragments
471
+
472
+ # views is optional
473
+ # In strings I need to properly escape \ or it will be mis-interpreted
474
+ VIEWS = "(Views: (?<views>#{MSECS})ms \\| )?"
475
+ # active records has two formats (according to Rails version)
476
+ ACTIVE_RECORDS_BASE = "ActiveRecord: (?<arec>#{MSECS})ms"
477
+ ACTIVE_RECORDS_QUERIES = "( \\((?<queries>#{INT}) queries, (?<cached_queries>#{INT}) cached\\))?"
478
+ ACTIVE_RECORDS = "#{ACTIVE_RECORDS_BASE}#{ACTIVE_RECORDS_QUERIES}"
479
+ # older rails versions have ALLOCATIONS, newer have GC
480
+ ALLOCATIONS = " \\| Allocations: (?<alloc>#{INT})"
481
+ GC = " \\| GC: (?<gc_duration>#{MSECS})ms"
482
+
483
+ COMPLETED_REGEXP = /I, \[#{TIMESTAMP} #[0-9]+\] INFO -- : \[#{LOG_ID}\] Completed #{STATUS} #{STATUS_IN_WORDS} in (?<total>#{MSECS})ms \(#{VIEWS}#{ACTIVE_RECORDS}(#{ALLOCATIONS}|#{GC})?\)/o
459
484
 
460
485
  def match_and_process_completed(line)
461
486
  matchdata = (COMPLETED_REGEXP.match line)
@@ -469,7 +494,10 @@ module LogSense
469
494
  duration_total_ms: matchdata[:total],
470
495
  duration_views_ms: matchdata[:views],
471
496
  duration_ar_ms: matchdata[:arec],
472
- allocations: matchdata[:alloc],
497
+ allocations: (matchdata[:alloc] || -1),
498
+ queries: (matchdata[:queries] || -1),
499
+ cached_queries: (matchdata[:cached_queries] || -1),
500
+ gc_duration: (matchdata[:gc_duration] || -1),
473
501
  comment: ""
474
502
  }
475
503
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LogSense
4
- VERSION = "2.3.1"
4
+ VERSION = "2.4.0"
5
5
  end
data/log_sense.gemspec CHANGED
@@ -6,8 +6,18 @@ Gem::Specification.new do |spec|
6
6
  spec.authors = ["Adolfo Villafiorita"]
7
7
  spec.email = ["adolfo@shair.tech"]
8
8
 
9
- spec.summary = %q{Generate analytics for Rails and Apache/Nginx log file.}
10
- spec.description = %q{Generate analytics in HTML, txt, and SQLite format for Rails and Apache/Nginx log files.}
9
+ spec.summary = %q{Analyze Rails and Apache/Nginx log file, generating statistics and reports.}
10
+ spec.description = %q{log_sense is a command-line command which analyzes Rails and Nginx logs and
11
+ provides detailed data about accesses, performances, and errors. It is a
12
+ one stop shop solution for analyzing your Rails application in production.
13
+
14
+ Simple to use and working offline, it does not require any modification to
15
+ your app (e.g., no need to change the log format, no cookies, no JavaScript
16
+ code, no infrastructure to setup).
17
+
18
+ We use it to monitor our applications in production, using a cron job which
19
+ pulls the logs and calls log_sense to generate HTML reports.
20
+ }
11
21
  spec.homepage = "https://github.com/shair-tech/log_sense/"
12
22
  spec.license = "MIT"
13
23
  spec.required_ruby_version = Gem::Requirement.new(">= 2.6.9")
@@ -26,7 +36,9 @@ Gem::Specification.new do |spec|
26
36
  spec.bindir = "exe"
27
37
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
38
  spec.require_paths = ["lib"]
29
-
39
+
40
+ spec.add_dependency "ostruct"
41
+ spec.add_dependency "csv"
30
42
  spec.add_dependency "browser", "~> 6.0.0"
31
43
  spec.add_dependency "ipaddr", "~> 1.2.0"
32
44
  spec.add_dependency "iso_country_codes", "~> 0.7.0"
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.3.1
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adolfo Villafiorita
@@ -9,6 +9,34 @@ bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: ostruct
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: csv
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
12
40
  - !ruby/object:Gem::Dependency
13
41
  name: browser
14
42
  requirement: !ruby/object:Gem::Requirement
@@ -135,8 +163,14 @@ dependencies:
135
163
  - - ">="
136
164
  - !ruby/object:Gem::Version
137
165
  version: '0'
138
- description: Generate analytics in HTML, txt, and SQLite format for Rails and Apache/Nginx
139
- log files.
166
+ description: "log_sense is a command-line command which analyzes Rails and Nginx logs
167
+ and\n provides detailed data about accesses, performances, and errors. It is
168
+ a\n one stop shop solution for analyzing your Rails application in production.\n\n
169
+ \ Simple to use and working offline, it does not require any modification to\n
170
+ \ your app (e.g., no need to change the log format, no cookies, no JavaScript\n
171
+ \ code, no infrastructure to setup).\n\n We use it to monitor our applications
172
+ in production, using a cron job which\n pulls the logs and calls log_sense to
173
+ generate HTML reports.\n "
140
174
  email:
141
175
  - adolfo@shair.tech
142
176
  executables:
@@ -218,5 +252,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
218
252
  requirements: []
219
253
  rubygems_version: 3.6.7
220
254
  specification_version: 4
221
- summary: Generate analytics for Rails and Apache/Nginx log file.
255
+ summary: Analyze Rails and Apache/Nginx log file, generating statistics and reports.
222
256
  test_files: []