fluent-plugin-elb-log 0.2.7 → 0.2.8
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/fluent-plugin-elb-log.gemspec +1 -1
- data/lib/fluent/plugin/in_elb_log.rb +26 -19
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4964547c8f6c81ddc8be0aee95bc942420cd824
|
4
|
+
data.tar.gz: 30fb414dc08343f64ee4c671aab0e5246fb8ba55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26bb99092bb3b2d5bd403f1e840cfe0f33ac75355e26dd02794300383f7ed0b29e86bd3bd66953d33fca842ddbf661b00290815af6f9b4f1c6b79b609c6bca53
|
7
|
+
data.tar.gz: 3d4c476adb92920fa4c51a1f7d109fbe5fe8138b9a05b6b5d8c939f5ea7d9ac6e2899656b769e861008636a5f886396f5462271af878bbab56db46b2c96438b6
|
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "fluent-plugin-elb-log"
|
7
|
-
spec.version = "0.2.
|
7
|
+
spec.version = "0.2.8"
|
8
8
|
spec.authors = ["shinsaka"]
|
9
9
|
spec.email = ["shinx1265@gmail.com"]
|
10
10
|
spec.summary = "Amazon ELB log input plugin"
|
@@ -1,9 +1,16 @@
|
|
1
|
+
require 'fluent/input'
|
2
|
+
|
1
3
|
class Fluent::Elb_LogInput < Fluent::Input
|
2
4
|
Fluent::Plugin.register_input('elb_log', self)
|
3
5
|
|
4
6
|
LOGFILE_REGEXP = /^((?<prefix>.+?)\/|)AWSLogs\/(?<account_id>[0-9]{12})\/elasticloadbalancing\/(?<region>.+?)\/(?<logfile_date>[0-9]{4}\/[0-9]{2}\/[0-9]{2})\/[0-9]{12}_elasticloadbalancing_.+?_(?<logfile_elb_name>[^_]+)_(?<elb_timestamp>[0-9]{8}T[0-9]{4}Z)_(?<elb_ip_address>.+?)_(?<logfile_hash>.+)\.log$/
|
5
7
|
ACCESSLOG_REGEXP = /^(?<time>\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}\.\d{6}Z) (?<elb>.+?) (?<client>[^ ]+)\:(?<client_port>.+?) (?<backend>.+?)(\:(?<backend_port>.+?))? (?<request_processing_time>.+?) (?<backend_processing_time>.+?) (?<response_processing_time>.+?) (?<elb_status_code>.+?) (?<backend_status_code>.+?) (?<received_bytes>.+?) (?<sent_bytes>.+?) \"(?<request_method>.+?) (?<request_uri>.+?) (?<request_protocol>.+?)\"( \"(?<user_agent>.*?)\" (?<ssl_cipher>.+?) (?<ssl_protocol>.+)(| (?<option3>.*)))?/
|
6
8
|
|
9
|
+
# To support log_level option implemented by Fluentd v0.10.43
|
10
|
+
unless method_defined?(:log)
|
11
|
+
define_method("log") { $log }
|
12
|
+
end
|
13
|
+
|
7
14
|
# Define `router` method to support v0.10.57 or earlier
|
8
15
|
unless method_defined?(:router)
|
9
16
|
define_method("router") { Fluent::Engine }
|
@@ -62,7 +69,7 @@ class Fluent::Elb_LogInput < Fluent::Input
|
|
62
69
|
ec2 = Aws::EC2::Client.new(region: @region)
|
63
70
|
!ec2.config.credentials.nil?
|
64
71
|
rescue => e
|
65
|
-
|
72
|
+
log.warn "EC2 Client error occurred: #{e.message}"
|
66
73
|
end
|
67
74
|
end
|
68
75
|
|
@@ -72,25 +79,25 @@ class Fluent::Elb_LogInput < Fluent::Input
|
|
72
79
|
# get timestamp last proc
|
73
80
|
start_time = @start_time ? Time.parse(@start_time).utc : Time.at(0)
|
74
81
|
timestamp = start_time.to_i
|
75
|
-
|
82
|
+
log.debug "timestamp file #{@timestamp_file} read"
|
76
83
|
File.open(@timestamp_file, File::RDONLY) do |file|
|
77
84
|
timestamp = file.read.to_i if file.size > 0
|
78
85
|
end
|
79
|
-
|
86
|
+
log.debug "timestamp start at:" + Time.at(timestamp).to_s
|
80
87
|
return timestamp
|
81
88
|
rescue => e
|
82
|
-
|
89
|
+
log.warn "timestamp file get and parse error occurred: #{e.message}"
|
83
90
|
end
|
84
91
|
end
|
85
92
|
|
86
93
|
def put_timestamp_file(timestamp)
|
87
94
|
begin
|
88
|
-
|
95
|
+
log.debug "timestamp file #{@timestamp_file} write"
|
89
96
|
File.open(@timestamp_file, File::WRONLY|File::CREAT|File::TRUNC) do |file|
|
90
97
|
file.puts timestamp.to_s
|
91
98
|
end
|
92
99
|
rescue => e
|
93
|
-
|
100
|
+
log.warn "timestamp file get and parse error occurred: #{e.message}"
|
94
101
|
end
|
95
102
|
end
|
96
103
|
|
@@ -106,34 +113,34 @@ class Fluent::Elb_LogInput < Fluent::Input
|
|
106
113
|
if @http_proxy
|
107
114
|
options[:http_proxy] = @http_proxy
|
108
115
|
end
|
109
|
-
|
116
|
+
log.debug "S3 client connect"
|
110
117
|
Aws::S3::Client.new(options)
|
111
118
|
rescue => e
|
112
|
-
|
119
|
+
log.warn "S3 Client error occurred: #{e.message}"
|
113
120
|
end
|
114
121
|
end
|
115
122
|
|
116
123
|
def s3bucket_is_ok
|
117
124
|
begin
|
118
|
-
|
125
|
+
log.debug "search bucket #{@s3_bucketname}"
|
119
126
|
|
120
127
|
s3_client.list_buckets.buckets.any? do |bucket|
|
121
128
|
bucket.name == @s3_bucketname
|
122
129
|
end
|
123
130
|
rescue => e
|
124
|
-
|
131
|
+
log.warn "S3 Client error occurred: #{e.message}"
|
125
132
|
end
|
126
133
|
end
|
127
134
|
|
128
135
|
def input
|
129
|
-
|
136
|
+
log.debug "start"
|
130
137
|
|
131
138
|
timestamp = get_timestamp_file()
|
132
139
|
|
133
140
|
object_keys = get_object_keys(timestamp)
|
134
141
|
object_keys = sort_object_key(object_keys)
|
135
142
|
|
136
|
-
|
143
|
+
log.info "processing #{object_keys.count} object(s)."
|
137
144
|
|
138
145
|
object_keys.each do |object_key|
|
139
146
|
record_common = {
|
@@ -176,7 +183,7 @@ class Fluent::Elb_LogInput < Fluent::Input
|
|
176
183
|
elb_timestamp_unixtime = Time.parse(matches[:elb_timestamp]).to_i
|
177
184
|
next if elb_timestamp_unixtime <= timestamp
|
178
185
|
|
179
|
-
|
186
|
+
log.debug content.key
|
180
187
|
object_keys << {
|
181
188
|
key: content.key,
|
182
189
|
prefix: matches[:prefix],
|
@@ -193,7 +200,7 @@ class Fluent::Elb_LogInput < Fluent::Input
|
|
193
200
|
end
|
194
201
|
return object_keys
|
195
202
|
rescue => e
|
196
|
-
|
203
|
+
log.warn "error occurred: #{e.message}"
|
197
204
|
end
|
198
205
|
end
|
199
206
|
|
@@ -203,13 +210,13 @@ class Fluent::Elb_LogInput < Fluent::Input
|
|
203
210
|
a[:elb_timestamp_unixtime] <=> b[:elb_timestamp_unixtime]
|
204
211
|
end
|
205
212
|
rescue => e
|
206
|
-
|
213
|
+
log.warn "error occurred: #{e.message}"
|
207
214
|
end
|
208
215
|
end
|
209
216
|
|
210
217
|
def get_file_from_s3(object_name)
|
211
218
|
begin
|
212
|
-
|
219
|
+
log.debug "getting object from s3 name is #{object_name}"
|
213
220
|
|
214
221
|
# read an object from S3 to a file and write buffer file
|
215
222
|
File.open(@buf_file, File::WRONLY|File::CREAT|File::TRUNC) do |file|
|
@@ -221,7 +228,7 @@ class Fluent::Elb_LogInput < Fluent::Input
|
|
221
228
|
end
|
222
229
|
end
|
223
230
|
rescue => e
|
224
|
-
|
231
|
+
log.warn "error occurred: #{e.message}"
|
225
232
|
end
|
226
233
|
end
|
227
234
|
|
@@ -232,7 +239,7 @@ class Fluent::Elb_LogInput < Fluent::Input
|
|
232
239
|
file.each_line do |line|
|
233
240
|
line_match = ACCESSLOG_REGEXP.match(line)
|
234
241
|
unless line_match
|
235
|
-
|
242
|
+
log.info "nomatch log found: #{line} in #{record_common['key']}"
|
236
243
|
next
|
237
244
|
end
|
238
245
|
|
@@ -263,7 +270,7 @@ class Fluent::Elb_LogInput < Fluent::Input
|
|
263
270
|
end
|
264
271
|
end
|
265
272
|
rescue => e
|
266
|
-
|
273
|
+
log.warn "error occurred: #{e.message}"
|
267
274
|
end
|
268
275
|
end
|
269
276
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-elb-log
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- shinsaka
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|