fluent-plugin-elb-log 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +71 -0
- data/Rakefile +1 -0
- data/fluent-plugin-elb-log.gemspec +25 -0
- data/fluent.conf.sample +15 -0
- data/lib/fluent/plugin/in_elb_log.rb +136 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b28cbf57d3635f360469e3aa85b5578fa22d42e6
|
4
|
+
data.tar.gz: 85f84e3f4af74a545c98149322a06cf8728f048e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b01dfd0527825704b8504f3162ae83091b316cfae1fff9426fa8e5be94e0d735a3da754d9b6a97a4cbc402e38caf176c7f2a4271284d3320952f8eec749790b4
|
7
|
+
data.tar.gz: f3c679a1f783b92dba3233de478216afcbf78fd730df3f8219e299b3c264deecd33fd73988a3ad6711aa05ccf074876f9299008a1652bd75efc70281ab22e464
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 shinsaka
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Amazon ELB log input plugin for fluentd
|
2
|
+
|
3
|
+
## Overview
|
4
|
+
- Amazon Web Services ELB log input plubin for fluentd
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
$ fluentd-gem fluent-plugin-elb-log
|
9
|
+
|
10
|
+
## AWS ELB Settings
|
11
|
+
- settings see: [Elastic Load Balancing](http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/enable-access-logs.html)
|
12
|
+
- developer guide: [](http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/access-log-collection.html)
|
13
|
+
|
14
|
+
## Configuration
|
15
|
+
|
16
|
+
```config
|
17
|
+
<source>
|
18
|
+
type elb_log
|
19
|
+
access_key_id <access_key>
|
20
|
+
secret_access_key <secret_access_key>
|
21
|
+
s3_endpoint <s3_endpoint>
|
22
|
+
s3_bucketname <bucketname>
|
23
|
+
s3_prefix <elb log's prefix>
|
24
|
+
timestamp_file <proc last file timestamp record filename>
|
25
|
+
refresh_interval <interval number by second>
|
26
|
+
</source>
|
27
|
+
```
|
28
|
+
|
29
|
+
### Example setting
|
30
|
+
```config
|
31
|
+
<source>
|
32
|
+
type elb_log
|
33
|
+
access_key_id XXXXXXXXXXXXXXXXXXXX
|
34
|
+
secret_access_key xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
35
|
+
s3_endpoint s3.amazonaws.com
|
36
|
+
s3_bucketname bucketname
|
37
|
+
s3_prefix prefix
|
38
|
+
timestamp_file elb_last_at.dat
|
39
|
+
refresh_interval 300
|
40
|
+
</source>
|
41
|
+
|
42
|
+
<match **>
|
43
|
+
type stdout
|
44
|
+
</match>
|
45
|
+
```json
|
46
|
+
{
|
47
|
+
"account_id": "999999999999",
|
48
|
+
"backend": "192.168.30.127",
|
49
|
+
"backend_port": "80",
|
50
|
+
"backend_processing_time": "0.000985",
|
51
|
+
"backend_status_code": "200",
|
52
|
+
"client": "118.20.x.x",
|
53
|
+
"client_port": "46171",
|
54
|
+
"elb": "fluent-test-elb",
|
55
|
+
"elb_ip_address": "54.250.x.x",
|
56
|
+
"elb_status_code": "200",
|
57
|
+
"logfile_date": "2014/03/09",
|
58
|
+
"logfile_elb_name": "fluent-test-elb",
|
59
|
+
"logfile_hash": "xyz123ab",
|
60
|
+
"received_bytes": "0",
|
61
|
+
"region": "ap-northeast-1",
|
62
|
+
"request_method": "GET",
|
63
|
+
"request_processing_time": "0.000072",
|
64
|
+
"request_protocol": "HTTP/1.1",
|
65
|
+
"request_uri": "http://logfile_elb_name-00000000.ap-northeast-1.elb.amazonaws.com:80/",
|
66
|
+
"response_processing_time": "0.00007",
|
67
|
+
"sent_bytes": "9",
|
68
|
+
"time": "2014-03-09T04:10:33.785083Z"
|
69
|
+
}
|
70
|
+
```
|
71
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "fluent-plugin-elb-log"
|
7
|
+
spec.version = "0.0.2"
|
8
|
+
spec.authors = ["shinsaka"]
|
9
|
+
spec.email = ["shinx1265@gmail.com"]
|
10
|
+
spec.summary = "Amazon ELB log input plugin"
|
11
|
+
spec.description = "Amazon ELB log input plugin for fluentd"
|
12
|
+
spec.homepage = "https://github.com/shinsaka/fluent-plugin-elb-log"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_runtime_dependency "fluentd"
|
21
|
+
spec.add_runtime_dependency "aws-sdk"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
end
|
data/fluent.conf.sample
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
<source>
|
2
|
+
type elb_log
|
3
|
+
access_key_id XXXXXXXXXXXXXXXXXXXX
|
4
|
+
secret_access_key xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
5
|
+
s3_endpoint s3.amazonaws.com
|
6
|
+
s3_bucketname bucketname
|
7
|
+
s3_prefix prefix
|
8
|
+
timestamp_file elb_last_at.dat
|
9
|
+
refresh_interval 300
|
10
|
+
</source>
|
11
|
+
|
12
|
+
<match elb.access>
|
13
|
+
type stdout
|
14
|
+
</match>
|
15
|
+
|
@@ -0,0 +1,136 @@
|
|
1
|
+
class Fluent::Elb_LogInput < Fluent::Input
|
2
|
+
Fluent::Plugin.register_input('elb_log', self)
|
3
|
+
|
4
|
+
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
|
+
ACCESSLOG_REGEXP = /^(?<time>.+?) (?<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>.+?)\"$/
|
6
|
+
|
7
|
+
config_param :access_key_id, :string, :default => nil
|
8
|
+
config_param :secret_access_key, :string, :default => nil
|
9
|
+
config_param :s3_bucketname, :string, :default => nil
|
10
|
+
config_param :s3_prefix, :string, :default => nil
|
11
|
+
config_param :s3_endpoint, :string, :default => 's3.amazon.com'
|
12
|
+
config_param :timestamp_file, :string, :default => nil
|
13
|
+
config_param :refresh_interval, :integer, :default => 300
|
14
|
+
|
15
|
+
def configure(conf)
|
16
|
+
super
|
17
|
+
require 'aws-sdk'
|
18
|
+
raise Fluent::ConfigError.new("access_key_id is required") unless @access_key_id
|
19
|
+
raise Fluent::ConfigError.new("secret_access_key is required") unless @secret_access_key
|
20
|
+
raise Fluent::ConfigError.new("s3_bucketname is required") unless @s3_bucketname
|
21
|
+
raise Fluent::ConfigError.new("timestamp_file is required") unless @timestamp_file
|
22
|
+
end
|
23
|
+
|
24
|
+
def start
|
25
|
+
super
|
26
|
+
|
27
|
+
init_s3bucket
|
28
|
+
|
29
|
+
@timestamp_file = File.open(@timestamp_file, File::RDWR|File::CREAT)
|
30
|
+
@timestamp_file.sync = true
|
31
|
+
|
32
|
+
@loop = Coolio::Loop.new
|
33
|
+
timer_trigger = TimerWatcher.new(@refresh_interval, true, &method(:input))
|
34
|
+
timer_trigger.attach(@loop)
|
35
|
+
@thread = Thread.new(&method(:run))
|
36
|
+
end
|
37
|
+
|
38
|
+
def shutdown
|
39
|
+
super
|
40
|
+
@loop.stop
|
41
|
+
@thread.join
|
42
|
+
@timestamp_file.close
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def init_s3bucket
|
48
|
+
@bucket = AWS::S3.new(
|
49
|
+
access_key_id: @access_key_id,
|
50
|
+
secret_access_key: @secret_access_key
|
51
|
+
).buckets[@s3_bucketname]
|
52
|
+
end
|
53
|
+
|
54
|
+
def run
|
55
|
+
@loop.run
|
56
|
+
end
|
57
|
+
|
58
|
+
def input
|
59
|
+
$log.info "fluent-plugin-elb-log: input start"
|
60
|
+
|
61
|
+
#get timestamp last proc
|
62
|
+
@timestamp_file.rewind
|
63
|
+
timestamp = @timestamp_file.read.to_i
|
64
|
+
timestamp = 0 unless timestamp
|
65
|
+
$log.info "fluent-plugin-elb-log: timestamp at start: " + Time.at(timestamp).to_s
|
66
|
+
|
67
|
+
log_objects = []
|
68
|
+
@bucket.objects.each do |obj|
|
69
|
+
next if obj.last_modified.to_i <= timestamp
|
70
|
+
matches = LOGFILE_REGEXP.match(obj.key)
|
71
|
+
next unless matches
|
72
|
+
next if !@s3_prefix.nil? && matches[:prefix] != @s3_prefix
|
73
|
+
log_objects.push obj
|
74
|
+
end
|
75
|
+
|
76
|
+
# sort by timestamp
|
77
|
+
log_objects.sort! do |a,b|
|
78
|
+
LOGFILE_REGEXP.match(a.key)[:elb_timestamp] <=> LOGFILE_REGEXP.match(b.key)[:elb_timestamp]
|
79
|
+
end
|
80
|
+
|
81
|
+
log_objects.each do |obj|
|
82
|
+
matches = LOGFILE_REGEXP.match(obj.key)
|
83
|
+
timestamp = matches[:elb_timestamp].to_i
|
84
|
+
record_common = {
|
85
|
+
account_id: matches[:account_id],
|
86
|
+
region: matches[:region],
|
87
|
+
logfile_date: matches[:logfile_date],
|
88
|
+
logfile_elb_name: matches[:logfile_elb_name],
|
89
|
+
elb_ip_address: matches[:elb_ip_address],
|
90
|
+
logfile_hash: matches[:logfile_hash],
|
91
|
+
}
|
92
|
+
|
93
|
+
obj.read do |line|
|
94
|
+
line_match = ACCESSLOG_REGEXP.match(line)
|
95
|
+
next unless line_match
|
96
|
+
|
97
|
+
record = {
|
98
|
+
time: line_match[:time],
|
99
|
+
elb: line_match[:elb],
|
100
|
+
client: line_match[:client],
|
101
|
+
client_port: line_match[:client_port],
|
102
|
+
backend: line_match[:backend],
|
103
|
+
backend_port: line_match[:backend_port],
|
104
|
+
request_processing_time: line_match[:request_processing_time],
|
105
|
+
backend_processing_time: line_match[:backend_processing_time],
|
106
|
+
response_processing_time: line_match[:response_processing_time],
|
107
|
+
elb_status_code: line_match[:elb_status_code],
|
108
|
+
backend_status_code: line_match[:backend_status_code],
|
109
|
+
received_bytes: line_match[:received_bytes],
|
110
|
+
sent_bytes: line_match[:sent_bytes],
|
111
|
+
request_method: line_match[:request_method],
|
112
|
+
request_uri: line_match[:request_uri],
|
113
|
+
request_protocol: line_match[:request_protocol],
|
114
|
+
}
|
115
|
+
|
116
|
+
Fluent::Engine.emit("elb.access", Fluent::Engine.now, record_common.merge(record))
|
117
|
+
end
|
118
|
+
# timestamp save
|
119
|
+
@timestamp_file.rewind
|
120
|
+
@timestamp_file.write(obj.last_modified.to_i)
|
121
|
+
@timestamp_file.truncate(@timestamp_file.tell)
|
122
|
+
$log.info "fluent-plugin-elb-log: timestamp save: " + obj.last_modified.to_s
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
class TimerWatcher < Coolio::TimerWatcher
|
127
|
+
def initialize(interval, repeat, &callback)
|
128
|
+
@callback = callback
|
129
|
+
super(interval, repeat)
|
130
|
+
end
|
131
|
+
|
132
|
+
def on_timer
|
133
|
+
@callback.call
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-elb-log
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- shinsaka
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fluentd
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: aws-sdk
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Amazon ELB log input plugin for fluentd
|
70
|
+
email:
|
71
|
+
- shinx1265@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- fluent-plugin-elb-log.gemspec
|
82
|
+
- fluent.conf.sample
|
83
|
+
- lib/fluent/plugin/in_elb_log.rb
|
84
|
+
homepage: https://github.com/shinsaka/fluent-plugin-elb-log
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.0.3
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Amazon ELB log input plugin
|
108
|
+
test_files: []
|