omloga 0.0.2 → 0.0.3

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.
Files changed (5) hide show
  1. checksums.yaml +2 -5
  2. data/README.md +3 -0
  3. data/lib/omloga.rb +27 -10
  4. data/lib/omloga/request.rb +7 -5
  5. metadata +12 -12
checksums.yaml CHANGED
@@ -1,7 +1,4 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e1a09f1d37411cdfb8dc303ab7c8350b18478ac6
4
- data.tar.gz: 64f016732252292f3accb2fa332a545047c24073
5
2
  SHA512:
6
- metadata.gz: 90acbdb13e3fdb2437d8833129706f299bf6ba05a4b518392a788df1da6df64cf7871a4a6ec3dde4ff39de6780aa00976a1f893a4f4034ad8613b71e39ac1e30
7
- data.tar.gz: ec3bc730f68597bc073f13ecf34cb5629b9c3ccb3a0a9a1a797cc5615581c5da3bbde6450ac1603462d4ed6d9f703c2f3afe5c40de4da51f87195e37e8845765
3
+ metadata.gz: b2fcace5055ab4a67e6138c39ef8c885a5ea2bee233e68c35d9ac9d1c7aecebdf2ae99b0bab7615ea8f37339aaa83ab9eff79b652ca605bed2bcb5314a95bad5
4
+ data.tar.gz: f73538cf307963df1f77abf2f4f37fc1c73d590b6f88fc4e0df12892f40a0f7515f2d82f9978d0b064d0816543c7b3bc66d638fee2fbd24a258ab56b6384d15d
data/README.md CHANGED
@@ -2,3 +2,6 @@ omloga
2
2
  ======
3
3
 
4
4
  A Ruby on Rails log parser and stitcher.
5
+
6
+
7
+ [![Gem Version](https://badge.fury.io/rb/omloga.png)](http://badge.fury.io/rb/omloga)
@@ -1,4 +1,4 @@
1
- require 'moped'
1
+ require 'mongo'
2
2
  require 'optparse'
3
3
  require 'ostruct'
4
4
  require 'omloga/request'
@@ -39,8 +39,8 @@ def omloga(args)
39
39
  exit
40
40
  end
41
41
 
42
- def db_session
43
- $DB_SESSION
42
+ def db_client
43
+ $DB_CLIENT
44
44
  end
45
45
 
46
46
  def logs_collection
@@ -51,8 +51,9 @@ def omloga(args)
51
51
  $REQUEST_HASH
52
52
  end
53
53
 
54
- $DB_SESSION = Moped::Session.connect(options.dburi)
55
- $DB_LOGS_COLLECTION = db_session[options.collection]
54
+ $DB_CLIENT = Mongo::Client.new(options.dburi)
55
+ db_client.logger.level = Logger::INFO
56
+ $DB_LOGS_COLLECTION = db_client[options.collection]
56
57
  $REQUEST_HASH = {}
57
58
  $LOG_FILE = args[0]
58
59
 
@@ -87,6 +88,15 @@ def omloga(args)
87
88
  end
88
89
  end
89
90
 
91
+ def get_uuid(line)
92
+ match_data = line.match(/([a-f\d]{8}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{12})/)
93
+ if match_data
94
+ return match_data[1]
95
+ else
96
+ return nil
97
+ end
98
+ end
99
+
90
100
  line_count = 0
91
101
  request_count = 0
92
102
  lines_skipped = 0
@@ -99,16 +109,23 @@ def omloga(args)
99
109
  end
100
110
 
101
111
  File.foreach($LOG_FILE) do |log_line|
112
+ log_line.strip!
102
113
  pid = get_pid(log_line)
103
- req = request_hash[pid]
114
+ uuid = get_uuid(log_line)
115
+ req = request_hash[uuid]
116
+ if uuid == nil
117
+ lines_skipped += 1
118
+ skipped_lines.print log_line if log_skip
119
+ next
120
+ end
104
121
 
105
122
  if is_start_line?(log_line)
106
123
  if req
107
124
  req.add_start_line(log_line)
108
125
  req.count+= 1
109
126
  else
110
- req = Omloga::Request.new(pid, log_line)
111
- request_hash[pid] = req
127
+ req = Omloga::Request.new(uuid, pid, log_line)
128
+ request_hash[uuid] = req
112
129
  end
113
130
  else
114
131
  unless req
@@ -123,8 +140,8 @@ def omloga(args)
123
140
  req.complete_count+= 1
124
141
 
125
142
  if req.complete_count >= req.count
126
- logs_collection.find(req.id_doc).upsert(req.mongo_doc)
127
- request_hash.delete(pid)
143
+ logs_collection.find(req.id_doc).update_one(req.mongo_doc, {upsert: true})
144
+ request_hash.delete(uuid)
128
145
  request_count+= req.count
129
146
  end
130
147
  else
@@ -1,13 +1,14 @@
1
1
  #encoding: utf-8
2
2
 
3
- require 'moped'
3
+ require 'mongo'
4
4
 
5
5
  module Omloga
6
6
  class Request
7
- attr_accessor :id, :pid, :saved, :lines, :count, :complete_count, :path, :status, :created_at, :updated_at
7
+ attr_accessor :id, :uuid, :pid, :saved, :lines, :count, :complete_count, :path, :status, :created_at, :updated_at
8
8
 
9
- def initialize(pid, start_line)
10
- @id = Moped::BSON::ObjectId.new
9
+ def initialize(uuid, pid, start_line)
10
+ @id = BSON::ObjectId.new
11
+ @uuid = uuid
11
12
  @pid = pid
12
13
  @saved = false
13
14
  @count = 1
@@ -31,11 +32,12 @@ module Omloga
31
32
  def mongo_doc
32
33
  obj = {
33
34
  '_id' => id,
35
+ 'uuid' => uuid,
34
36
  'pid' => pid,
35
37
  'count' => count,
36
38
  'path' => path,
37
39
  'status' => status,
38
- 'lines' => lines.join("")
40
+ 'lines' => lines
39
41
  }
40
42
 
41
43
  if saved
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omloga
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Srirang G Doddihal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-07 00:00:00.000000000 Z
11
+ date: 2020-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: moped
14
+ name: mongo
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.4.3
19
+ version: 2.6.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.4.3
26
+ version: 2.6.4
27
27
  description: Stitches together log lines of every request and inserts them as one
28
28
  record in MongoDB for easier analysis
29
29
  email: saferanga-rubygems@yahoo.com
@@ -32,10 +32,10 @@ executables:
32
32
  extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
- - lib/omloga.rb
36
- - lib/omloga/request.rb
37
35
  - README.md
38
36
  - bin/omloga
37
+ - lib/omloga.rb
38
+ - lib/omloga/request.rb
39
39
  homepage: http://rubygems.org/gems/omloga
40
40
  licenses:
41
41
  - MIT
@@ -46,17 +46,17 @@ require_paths:
46
46
  - lib
47
47
  required_ruby_version: !ruby/object:Gem::Requirement
48
48
  requirements:
49
- - - '>='
49
+ - - ">="
50
50
  - !ruby/object:Gem::Version
51
51
  version: '0'
52
52
  required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - '>='
54
+ - - ">="
55
55
  - !ruby/object:Gem::Version
56
56
  version: '0'
57
57
  requirements: []
58
58
  rubyforge_project:
59
- rubygems_version: 2.0.3
59
+ rubygems_version: 2.4.5.3
60
60
  signing_key:
61
61
  specification_version: 4
62
62
  summary: A Ruby on Rails log parser and stitcher.