browser_sense 1.0.1 → 1.1.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 +4 -4
- data/CHANGELOG.org +17 -0
- data/README.org +29 -5
- data/app/controllers/browser_sense_filter.rb +17 -4
- data/app/services/browser_sense_parser.rb +32 -0
- data/browser_sense.gemspec +6 -3
- data/exe/browser_sense +10 -1
- data/lib/browser_sense/version.rb +1 -1
- metadata +19 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e8fa590833475085fe473a90988cb128353267bc7bbcef259b0159a812fcf98c
|
|
4
|
+
data.tar.gz: 4b34a65d1875803994557840fb211e769fe406f63ccbd8b6b81b83f32216e382
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8cf8c94b32d56f262c414adbff5560f23da9a1e5263ff380583d8f81582a4f4fa35c0c198adfddd9633fe4902938fc2920b445c2183dc83df5ad60d61bc702af
|
|
7
|
+
data.tar.gz: 99d3a4e0c8938291aa0155459579dbdf83569dcecbf024d35de61d49ea771ab3105da1255c5698d7e4b6beca4711f28d42c87c699000229bf28a40f3a3fa972c
|
data/CHANGELOG.org
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
#+TITLE: BrowserSense ChangeLog
|
|
2
2
|
|
|
3
|
+
* [1.1.0] - <2025-12-21 Sun>
|
|
4
|
+
|
|
5
|
+
- Store more information. The following fields are now appended to the lines
|
|
6
|
+
generated by BrowserSense:
|
|
7
|
+
|
|
8
|
+
- ip
|
|
9
|
+
- browser.version
|
|
10
|
+
- platform.version,
|
|
11
|
+
- browser.bot?
|
|
12
|
+
- browser.bot&.name
|
|
13
|
+
- browser.bot&.search_engine?
|
|
14
|
+
|
|
15
|
+
- Use CSV to ensure the log line is properly parsable as a CSV string
|
|
16
|
+
- Add the following two methods: =BrowserSenseParser.match?= and
|
|
17
|
+
=BrowserSenseParser.parse=
|
|
18
|
+
|
|
19
|
+
|
|
3
20
|
* [1.0.1] - <2025-09-30 Tue>
|
|
4
21
|
|
|
5
22
|
- Fixes documentation
|
data/README.org
CHANGED
|
@@ -47,23 +47,41 @@ following details:
|
|
|
47
47
|
7. Hashed IP, which allows to track requests from the same IP, while preserving
|
|
48
48
|
privacy
|
|
49
49
|
8. Timestamp
|
|
50
|
+
9. IP
|
|
51
|
+
10. browser_version
|
|
52
|
+
11. platform_version
|
|
53
|
+
12. bot?
|
|
54
|
+
13. search_engine?
|
|
55
|
+
14. bot name
|
|
50
56
|
|
|
51
57
|
Information is stored in the application log, each line prefixed by
|
|
52
58
|
=BrowserSense= and data presented in CSV.
|
|
53
59
|
|
|
54
60
|
*Example*
|
|
55
61
|
|
|
62
|
+
Before 1.10:
|
|
63
|
+
|
|
56
64
|
#+begin_example bash
|
|
57
65
|
$ cat production.log
|
|
58
66
|
[...]
|
|
59
|
-
BrowserSense: "Firefox","linux","Unknown","Devise::SessionsController","new","12ca17b49af2289436f303e0166030a21e525d266e209267433801a8fd4071a0","2022-06-09T10:08:09+02:00"
|
|
67
|
+
[<production log header>] BrowserSense: "Firefox","linux","Unknown","Devise::SessionsController","new","12ca17b49af2289436f303e0166030a21e525d266e209267433801a8fd4071a0","2022-06-09T10:08:09+02:00"
|
|
60
68
|
[...]
|
|
61
69
|
#+end_example
|
|
62
70
|
|
|
71
|
+
From 1.10 on (we add some field and use CSV for rendering the CSV, which removes unnecessary quotes).
|
|
72
|
+
(Notice that the last field, =bot_name= is empty. Hence the final comma.
|
|
73
|
+
|
|
74
|
+
#+begin_example bash
|
|
75
|
+
$ cat production.log
|
|
76
|
+
[...]
|
|
77
|
+
[<production log header>] BrowserSense: Firefox,linux,Unknown,UsageController,index,html,12ca17b49af2289436f303e0166030a21e525d266e209267433801a8fd4071a0,2025-12-22T09:29:58+01:00,127.0.0.1,145,0,false,false,
|
|
78
|
+
[...]
|
|
79
|
+
#+end_example
|
|
80
|
+
|
|
63
81
|
|
|
64
82
|
* Analyzing Data
|
|
65
83
|
|
|
66
|
-
When you want to analyze data, extract the information with:
|
|
84
|
+
*(Option 1)* When you want to analyze data, extract the information with:
|
|
67
85
|
|
|
68
86
|
#+begin_example
|
|
69
87
|
grep BrowserSense production.log | cut -f2- -d: > data.csv
|
|
@@ -71,12 +89,18 @@ grep BrowserSense production.log | cut -f2- -d: > data.csv
|
|
|
71
89
|
|
|
72
90
|
and then, e.g., open the resulting file in a spreadsheet.
|
|
73
91
|
|
|
74
|
-
|
|
75
|
-
|
|
92
|
+
*(Option 2)* If you prefer you can use
|
|
93
|
+
|
|
94
|
+
- =BrowserSenseParser.match?(line)= which returns true if the =line= is a line
|
|
95
|
+
produced by BrowserSense
|
|
96
|
+
- =BrowserSenseParser.parse(line)= which returns a Hash with all the fields
|
|
97
|
+
|
|
98
|
+
*(Option 3)* There is a Ruby script =browser_sense=. The script takes as input
|
|
99
|
+
the pathname of the file with the log and prints to stdout the result of various
|
|
76
100
|
analyses. The script is a quick hack, wrapping =sed=, =grep= and =miller=
|
|
77
101
|
([[https://github.com/johnkerl/miller][Miller)]], which must be installed on your machine for the script to succeed.
|
|
78
102
|
|
|
79
|
-
If you want more reports and plots, you can use the =log_sense= gem
|
|
103
|
+
*(Option 4)* If you want more reports and plots, you can use the =log_sense= gem
|
|
80
104
|
(https://rubygems.org/gems/log_sense), which understands the data generated by
|
|
81
105
|
this gem.
|
|
82
106
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require "active_support/concern"
|
|
2
2
|
require "browser"
|
|
3
|
+
require "csv"
|
|
3
4
|
|
|
4
5
|
module BrowserSenseFilter
|
|
5
6
|
extend ActiveSupport::Concern
|
|
@@ -18,15 +19,27 @@ module BrowserSenseFilter
|
|
|
18
19
|
now = DateTime.now
|
|
19
20
|
|
|
20
21
|
logger = Rails.logger
|
|
22
|
+
|
|
21
23
|
browser_data = [
|
|
22
|
-
b.name,
|
|
23
|
-
|
|
24
|
+
b.name,
|
|
25
|
+
b.platform,
|
|
26
|
+
b.device.name,
|
|
27
|
+
controller.class.name,
|
|
28
|
+
controller.action_name,
|
|
24
29
|
request.format.symbol,
|
|
25
30
|
hashed_ip,
|
|
26
|
-
now
|
|
31
|
+
now,
|
|
32
|
+
# added in v 1.1.10
|
|
33
|
+
ip,
|
|
34
|
+
b.version,
|
|
35
|
+
b.platform.version,
|
|
36
|
+
browser.bot?,
|
|
37
|
+
browser.bot&.search_engine?,
|
|
38
|
+
browser.bot&.name
|
|
27
39
|
]
|
|
28
40
|
|
|
29
|
-
browser_data_str =
|
|
41
|
+
CSV(browser_data_str = "") { |csv_str| csv_str << browser_data }
|
|
42
|
+
|
|
30
43
|
logger.info "BrowserSense: #{browser_data_str}"
|
|
31
44
|
end
|
|
32
45
|
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module BrowserSenseParser
|
|
4
|
+
HEADERS = %i[
|
|
5
|
+
browser platform device_name controller method
|
|
6
|
+
request_format anon_ip timestamp
|
|
7
|
+
ip browser_version platform_version
|
|
8
|
+
bot search_engine bot_name
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
def self.match?(line)
|
|
12
|
+
/Browser(Sense|Info):/.match? line
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.parse(line)
|
|
16
|
+
begin
|
|
17
|
+
csv_portion = line.gsub(/^.*Browser(Sense|Info): /, "")
|
|
18
|
+
data = CSV.parse csv_portion, headers: HEADERS
|
|
19
|
+
log_id = log_id(line)
|
|
20
|
+
data.first.to_h.merge(log_id)
|
|
21
|
+
rescue => exception
|
|
22
|
+
Rails.logger.debug exception
|
|
23
|
+
{}
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private_class_method def self.log_id(line)
|
|
28
|
+
matchdata = /-- : \[(?<log_id>[a-f0-9-]+)\]/.match(line)
|
|
29
|
+
|
|
30
|
+
{ log_id: matchdata[:log_id] }
|
|
31
|
+
end
|
|
32
|
+
end
|
data/browser_sense.gemspec
CHANGED
|
@@ -10,9 +10,10 @@ Gem::Specification.new do |spec|
|
|
|
10
10
|
|
|
11
11
|
spec.summary = "Monitor which browser is accessing your Ruby on Rails app."
|
|
12
12
|
spec.description = <<-EOS
|
|
13
|
-
BrowserSense logs information about the browsers
|
|
13
|
+
BrowserSense logs information about the browsers using your RubyOnRails app.
|
|
14
14
|
|
|
15
|
-
Data can be easily extracted from the log, analyzed with the included
|
|
15
|
+
Data can be easily extracted from the log, analyzed with the included
|
|
16
|
+
script or with the log_sense gem.
|
|
16
17
|
EOS
|
|
17
18
|
spec.homepage = "https://github.com/shair-tech/browser_sense"
|
|
18
19
|
spec.license = "MIT"
|
|
@@ -36,8 +37,10 @@ Gem::Specification.new do |spec|
|
|
|
36
37
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
37
38
|
spec.require_paths = ["lib"]
|
|
38
39
|
|
|
39
|
-
#
|
|
40
|
+
# We just log. All the recognition work is done by browser
|
|
40
41
|
spec.add_dependency "browser", "~> 6.2.0"
|
|
42
|
+
# To properly quote log lines
|
|
43
|
+
spec.add_dependency "csv"
|
|
41
44
|
|
|
42
45
|
# For more information and examples about making a new gem, check out our
|
|
43
46
|
# guide at: https://bundler.io/guides/creating_gem.html
|
data/exe/browser_sense
CHANGED
|
@@ -22,7 +22,7 @@ end
|
|
|
22
22
|
|
|
23
23
|
# Look for BrowserSense | cut info by Rails | remove lines with less than 7 fields
|
|
24
24
|
# No need to remove double quotes with sed -e 's/\"//g'
|
|
25
|
-
`grep -E -e 'Browser(Info|Sense)' #{LOG_FILE} | sed -E 's/.*Browser(Info|Sense): (
|
|
25
|
+
`grep -E -e 'Browser(Info|Sense)' #{LOG_FILE} | sed -E 's/.*Browser(Info|Sense): (.+,.+,.+,.+,.+,.+,.+,.+,(.+,.+,.+,.+,.+,.+)?)/\\2/g' > #{TMP_FILE}`
|
|
26
26
|
|
|
27
27
|
# Look at the README file of BrowserSense for the field specification
|
|
28
28
|
#
|
|
@@ -37,6 +37,15 @@ end
|
|
|
37
37
|
# 7. Hashed IP, which allows to track requests from the same IP, while preserving privacy
|
|
38
38
|
# 8. Timestamp
|
|
39
39
|
#
|
|
40
|
+
# Added in 1.10 (and made optional in the regexp above
|
|
41
|
+
#
|
|
42
|
+
# 9, ip
|
|
43
|
+
# 10. b.version
|
|
44
|
+
# 11. b.platform.version
|
|
45
|
+
# 12. browser.bot?
|
|
46
|
+
# 13. browser.bot&.search_engine?
|
|
47
|
+
# 13. browser.bot&.name
|
|
48
|
+
#
|
|
40
49
|
|
|
41
50
|
# methods by os
|
|
42
51
|
# the usage of reshape and unsparsify is still kind of magic to me.
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: browser_sense
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Adolfo Villafiorita
|
|
@@ -23,10 +23,25 @@ dependencies:
|
|
|
23
23
|
- - "~>"
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
25
|
version: 6.2.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'
|
|
26
40
|
description: |2
|
|
27
|
-
BrowserSense logs information about the browsers
|
|
41
|
+
BrowserSense logs information about the browsers using your RubyOnRails app.
|
|
28
42
|
|
|
29
|
-
Data can be easily extracted from the log, analyzed with the included
|
|
43
|
+
Data can be easily extracted from the log, analyzed with the included
|
|
44
|
+
script or with the log_sense gem.
|
|
30
45
|
email:
|
|
31
46
|
- adolfo@shair.tech
|
|
32
47
|
executables:
|
|
@@ -42,6 +57,7 @@ files:
|
|
|
42
57
|
- README.org
|
|
43
58
|
- Rakefile
|
|
44
59
|
- app/controllers/browser_sense_filter.rb
|
|
60
|
+
- app/services/browser_sense_parser.rb
|
|
45
61
|
- browser_sense.gemspec
|
|
46
62
|
- exe/browser_sense
|
|
47
63
|
- lib/browser_sense.rb
|