log_insight 0.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 +7 -0
- data/README.md +0 -0
- data/exe/log_insight +11 -0
- data/lib/log_insight.rb +94 -0
- metadata +42 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: eccb0637697cbfd71698ac1e3c3829bec47a1cd6f635ab8565bbc830eb9e2739
|
|
4
|
+
data.tar.gz: e6c66cf24baebf4a85fd7fc6a67602ac733669c365503a59dcf9531e8c0aabfb
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 93811489139644d21c08aafb13e6e5353277168ea9bb6d916f2df3c4b70a9ab3585d577b656286c029c734648d8aed3d038cf3fac43213cda3f443f7a28e9cbe
|
|
7
|
+
data.tar.gz: c15413b5adbb0ded9b03710fe27ae636a1afaa44afec7d49c88a4619b9d3dce9df85610c304c608f26d4b0aa3f1ccffaa746f7508fcd484f63c7959250d0b8f0
|
data/README.md
ADDED
|
File without changes
|
data/exe/log_insight
ADDED
data/lib/log_insight.rb
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
require 'csv'
|
|
2
|
+
require 'json'
|
|
3
|
+
|
|
4
|
+
class LogInsight
|
|
5
|
+
def self.run(file_path, filter_method: nil, filter_route: nil)
|
|
6
|
+
unless File.exist?(file_path)
|
|
7
|
+
puts "Error: file not found"
|
|
8
|
+
return
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
total_lines = 0
|
|
12
|
+
method_counts = Hash.new(0)
|
|
13
|
+
status_counts = Hash.new(0)
|
|
14
|
+
error_count = 0
|
|
15
|
+
|
|
16
|
+
output_dir = "output"
|
|
17
|
+
Dir.mkdir(output_dir) unless Dir.exist?(output_dir)
|
|
18
|
+
|
|
19
|
+
File.foreach(file_path) do |line|
|
|
20
|
+
parts = line.split(" ")
|
|
21
|
+
next if parts.size < 5
|
|
22
|
+
|
|
23
|
+
method = parts[2]
|
|
24
|
+
route = parts[3]
|
|
25
|
+
status = parts[4].to_i
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
next if filter_method && method != filter_method
|
|
29
|
+
next if filter_route && route != filter_route
|
|
30
|
+
|
|
31
|
+
output_file = File.join(output_dir, "#{method}.log")
|
|
32
|
+
|
|
33
|
+
File.open(output_file, "a") do |file|
|
|
34
|
+
file.puts line
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
total_lines += 1
|
|
38
|
+
method_counts[method] += 1
|
|
39
|
+
status_counts[status] += 1
|
|
40
|
+
error_count += 1 if status >= 400
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
puts "Log Insight Report"
|
|
45
|
+
puts "------------------"
|
|
46
|
+
puts "\nEntries by HTTP method:"
|
|
47
|
+
method_counts.sort_by { |_, c| -c }.each { |m, c| puts " #{m}: #{c}" }
|
|
48
|
+
|
|
49
|
+
puts "\nEntries by status code:"
|
|
50
|
+
status_counts.sort_by { |_, c| -c }.each { |s, c| puts " #{s}: #{c}" }
|
|
51
|
+
|
|
52
|
+
puts "\nErrors (status >= 400): #{error_count}"
|
|
53
|
+
puts "Total log entries: #{total_lines}"
|
|
54
|
+
|
|
55
|
+
# GRAPH
|
|
56
|
+
puts "\nGraphical view of HTTP methods:"
|
|
57
|
+
method_counts.sort_by { |_, c| -c }.each do |m, c|
|
|
58
|
+
puts "#{m.ljust(6)} | #{'#' * c} (#{c})"
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
puts "\nGraphical view of Status codes:"
|
|
62
|
+
status_counts.sort_by { |_, c| -c }.each do |status, count|
|
|
63
|
+
bars = count / 100
|
|
64
|
+
bars = 1 if bars == 0 && count > 0
|
|
65
|
+
|
|
66
|
+
puts "#{status} | #{'#' * bars} (#{count})"
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
puts "\nNote: 1 # = 100 requests"
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
CSV.open("report.csv", "w") do |csv|
|
|
74
|
+
csv << ["Method", "Count"]
|
|
75
|
+
method_counts.each { |m, c| csv << [m, c] }
|
|
76
|
+
|
|
77
|
+
csv << []
|
|
78
|
+
csv << ["Status", "Count"]
|
|
79
|
+
status_counts.each { |s, c| csv << [s, c] }
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
File.write("report.json", {
|
|
84
|
+
methods: method_counts,
|
|
85
|
+
status: status_counts,
|
|
86
|
+
errors: error_count,
|
|
87
|
+
total: total_lines
|
|
88
|
+
}.to_json)
|
|
89
|
+
|
|
90
|
+
puts "\nReports exported: report.csv, report.json"
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
|
metadata
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: log_insight
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- MANDANIA INAPRECIEUX
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: Analyze HTTP logs, extract stats, export CSV/JSON.
|
|
13
|
+
executables:
|
|
14
|
+
- log_insight
|
|
15
|
+
extensions: []
|
|
16
|
+
extra_rdoc_files: []
|
|
17
|
+
files:
|
|
18
|
+
- README.md
|
|
19
|
+
- exe/log_insight
|
|
20
|
+
- lib/log_insight.rb
|
|
21
|
+
homepage: https://github.com/MANDANIAINAPRECIEUX/log_insight
|
|
22
|
+
licenses:
|
|
23
|
+
- MIT
|
|
24
|
+
metadata: {}
|
|
25
|
+
rdoc_options: []
|
|
26
|
+
require_paths:
|
|
27
|
+
- lib
|
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '2.7'
|
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - ">="
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
requirements: []
|
|
39
|
+
rubygems_version: 3.6.9
|
|
40
|
+
specification_version: 4
|
|
41
|
+
summary: HTTP log analyzer CLI
|
|
42
|
+
test_files: []
|