fluent-plugin-cloudwatch-logs 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +51 -3
- data/lib/fluent/plugin/cloudwatch/logs/version.rb +1 -1
- data/lib/fluent/plugin/in_cloudwatch_logs.rb +8 -1
- data/lib/fluent/plugin/out_cloudwatch_logs.rb +9 -3
- data/test/plugin/test_in_cloudwatch_logs.rb +10 -2
- data/test/plugin/test_out_cloudwatch_logs.rb +11 -3
- data/test/test_helper.rb +16 -2
- 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: 9ba82ca82f0ebbaf1df3fb81e42606433d99b520
|
4
|
+
data.tar.gz: e29e78f866b41a7623d27c3d1af5428fd23b00ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12e1b6c8596c9da1fa8945ca8cee1e553b0b5019812c55d2c082c11df74332683f61f7d07d9d99e8a0a51448ae8c92070343d37740f80cb0f1c1279dd66b3dfc
|
7
|
+
data.tar.gz: db5edcaa122522537ad34ec72dbeb49e9f420dc6f29ef02b7f47a24180abde671f0643904710d930e1c415d3c991d2fbf3e12b867589343e186fb9e178700c92
|
data/README.md
CHANGED
@@ -1,11 +1,42 @@
|
|
1
1
|
# fluent-plugin-cloudwatch-logs
|
2
2
|
|
3
|
-
CloudWatch Logs Plugin for Fluentd
|
3
|
+
[CloudWatch Logs](http://aws.amazon.com/blogs/aws/cloudwatch-log-service/) Plugin for Fluentd
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
7
|
$ gem install fluent-plugin-cloudwatch-logs
|
8
8
|
|
9
|
+
## Preparation
|
10
|
+
|
11
|
+
Create IAM user with a policy like the following:
|
12
|
+
|
13
|
+
```json
|
14
|
+
{
|
15
|
+
"Version": "2012-10-17",
|
16
|
+
"Statement": [
|
17
|
+
{
|
18
|
+
"Effect": "Allow",
|
19
|
+
"Action": [
|
20
|
+
"logs:*",
|
21
|
+
"s3:GetObject"
|
22
|
+
],
|
23
|
+
"Resource": [
|
24
|
+
"arn:aws:logs:us-east-1:*:*",
|
25
|
+
"arn:aws:s3:::*"
|
26
|
+
]
|
27
|
+
}
|
28
|
+
]
|
29
|
+
}
|
30
|
+
```
|
31
|
+
|
32
|
+
Set region and credentials:
|
33
|
+
|
34
|
+
```
|
35
|
+
$ export AWS_REGION=us-east-1
|
36
|
+
$ export AWS_ACCESS_KEY_ID="YOUR_ACCESS_KEY"
|
37
|
+
$ export AWS_SECRET_ACCESS_KEY="YOUR_SECRET_ACCESS_KEY"
|
38
|
+
```
|
39
|
+
|
9
40
|
## Example
|
10
41
|
|
11
42
|
Start fluentd:
|
@@ -27,7 +58,8 @@ Fetch sample log from CloudWatch Logs:
|
|
27
58
|
2014-07-17 00:28:02 +0900 test.cloudwatch_logs.in: {"hello":"world"}
|
28
59
|
```
|
29
60
|
|
30
|
-
##
|
61
|
+
## Configuration
|
62
|
+
### out_cloudwatch_logs
|
31
63
|
|
32
64
|
```
|
33
65
|
<match tag>
|
@@ -39,7 +71,12 @@ Fetch sample log from CloudWatch Logs:
|
|
39
71
|
</match>
|
40
72
|
```
|
41
73
|
|
42
|
-
|
74
|
+
* `log_group_name`: name of log group to store logs
|
75
|
+
* `log_stream_name`: name of log stream to store logs
|
76
|
+
* `sequence_token_file`: file to store next sequence token
|
77
|
+
* `auto_create_stream`: to create log group and stream automatically
|
78
|
+
|
79
|
+
### in_cloudwatch_logs
|
43
80
|
|
44
81
|
```
|
45
82
|
<source>
|
@@ -51,6 +88,11 @@ Fetch sample log from CloudWatch Logs:
|
|
51
88
|
</source>
|
52
89
|
```
|
53
90
|
|
91
|
+
* `tag`: fluentd tag
|
92
|
+
* `log_group_name`: name of log group to fetch logs
|
93
|
+
* `log_stream_name`: name of log stream to fetch logs
|
94
|
+
* `state_file`: file to store current state (e.g. next\_forward\_token)
|
95
|
+
|
54
96
|
## Test
|
55
97
|
|
56
98
|
Set credentials:
|
@@ -67,6 +109,12 @@ Run tests:
|
|
67
109
|
$ rake test
|
68
110
|
```
|
69
111
|
|
112
|
+
Or, If you do not want to use IAM roll or ENV(this is just like writing to configuration file) :
|
113
|
+
|
114
|
+
```
|
115
|
+
$ rake aws_key_id=YOUR_ACCESS_KEY aws_sec_key=YOUR_SECRET_KEY region=us-east-1 test
|
116
|
+
```
|
117
|
+
|
70
118
|
## TODO
|
71
119
|
|
72
120
|
* out_cloudwatch_logs
|
@@ -2,6 +2,9 @@ module Fluent
|
|
2
2
|
class CloudwatchLogsInput < Input
|
3
3
|
Plugin.register_input('cloudwatch_logs', self)
|
4
4
|
|
5
|
+
config_param :aws_key_id, :string, :default => nil
|
6
|
+
config_param :aws_sec_key, :string, :default => nil
|
7
|
+
config_param :region, :string, :default => nil
|
5
8
|
config_param :tag, :string
|
6
9
|
config_param :log_group_name, :string
|
7
10
|
config_param :log_stream_name, :string
|
@@ -12,10 +15,14 @@ module Fluent
|
|
12
15
|
super
|
13
16
|
|
14
17
|
require 'aws-sdk-core'
|
15
|
-
@logs = Aws::CloudWatchLogs.new
|
16
18
|
end
|
17
19
|
|
18
20
|
def start
|
21
|
+
options = {}
|
22
|
+
options[:credentials] = Aws::Credentials.new(@aws_key_id, @aws_sec_key) if @aws_key_id && @aws_sec_key
|
23
|
+
options[:region] = @region if @region
|
24
|
+
@logs = Aws::CloudWatchLogs.new(options)
|
25
|
+
|
19
26
|
@finished = false
|
20
27
|
@thread = Thread.new(&method(:run))
|
21
28
|
end
|
@@ -2,6 +2,9 @@ module Fluent
|
|
2
2
|
class CloudwatchLogsOutput < BufferedOutput
|
3
3
|
Plugin.register_output('cloudwatch_logs', self)
|
4
4
|
|
5
|
+
config_param :aws_key_id, :string, :default => nil
|
6
|
+
config_param :aws_sec_key, :string, :default => nil
|
7
|
+
config_param :region, :string, :default => nil
|
5
8
|
config_param :log_group_name, :string
|
6
9
|
config_param :log_stream_name, :string
|
7
10
|
config_param :sequence_token_file, :string
|
@@ -15,12 +18,16 @@ module Fluent
|
|
15
18
|
super
|
16
19
|
|
17
20
|
require 'aws-sdk-core'
|
18
|
-
@logs = Aws::CloudWatchLogs.new
|
19
21
|
end
|
20
22
|
|
21
|
-
def
|
23
|
+
def start
|
22
24
|
super
|
23
25
|
|
26
|
+
options = {}
|
27
|
+
options[:credentials] = Aws::Credentials.new(@aws_key_id, @aws_sec_key) if @aws_key_id && @aws_sec_key
|
28
|
+
options[:region] = @region if @region
|
29
|
+
@logs = Aws::CloudWatchLogs.new(options)
|
30
|
+
|
24
31
|
create_stream if @auto_create_stream
|
25
32
|
end
|
26
33
|
|
@@ -78,4 +85,3 @@ module Fluent
|
|
78
85
|
end
|
79
86
|
end
|
80
87
|
end
|
81
|
-
|
@@ -16,12 +16,18 @@ class CloudwatchLogsInputTest < Test::Unit::TestCase
|
|
16
16
|
def test_configure
|
17
17
|
d = create_driver(<<-EOC)
|
18
18
|
type cloudwatch_logs
|
19
|
+
aws_key_id test_id
|
20
|
+
aws_sec_key test_key
|
21
|
+
region us-east-1
|
19
22
|
tag test
|
20
23
|
log_group_name group
|
21
24
|
log_stream_name stream
|
22
25
|
state_file /tmp/state
|
23
26
|
EOC
|
24
27
|
|
28
|
+
assert_equal('test_id', d.instance.aws_key_id)
|
29
|
+
assert_equal('test_key', d.instance.aws_sec_key)
|
30
|
+
assert_equal('us-east-1', d.instance.region)
|
25
31
|
assert_equal('test', d.instance.tag)
|
26
32
|
assert_equal('group', d.instance.log_group_name)
|
27
33
|
assert_equal('stream', d.instance.log_stream_name)
|
@@ -43,7 +49,7 @@ class CloudwatchLogsInputTest < Test::Unit::TestCase
|
|
43
49
|
d.run do
|
44
50
|
sleep 5
|
45
51
|
end
|
46
|
-
|
52
|
+
|
47
53
|
emits = d.emits
|
48
54
|
assert_equal(2, emits.size)
|
49
55
|
assert_equal(['test', (time_ms / 1000).floor, {'cloudwatch' => 'logs1'}], emits[0])
|
@@ -58,6 +64,9 @@ class CloudwatchLogsInputTest < Test::Unit::TestCase
|
|
58
64
|
log_group_name #{log_group_name}
|
59
65
|
log_stream_name #{log_stream_name}
|
60
66
|
state_file /tmp/state
|
67
|
+
#{aws_key_id}
|
68
|
+
#{aws_sec_key}
|
69
|
+
#{region}
|
61
70
|
EOC
|
62
71
|
end
|
63
72
|
|
@@ -65,4 +74,3 @@ class CloudwatchLogsInputTest < Test::Unit::TestCase
|
|
65
74
|
Fluent::Test::InputTestDriver.new(Fluent::CloudwatchLogsInput).configure(conf)
|
66
75
|
end
|
67
76
|
end
|
68
|
-
|
@@ -8,24 +8,29 @@ class CloudwatchLogsOutputTest < Test::Unit::TestCase
|
|
8
8
|
Fluent::Test.setup
|
9
9
|
require 'fluent/plugin/out_cloudwatch_logs'
|
10
10
|
|
11
|
-
@logs = Aws::CloudWatchLogs.new
|
12
11
|
end
|
13
12
|
|
14
13
|
def teardown
|
15
14
|
clear_log_group
|
16
15
|
FileUtils.rm_f(sequence_token_file)
|
17
16
|
end
|
18
|
-
|
17
|
+
|
19
18
|
|
20
19
|
def test_configure
|
21
20
|
d = create_driver(<<-EOC)
|
22
21
|
type cloudwatch_logs
|
22
|
+
aws_key_id test_id
|
23
|
+
aws_sec_key test_key
|
24
|
+
region us-east-1
|
23
25
|
log_group_name test_group
|
24
26
|
log_stream_name test_stream
|
25
27
|
sequence_token_file /tmp/sq
|
26
28
|
auto_create_stream false
|
27
29
|
EOC
|
28
30
|
|
31
|
+
assert_equal('test_id', d.instance.aws_key_id)
|
32
|
+
assert_equal('test_key', d.instance.aws_sec_key)
|
33
|
+
assert_equal('us-east-1', d.instance.region)
|
29
34
|
assert_equal('test_group', d.instance.log_group_name)
|
30
35
|
assert_equal('test_stream', d.instance.log_stream_name)
|
31
36
|
assert_equal('/tmp/sq', d.instance.sequence_token_file)
|
@@ -41,7 +46,7 @@ class CloudwatchLogsOutputTest < Test::Unit::TestCase
|
|
41
46
|
d.emit({'cloudwatch' => 'logs2'}, time.to_i + 1)
|
42
47
|
d.run
|
43
48
|
|
44
|
-
sleep
|
49
|
+
sleep 20
|
45
50
|
|
46
51
|
events = get_log_events
|
47
52
|
assert_equal(2, events.size)
|
@@ -59,6 +64,9 @@ class CloudwatchLogsOutputTest < Test::Unit::TestCase
|
|
59
64
|
log_stream_name #{log_stream_name}
|
60
65
|
sequence_token_file #{sequence_token_file}
|
61
66
|
auto_create_stream true
|
67
|
+
#{aws_key_id}
|
68
|
+
#{aws_sec_key}
|
69
|
+
#{region}
|
62
70
|
EOC
|
63
71
|
end
|
64
72
|
|
data/test/test_helper.rb
CHANGED
@@ -6,13 +6,28 @@ require 'aws-sdk-core'
|
|
6
6
|
module CloudwatchLogsTestHelper
|
7
7
|
private
|
8
8
|
def logs
|
9
|
-
|
9
|
+
options = {}
|
10
|
+
options[:credentials] = Aws::Credentials.new(ENV['aws_key_id'], ENV['aws_sec_key']) if ENV['aws_key_id'] && ENV['aws_sec_key']
|
11
|
+
options[:region] = ENV['region'] if ENV['region']
|
12
|
+
@logs ||= Aws::CloudWatchLogs.new(options)
|
10
13
|
end
|
11
14
|
|
12
15
|
def log_group_name
|
13
16
|
@log_group_name ||= "fluent-plugin-cloudwatch-test-#{Time.now.to_f}"
|
14
17
|
end
|
15
18
|
|
19
|
+
def aws_key_id
|
20
|
+
"aws_key_id #{ENV['aws_key_id']}" if ENV['aws_key_id']
|
21
|
+
end
|
22
|
+
|
23
|
+
def aws_sec_key
|
24
|
+
"aws_sec_key #{ENV['aws_sec_key']}" if ENV['aws_sec_key']
|
25
|
+
end
|
26
|
+
|
27
|
+
def region
|
28
|
+
"region #{ENV['region']}" if ENV['region']
|
29
|
+
end
|
30
|
+
|
16
31
|
def log_stream_name
|
17
32
|
if !@log_stream_name
|
18
33
|
new_log_stream
|
@@ -57,4 +72,3 @@ module CloudwatchLogsTestHelper
|
|
57
72
|
logs.put_log_events(args)
|
58
73
|
end
|
59
74
|
end
|
60
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-cloudwatch-logs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryota Arai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|