logstash-input-mongoprofile 0.1.2 → 0.1.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.
- checksums.yaml +4 -4
- data/lib/logstash/inputs/mongoprofile.rb +103 -1
- data/logstash-input-mongoprofile.gemspec +1 -1
- metadata +1 -2
- data/lib/mongo/mongo.rb +0 -117
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f26f651e99da27cbe03bf873ef7bb6c736db4fb2
|
4
|
+
data.tar.gz: bb5705c865fd804733ed18cb815a63af8b39751e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64467f27ef79e98ad9f299168c09822727c562c69ea3d3ca5098630266fb7454d4225348e0a74131e078c0063bd1b959d221a4f0a9e73a2e99c979ac194bf6a7
|
7
|
+
data.tar.gz: fed81e42dc1464f287804c922513c5fbd1749dab5dd91bd515c920e7820360a686f7e6af562d06ca42ffebd8950eae5b729c7cd184f1cbddc130f1c87665ea5a
|
@@ -3,7 +3,7 @@ require "logstash/inputs/base"
|
|
3
3
|
require "logstash/namespace"
|
4
4
|
require "stud/interval"
|
5
5
|
require "socket" # for Socket.gethostname
|
6
|
-
require
|
6
|
+
require "mongo"
|
7
7
|
|
8
8
|
# Generate a repeating message.
|
9
9
|
#
|
@@ -53,3 +53,105 @@ class LogStash::Inputs::Mongoprofile < LogStash::Inputs::Base
|
|
53
53
|
# * terminate spawned threads
|
54
54
|
end
|
55
55
|
end # class LogStash::Inputs::Mongoprofile
|
56
|
+
|
57
|
+
class MongoAccessor
|
58
|
+
def initialize(url, collection, client_host)
|
59
|
+
connection = Mongo::Client.new(url)
|
60
|
+
|
61
|
+
@mongodb = connection.database
|
62
|
+
@collection = @mongodb.collection(collection)
|
63
|
+
@client_host = client_host
|
64
|
+
end
|
65
|
+
|
66
|
+
def get_documents_by_ts(date, limit)
|
67
|
+
@collection.find({:ts => {:$gt => date}, :client => {:$ne => @client_host}}).limit(limit)
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_documents(limit)
|
71
|
+
@collection.find({:client => {:$ne => @client_host}}).limit(limit)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class ProfileCollection
|
76
|
+
def initialize(documents, parser)
|
77
|
+
@documents = documents
|
78
|
+
@parser = parser
|
79
|
+
end
|
80
|
+
|
81
|
+
def each
|
82
|
+
@documents.each do |document|
|
83
|
+
document['_id'] = generate_id
|
84
|
+
yield @parser.parse(document)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def get_last_document_date
|
89
|
+
@documents[-1]['ts']
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
def generate_id
|
94
|
+
# noinspection RubyArgCount
|
95
|
+
BSON::ObjectId.new
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
class DocumentParser
|
100
|
+
def initialize(host)
|
101
|
+
@host = host
|
102
|
+
end
|
103
|
+
|
104
|
+
def parse(document)
|
105
|
+
event = LogStash::Event.new('host' => @host)
|
106
|
+
|
107
|
+
document.each do |key, value|
|
108
|
+
event.set(key, value)
|
109
|
+
end
|
110
|
+
|
111
|
+
event
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
class LastValueStore
|
116
|
+
def initialize(path, name)
|
117
|
+
@file_full_name = "#{path}/#{name}"
|
118
|
+
end
|
119
|
+
|
120
|
+
def save_last_value(value)
|
121
|
+
file = File.open(@file_full_name, 'a+')
|
122
|
+
|
123
|
+
file.truncate(0)
|
124
|
+
file.puts(value)
|
125
|
+
|
126
|
+
file.close
|
127
|
+
end
|
128
|
+
|
129
|
+
def get_last_value
|
130
|
+
File.read(@file_full_name)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
class Controller
|
135
|
+
def initialize(event, url, collection, limit, path, client_host)
|
136
|
+
@mongo_accessor = MongoAccessor.new(url, collection, client_host)
|
137
|
+
@last_value_store = LastValueStore.new(path, collection)
|
138
|
+
@document_parser = DocumentParser.new(event)
|
139
|
+
@limit = limit
|
140
|
+
end
|
141
|
+
|
142
|
+
def get_next_events
|
143
|
+
last_date_value = @last_value_store.get_last_value
|
144
|
+
|
145
|
+
if last_date_value == ''
|
146
|
+
documents = @mongo_accessor.get_documents(@limit)
|
147
|
+
else
|
148
|
+
documents = @mongo_accessor.get_documents_by_ts(last_date_value, @limit)
|
149
|
+
end
|
150
|
+
|
151
|
+
profile_collection = ProfileCollection.new(documents, @document_parser)
|
152
|
+
|
153
|
+
@last_value_store.save_last_value(profile_collection.get_last_document_date)
|
154
|
+
|
155
|
+
profile_collection
|
156
|
+
end
|
157
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-input-mongoprofile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artem Antonov
|
@@ -93,7 +93,6 @@ files:
|
|
93
93
|
- LICENSE
|
94
94
|
- README.md
|
95
95
|
- lib/logstash/inputs/mongoprofile.rb
|
96
|
-
- lib/mongo/mongo.rb
|
97
96
|
- logstash-input-mongoprofile.gemspec
|
98
97
|
- spec/inputs/mongoprofile_spec.rb
|
99
98
|
homepage: https://github.com/aantonovdevelop/logstash-input-mongoprofile
|
data/lib/mongo/mongo.rb
DELETED
@@ -1,117 +0,0 @@
|
|
1
|
-
require 'mongo'
|
2
|
-
require 'logstash/inputs/base'
|
3
|
-
|
4
|
-
class MongoAccessor
|
5
|
-
def initialize(url, collection, client_host)
|
6
|
-
connection = Mongo::Client.new(url)
|
7
|
-
|
8
|
-
@mongodb = connection.database
|
9
|
-
@collection = @mongodb.collection(collection)
|
10
|
-
@client_host = client_host
|
11
|
-
end
|
12
|
-
|
13
|
-
def get_documents_by_ts(date, limit)
|
14
|
-
@collection.find({:ts => {:$gt => date}, :client => {:$ne => @client_host}}).limit(limit)
|
15
|
-
end
|
16
|
-
|
17
|
-
def get_documents(limit)
|
18
|
-
@collection.find({:client => {:$ne => @client_host}}).limit(limit)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class ProfileCollection
|
23
|
-
def initialize(documents, parser)
|
24
|
-
@documents = documents
|
25
|
-
@parser = parser
|
26
|
-
end
|
27
|
-
|
28
|
-
def each
|
29
|
-
@documents.each do |document|
|
30
|
-
document['_id'] = generate_id
|
31
|
-
yield @parser.parse(document)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def get_last_document_date
|
36
|
-
@documents[-1]['ts']
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
def generate_id
|
41
|
-
# noinspection RubyArgCount
|
42
|
-
BSON::ObjectId.new
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
class DocumentParser
|
47
|
-
def initialize(host)
|
48
|
-
@host = host
|
49
|
-
end
|
50
|
-
|
51
|
-
def parse(document)
|
52
|
-
event = LogStash::Event.new('host' => @host)
|
53
|
-
|
54
|
-
document.each do |key, value|
|
55
|
-
event.set(key, value)
|
56
|
-
end
|
57
|
-
|
58
|
-
event
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
class LastValueStore
|
63
|
-
def initialize(path, name)
|
64
|
-
@file_full_name = "#{path}/#{name}"
|
65
|
-
end
|
66
|
-
|
67
|
-
def save_last_value(value)
|
68
|
-
file = File.open(@file_full_name, 'a+')
|
69
|
-
|
70
|
-
file.truncate(0)
|
71
|
-
file.puts(value)
|
72
|
-
|
73
|
-
file.close
|
74
|
-
end
|
75
|
-
|
76
|
-
def get_last_value
|
77
|
-
File.read(@file_full_name)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
class Controller
|
82
|
-
def initialize(event, url, collection, limit, path, client_host)
|
83
|
-
@mongo_accessor = MongoAccessor.new(url, collection, client_host)
|
84
|
-
@last_value_store = LastValueStore.new(path, collection)
|
85
|
-
@document_parser = DocumentParser.new(event)
|
86
|
-
@limit = limit
|
87
|
-
end
|
88
|
-
|
89
|
-
def get_next_events
|
90
|
-
last_date_value = @last_value_store.get_last_value
|
91
|
-
|
92
|
-
if last_date_value == ''
|
93
|
-
documents = @mongo_accessor.get_documents(@limit)
|
94
|
-
else
|
95
|
-
documents = @mongo_accessor.get_documents_by_ts(last_date_value, @limit)
|
96
|
-
end
|
97
|
-
|
98
|
-
profile_collection = ProfileCollection.new(documents, @document_parser)
|
99
|
-
|
100
|
-
@last_value_store.save_last_value(profile_collection.get_last_document_date)
|
101
|
-
|
102
|
-
profile_collection
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
lv = LastValueStore.new('/home/artem', 'mex.txt')
|
107
|
-
|
108
|
-
lv.save_last_value("blasaldkfj")
|
109
|
-
puts lv.get_last_value
|
110
|
-
|
111
|
-
#mongo = MongoAccessor.new('mongodb://192.168.1.37/eleet-v2-dev', 'system.profile')
|
112
|
-
|
113
|
-
#ProfileCollection.new(mongo.get_documents(10)).each do |document|
|
114
|
-
#puts document['_id']
|
115
|
-
#end
|
116
|
-
|
117
|
-
|