fluent-plugin-cloudwatch-put 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.travis.yml +6 -0
- data/Gemfile +5 -0
- data/LICENSE +21 -0
- data/README.md +197 -0
- data/Rakefile +13 -0
- data/fluent-plugin-cloudwatch-put.gemspec +30 -0
- data/lib/fluent/plugin/out_cloudwatch_put.rb +252 -0
- data/test/helper.rb +9 -0
- data/test/plugin/test_out_cloudwatch_put.rb +245 -0
- metadata +146 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d384c9797d32c4f7342de78a6354b35112c7cce6
|
4
|
+
data.tar.gz: f37a80601492563df64e5e77c2428ca22e72bd83
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c9d30d0c594b9317f56c728f29745f78a8763bb36273556da7c57b9040e95c1081759779ff0102a9a55844e7810011dc921be452f412834836a8c3b9606cd797
|
7
|
+
data.tar.gz: be243f0ef19d60b0eaffea326f9450b7a86fe878e00233408dbecb7cfa44246b056da77efe6df5c1f1330edfcc6aca697ac22477d95e3a9e9ab72f1276ff4d2f
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 joker1007
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
# fluent-plugin-cloudwatch-put
|
2
|
+
[![Build Status](https://travis-ci.org/joker1007/fluent-plugin-cloudwatch-put.svg?branch=master)](https://travis-ci.org/joker1007/fluent-plugin-cloudwatch-put)
|
3
|
+
|
4
|
+
[Fluentd](http://fluentd.org/) output plugin to put metric data to AWS CloudWatch.
|
5
|
+
|
6
|
+
This plugin for fluentd-0.14.x or later.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
### RubyGems
|
11
|
+
|
12
|
+
```
|
13
|
+
$ gem install fluent-plugin-cloudwatch-put
|
14
|
+
```
|
15
|
+
|
16
|
+
### Bundler
|
17
|
+
|
18
|
+
Add following line to your Gemfile:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
gem "fluent-plugin-cloudwatch-put"
|
22
|
+
```
|
23
|
+
|
24
|
+
And then execute:
|
25
|
+
|
26
|
+
```
|
27
|
+
$ bundle
|
28
|
+
```
|
29
|
+
|
30
|
+
## Plugin helpers
|
31
|
+
|
32
|
+
* inject
|
33
|
+
|
34
|
+
* See also: Fluent::Plugin::Output
|
35
|
+
|
36
|
+
## Configuration
|
37
|
+
|
38
|
+
```
|
39
|
+
<match cloudwatch.metric_name>
|
40
|
+
@type cloudwatch_put
|
41
|
+
|
42
|
+
<buffer tag, key1>
|
43
|
+
path cloudwatch.*.buffer
|
44
|
+
|
45
|
+
flush_interval 1m
|
46
|
+
</buffer>
|
47
|
+
|
48
|
+
aws_key_id "#{ENV["AWS_ACCESS_KEY_ID"]}"
|
49
|
+
aws_sec_key "#{ENV["AWS_SECRET_ACCESS_KEY"]}"
|
50
|
+
|
51
|
+
region ap-northeast-1
|
52
|
+
|
53
|
+
namespace "Dummy/Namespace"
|
54
|
+
metric_name ${tag[1]}
|
55
|
+
unit Count
|
56
|
+
value_key value
|
57
|
+
|
58
|
+
use_statistic_sets
|
59
|
+
|
60
|
+
<dimensions>
|
61
|
+
name method
|
62
|
+
value ${key1}
|
63
|
+
</dimensions>
|
64
|
+
</match>
|
65
|
+
```
|
66
|
+
|
67
|
+
### namespace (string) (required)
|
68
|
+
|
69
|
+
CloudWatch metric namespace (support placeholder)
|
70
|
+
|
71
|
+
### metric_name (string) (required)
|
72
|
+
|
73
|
+
CloudWatch metric name (support placeholder)
|
74
|
+
|
75
|
+
### unit (string) (required)
|
76
|
+
|
77
|
+
CloudWatch metric unit (support placeholder)
|
78
|
+
|
79
|
+
### value_key (string) (required)
|
80
|
+
|
81
|
+
Use this key as metric value
|
82
|
+
|
83
|
+
### storage_resolution (integer) (optional)
|
84
|
+
|
85
|
+
Cloudwatch storage resolution
|
86
|
+
|
87
|
+
Default value: `60`.
|
88
|
+
|
89
|
+
### use_statistic_sets (bool) (optional)
|
90
|
+
|
91
|
+
If this is true, aggregates record chunk before put metric
|
92
|
+
|
93
|
+
|
94
|
+
### \<dimensions\> section (required) (multiple)
|
95
|
+
|
96
|
+
#### name (string) (required)
|
97
|
+
|
98
|
+
Dimension name (support placeholder)
|
99
|
+
|
100
|
+
#### key (string) (optional)
|
101
|
+
|
102
|
+
Use this key as dimension value. If use_statistic_sets is true, this param is not supported. Use `value`
|
103
|
+
|
104
|
+
#### value (string) (optional)
|
105
|
+
|
106
|
+
Use static value as dimension value (support placeholder)
|
107
|
+
|
108
|
+
|
109
|
+
### \<buffer\> section (optional) (multiple)
|
110
|
+
|
111
|
+
#### chunk_limit_size (optional)
|
112
|
+
|
113
|
+
Default value: `30720`.
|
114
|
+
|
115
|
+
#### chunk_limit_records (optional)
|
116
|
+
|
117
|
+
Default value: `20`.
|
118
|
+
|
119
|
+
## Configuration for Authentication
|
120
|
+
|
121
|
+
### aws_key_id (string) (optional)
|
122
|
+
|
123
|
+
AWS access key id
|
124
|
+
|
125
|
+
### aws_sec_key (string) (optional)
|
126
|
+
|
127
|
+
AWS secret key.
|
128
|
+
|
129
|
+
### region (string) (optional)
|
130
|
+
|
131
|
+
region name
|
132
|
+
|
133
|
+
Default value: `us-east-1`.
|
134
|
+
|
135
|
+
### proxy_uri (string) (optional)
|
136
|
+
|
137
|
+
URI of proxy environment
|
138
|
+
|
139
|
+
### \<assume_role_credentials\> section (optional) (single)
|
140
|
+
|
141
|
+
#### role_arn (string) (required)
|
142
|
+
|
143
|
+
The Amazon Resource Name (ARN) of the role to assume
|
144
|
+
|
145
|
+
#### role_session_name (string) (required)
|
146
|
+
|
147
|
+
An identifier for the assumed role session
|
148
|
+
|
149
|
+
#### policy (string) (optional)
|
150
|
+
|
151
|
+
An IAM policy in JSON format
|
152
|
+
|
153
|
+
#### duration_seconds (integer) (optional)
|
154
|
+
|
155
|
+
The duration, in seconds, of the role session (900-3600)
|
156
|
+
|
157
|
+
#### external_id (string) (optional)
|
158
|
+
|
159
|
+
A unique identifier that is used by third parties when assuming roles in their customers' accounts.
|
160
|
+
|
161
|
+
### \<instance_profile_credentials\> section (optional) (single)
|
162
|
+
|
163
|
+
#### retries (integer) (optional)
|
164
|
+
|
165
|
+
Number of times to retry when retrieving credentials
|
166
|
+
|
167
|
+
#### ip_address (string) (optional)
|
168
|
+
|
169
|
+
IP address (default:169.254.169.254)
|
170
|
+
|
171
|
+
#### port (integer) (optional)
|
172
|
+
|
173
|
+
Port number (default:80)
|
174
|
+
|
175
|
+
#### http_open_timeout (float) (optional)
|
176
|
+
|
177
|
+
Number of seconds to wait for the connection to open
|
178
|
+
|
179
|
+
#### http_read_timeout (float) (optional)
|
180
|
+
|
181
|
+
Number of seconds to wait for one block to be read
|
182
|
+
|
183
|
+
### \<shared_credentials\> section (optional) (single)
|
184
|
+
|
185
|
+
#### path (string) (optional)
|
186
|
+
|
187
|
+
Path to the shared file. (default: $HOME/.aws/credentials)
|
188
|
+
|
189
|
+
#### profile_name (string) (optional)
|
190
|
+
|
191
|
+
Profile name. Default to 'default' or ENV['AWS_PROFILE']
|
192
|
+
|
193
|
+
## Copyright
|
194
|
+
|
195
|
+
* Copyright(c) 2017- joker1007
|
196
|
+
* License
|
197
|
+
* MIT License
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "bundler"
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs.push("lib", "test")
|
8
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
9
|
+
t.verbose = true
|
10
|
+
t.warning = true
|
11
|
+
end
|
12
|
+
|
13
|
+
task default: [:test]
|
@@ -0,0 +1,30 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "fluent-plugin-cloudwatch-put"
|
6
|
+
spec.version = "0.1.0"
|
7
|
+
spec.authors = ["joker1007"]
|
8
|
+
spec.email = ["kakyoin.hierophant@gmail.com"]
|
9
|
+
|
10
|
+
spec.summary = %q{Cloudwatch put metric plugin for fluentd.}
|
11
|
+
spec.description = %q{Cloudwatch put metric plugin for fluentd.}
|
12
|
+
spec.homepage = "https://github.com/joker1007/fluent-plugin-cloudwatch-put"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
test_files, files = `git ls-files -z`.split("\x0").partition do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.files = files
|
19
|
+
spec.executables = files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = test_files
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
24
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
25
|
+
spec.add_development_dependency "test-unit", "~> 3.0"
|
26
|
+
spec.add_development_dependency "test-unit-rr"
|
27
|
+
|
28
|
+
spec.add_runtime_dependency "fluentd", [">= 0.14.10", "< 2"]
|
29
|
+
spec.add_runtime_dependency "aws-sdk", ">= 2"
|
30
|
+
end
|
@@ -0,0 +1,252 @@
|
|
1
|
+
require "fluent/plugin/output"
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "aws-sdk-cloudwatch"
|
5
|
+
rescue LoadError
|
6
|
+
require "aws-sdk"
|
7
|
+
end
|
8
|
+
|
9
|
+
module Fluent
|
10
|
+
module Plugin
|
11
|
+
class CloudWatchPutOutput < Fluent::Plugin::Output
|
12
|
+
Fluent::Plugin.register_output("cloudwatch_put", self)
|
13
|
+
|
14
|
+
helpers :inject
|
15
|
+
|
16
|
+
# Credential Configs from fluent-plugin-s3
|
17
|
+
# Apache License, version 2.0
|
18
|
+
desc "AWS access key id"
|
19
|
+
config_param :aws_key_id, :string, default: nil, secret: true
|
20
|
+
desc "AWS secret key."
|
21
|
+
config_param :aws_sec_key, :string, default: nil, secret: true
|
22
|
+
config_section :assume_role_credentials, multi: false do
|
23
|
+
desc "The Amazon Resource Name (ARN) of the role to assume"
|
24
|
+
config_param :role_arn, :string, secret: true
|
25
|
+
desc "An identifier for the assumed role session"
|
26
|
+
config_param :role_session_name, :string
|
27
|
+
desc "An IAM policy in JSON format"
|
28
|
+
config_param :policy, :string, default: nil
|
29
|
+
desc "The duration, in seconds, of the role session (900-3600)"
|
30
|
+
config_param :duration_seconds, :integer, default: nil
|
31
|
+
desc "A unique identifier that is used by third parties when assuming roles in their customers' accounts."
|
32
|
+
config_param :external_id, :string, default: nil, secret: true
|
33
|
+
end
|
34
|
+
config_section :instance_profile_credentials, multi: false do
|
35
|
+
desc "Number of times to retry when retrieving credentials"
|
36
|
+
config_param :retries, :integer, default: nil
|
37
|
+
desc "IP address (default:169.254.169.254)"
|
38
|
+
config_param :ip_address, :string, default: nil
|
39
|
+
desc "Port number (default:80)"
|
40
|
+
config_param :port, :integer, default: nil
|
41
|
+
desc "Number of seconds to wait for the connection to open"
|
42
|
+
config_param :http_open_timeout, :float, default: nil
|
43
|
+
desc "Number of seconds to wait for one block to be read"
|
44
|
+
config_param :http_read_timeout, :float, default: nil
|
45
|
+
# config_param :delay, :integer or :proc, :default => nil
|
46
|
+
# config_param :http_degub_output, :io, :default => nil
|
47
|
+
end
|
48
|
+
config_section :shared_credentials, multi: false do
|
49
|
+
desc "Path to the shared file. (default: $HOME/.aws/credentials)"
|
50
|
+
config_param :path, :string, default: nil
|
51
|
+
desc "Profile name. Default to 'default' or ENV['AWS_PROFILE']"
|
52
|
+
config_param :profile_name, :string, default: nil
|
53
|
+
end
|
54
|
+
|
55
|
+
desc "region name"
|
56
|
+
config_param :region, :string, default: ENV["AWS_REGION"] || "us-east-1"
|
57
|
+
|
58
|
+
desc "URI of proxy environment"
|
59
|
+
config_param :proxy_uri, :string, default: nil
|
60
|
+
|
61
|
+
desc "CloudWatch metric namespace (support placeholder)"
|
62
|
+
config_param :namespace, :string
|
63
|
+
desc "CloudWatch metric name (support placeholder)"
|
64
|
+
config_param :metric_name, :string
|
65
|
+
desc "CloudWatch metric unit (support placeholder)"
|
66
|
+
config_param :unit, :string
|
67
|
+
|
68
|
+
desc "Definition of dimension"
|
69
|
+
config_section :dimensions, multi: true, required: true do
|
70
|
+
desc "Dimension name (support placeholder)"
|
71
|
+
config_param :name, :string
|
72
|
+
desc "Use this key as dimension value. If use_statistic_sets is true, this param is not supported. Use `value`"
|
73
|
+
config_param :key, :string, default: nil
|
74
|
+
desc "Use static value as dimension value (support placeholder)"
|
75
|
+
config_param :value, :string, default: nil
|
76
|
+
end
|
77
|
+
|
78
|
+
desc "Use this key as metric value"
|
79
|
+
config_param :value_key, :string
|
80
|
+
|
81
|
+
desc "Cloudwatch storage resolution"
|
82
|
+
config_param :storage_resolution, :integer, default: 60
|
83
|
+
|
84
|
+
desc "If this is true, aggregates record chunk before put metric"
|
85
|
+
config_param :use_statistic_sets, :bool, default: false
|
86
|
+
|
87
|
+
config_section :buffer do
|
88
|
+
config_set_default :chunk_limit_size, 30 * 1024
|
89
|
+
config_set_default :chunk_limit_records, 20 # max record size of metric_data payload
|
90
|
+
end
|
91
|
+
|
92
|
+
attr_reader :cloudwatch
|
93
|
+
|
94
|
+
def configure(conf)
|
95
|
+
super
|
96
|
+
|
97
|
+
@dimensions.each do |d|
|
98
|
+
unless d.key.nil? ^ d.value.nil?
|
99
|
+
raise Fluent::ConfigError, "'Either dimensions[key]' or 'dimensions[value]' must be set"
|
100
|
+
end
|
101
|
+
|
102
|
+
if @use_statistic_sets && d.key
|
103
|
+
raise Fluent::ConfigError, "If 'use_statistic_sets' is true, dimensions[key] is not supportted"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
placeholder_params = "namespace=#{@namespace}/metric_name=#{@metric_name}/unit=#{@unit}/dimensions[name]=#{@dimensions.map(&:name).join(",")}/dimensions[value]=#{@dimensions.map(&:value).join(",")}"
|
108
|
+
placeholder_validate!(:cloudwatch_put, placeholder_params)
|
109
|
+
end
|
110
|
+
|
111
|
+
def start
|
112
|
+
super
|
113
|
+
|
114
|
+
options = setup_credentials
|
115
|
+
options[:region] = @region if @region
|
116
|
+
options[:http_proxy] = @proxy_uri if @proxy_uri
|
117
|
+
log.on_trace do
|
118
|
+
options[:http_wire_trace] = true
|
119
|
+
options[:logger] = log
|
120
|
+
end
|
121
|
+
|
122
|
+
@cloudwatch = Aws::CloudWatch::Client.new(options)
|
123
|
+
end
|
124
|
+
|
125
|
+
def write(chunk)
|
126
|
+
if @use_statistic_sets
|
127
|
+
metric_data = build_statistic_metric_data(chunk)
|
128
|
+
else
|
129
|
+
metric_data = build_metric_data(chunk)
|
130
|
+
end
|
131
|
+
|
132
|
+
namespace = extract_placeholders(@namespace, chunk.metadata)
|
133
|
+
log.debug "Put metric to #{namespace}, count=#{metric_data.size}"
|
134
|
+
log.on_trace do
|
135
|
+
log.trace metric_data.to_json
|
136
|
+
end
|
137
|
+
@cloudwatch.put_metric_data({
|
138
|
+
namespace: namespace,
|
139
|
+
metric_data: metric_data,
|
140
|
+
})
|
141
|
+
end
|
142
|
+
|
143
|
+
private
|
144
|
+
|
145
|
+
def base_metric_data(meta)
|
146
|
+
{
|
147
|
+
metric_name: extract_placeholders(@metric_name, meta),
|
148
|
+
unit: extract_placeholders(@unit, meta),
|
149
|
+
storage_resolution: @storage_resolution,
|
150
|
+
}
|
151
|
+
end
|
152
|
+
|
153
|
+
def build_metric_data(chunk)
|
154
|
+
meta = chunk.metadata
|
155
|
+
metric_data = []
|
156
|
+
chunk.msgpack_each do |(timestamp, record)|
|
157
|
+
metric_data << base_metric_data(meta).merge({
|
158
|
+
dimensions: @dimensions.map { |d|
|
159
|
+
{
|
160
|
+
name: extract_placeholders(d.name, meta),
|
161
|
+
value: d.key ? record[d.key] : extract_placeholders(d.value, meta),
|
162
|
+
}
|
163
|
+
},
|
164
|
+
value: record[@value_key].to_f,
|
165
|
+
timestamp: Time.at(timestamp)
|
166
|
+
})
|
167
|
+
end
|
168
|
+
metric_data
|
169
|
+
end
|
170
|
+
|
171
|
+
def build_statistic_metric_data(chunk)
|
172
|
+
meta = chunk.metadata
|
173
|
+
values = []
|
174
|
+
timestamps = []
|
175
|
+
chunk.msgpack_each do |(timestamp, record)|
|
176
|
+
values << record[@value_key].to_f
|
177
|
+
timestamps << timestamp
|
178
|
+
end
|
179
|
+
|
180
|
+
[
|
181
|
+
base_metric_data(meta).merge({
|
182
|
+
dimensions: @dimensions.map { |d|
|
183
|
+
{
|
184
|
+
name: extract_placeholders(d.name, meta),
|
185
|
+
value: extract_placeholders(d.value, meta),
|
186
|
+
}
|
187
|
+
},
|
188
|
+
statistic_values: {
|
189
|
+
sample_count: values.size,
|
190
|
+
sum: values.inject(&:+),
|
191
|
+
minimum: values.min,
|
192
|
+
maximum: values.max,
|
193
|
+
},
|
194
|
+
timestamp: Time.at(timestamps.max)
|
195
|
+
})
|
196
|
+
]
|
197
|
+
end
|
198
|
+
|
199
|
+
# Credential Configs from fluent-plugin-s3
|
200
|
+
# Apache License, version 2.0
|
201
|
+
def setup_credentials
|
202
|
+
options = {}
|
203
|
+
credentials_options = {}
|
204
|
+
case
|
205
|
+
when @aws_key_id && @aws_sec_key
|
206
|
+
options[:access_key_id] = @aws_key_id
|
207
|
+
options[:secret_access_key] = @aws_sec_key
|
208
|
+
when @assume_role_credentials
|
209
|
+
c = @assume_role_credentials
|
210
|
+
credentials_options[:role_arn] = c.role_arn
|
211
|
+
credentials_options[:role_session_name] = c.role_session_name
|
212
|
+
credentials_options[:policy] = c.policy if c.policy
|
213
|
+
credentials_options[:duration_seconds] = c.duration_seconds if c.duration_seconds
|
214
|
+
credentials_options[:external_id] = c.external_id if c.external_id
|
215
|
+
if @region
|
216
|
+
credentials_options[:client] = Aws::STS::Client.new(region: @region)
|
217
|
+
end
|
218
|
+
options[:credentials] = Aws::AssumeRoleCredentials.new(credentials_options)
|
219
|
+
when @instance_profile_credentials
|
220
|
+
c = @instance_profile_credentials
|
221
|
+
credentials_options[:retries] = c.retries if c.retries
|
222
|
+
credentials_options[:ip_address] = c.ip_address if c.ip_address
|
223
|
+
credentials_options[:port] = c.port if c.port
|
224
|
+
credentials_options[:http_open_timeout] = c.http_open_timeout if c.http_open_timeout
|
225
|
+
credentials_options[:http_read_timeout] = c.http_read_timeout if c.http_read_timeout
|
226
|
+
if ENV["AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"]
|
227
|
+
options[:credentials] = Aws::ECSCredentials.new(credentials_options)
|
228
|
+
else
|
229
|
+
options[:credentials] = Aws::InstanceProfileCredentials.new(credentials_options)
|
230
|
+
end
|
231
|
+
when @shared_credentials
|
232
|
+
c = @shared_credentials
|
233
|
+
credentials_options[:path] = c.path if c.path
|
234
|
+
credentials_options[:profile_name] = c.profile_name if c.profile_name
|
235
|
+
options[:credentials] = Aws::SharedCredentials.new(credentials_options)
|
236
|
+
when @aws_iam_retries
|
237
|
+
log.warn("'aws_iam_retries' parameter is deprecated. Use 'instance_profile_credentials' instead")
|
238
|
+
credentials_options[:retries] = @aws_iam_retries
|
239
|
+
if ENV["AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"]
|
240
|
+
options[:credentials] = Aws::ECSCredentials.new(credentials_options)
|
241
|
+
else
|
242
|
+
options[:credentials] = Aws::InstanceProfileCredentials.new(credentials_options)
|
243
|
+
end
|
244
|
+
else
|
245
|
+
# Use default credentials
|
246
|
+
# See http://docs.aws.amazon.com/sdkforruby/api/Aws/S3/Client.html
|
247
|
+
end
|
248
|
+
options
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.expand_path("../../", __FILE__))
|
2
|
+
require "test-unit"
|
3
|
+
require "test/unit/rr"
|
4
|
+
require "fluent/test"
|
5
|
+
require "fluent/test/driver/output"
|
6
|
+
require "fluent/test/helpers"
|
7
|
+
|
8
|
+
Test::Unit::TestCase.include(Fluent::Test::Helpers)
|
9
|
+
Test::Unit::TestCase.extend(Fluent::Test::Helpers)
|
@@ -0,0 +1,245 @@
|
|
1
|
+
require "helper"
|
2
|
+
require "fluent/plugin/out_cloudwatch_put.rb"
|
3
|
+
|
4
|
+
class CloudWatchPutOutputTest < Test::Unit::TestCase
|
5
|
+
setup do
|
6
|
+
Fluent::Test.setup
|
7
|
+
end
|
8
|
+
|
9
|
+
DEFAULT_CONF = %q{
|
10
|
+
region ap-northeast-1
|
11
|
+
namespace Test
|
12
|
+
metric_name MetricName
|
13
|
+
unit Count
|
14
|
+
|
15
|
+
<dimensions>
|
16
|
+
name dim1
|
17
|
+
key key1
|
18
|
+
</dimensions>
|
19
|
+
|
20
|
+
<dimensions>
|
21
|
+
name dim2
|
22
|
+
key key2
|
23
|
+
</dimensions>
|
24
|
+
|
25
|
+
value_key key3
|
26
|
+
|
27
|
+
aws_key_id dummy
|
28
|
+
aws_sec_key dummy
|
29
|
+
}
|
30
|
+
|
31
|
+
test "configure" do
|
32
|
+
d = create_driver
|
33
|
+
assert { d.instance.buffer.chunk_limit_size == 30 * 1024 }
|
34
|
+
assert { d.instance.dimensions.size == 2 }
|
35
|
+
assert { d.instance.dimensions[0].name == "dim1" }
|
36
|
+
assert { d.instance.dimensions[1].name == "dim2" }
|
37
|
+
end
|
38
|
+
|
39
|
+
test "write" do
|
40
|
+
d = create_driver
|
41
|
+
now = Time.now.to_i
|
42
|
+
|
43
|
+
d.instance.start
|
44
|
+
|
45
|
+
mock(d.instance.cloudwatch).put_metric_data({
|
46
|
+
namespace: "Test",
|
47
|
+
metric_data: [
|
48
|
+
{
|
49
|
+
metric_name: "MetricName",
|
50
|
+
dimensions: [
|
51
|
+
{
|
52
|
+
name: "dim1",
|
53
|
+
value: "val1",
|
54
|
+
},
|
55
|
+
{
|
56
|
+
name: "dim2",
|
57
|
+
value: "val2",
|
58
|
+
},
|
59
|
+
],
|
60
|
+
timestamp: Time.at(now),
|
61
|
+
value: 1.0,
|
62
|
+
unit: "Count",
|
63
|
+
storage_resolution: 60,
|
64
|
+
},
|
65
|
+
{
|
66
|
+
metric_name: "MetricName",
|
67
|
+
dimensions: [
|
68
|
+
{
|
69
|
+
name: "dim1",
|
70
|
+
value: "val1",
|
71
|
+
},
|
72
|
+
{
|
73
|
+
name: "dim2",
|
74
|
+
value: "val2",
|
75
|
+
},
|
76
|
+
],
|
77
|
+
timestamp: Time.at(now),
|
78
|
+
value: 2.0,
|
79
|
+
unit: "Count",
|
80
|
+
storage_resolution: 60,
|
81
|
+
},
|
82
|
+
{
|
83
|
+
metric_name: "MetricName",
|
84
|
+
dimensions: [
|
85
|
+
{
|
86
|
+
name: "dim1",
|
87
|
+
value: "val1",
|
88
|
+
},
|
89
|
+
{
|
90
|
+
name: "dim2",
|
91
|
+
value: "val2",
|
92
|
+
},
|
93
|
+
],
|
94
|
+
timestamp: Time.at(now),
|
95
|
+
value: 3.0,
|
96
|
+
unit: "Count",
|
97
|
+
storage_resolution: 60,
|
98
|
+
},
|
99
|
+
]
|
100
|
+
})
|
101
|
+
|
102
|
+
d.run do
|
103
|
+
d.feed('tag', now, {"key1" => "val1", "key2" => "val2", "key3" => 1})
|
104
|
+
d.feed('tag', now, {"key1" => "val1", "key2" => "val2", "key3" => 2})
|
105
|
+
d.feed('tag', now, {"key1" => "val1", "key2" => "val2", "key3" => 3})
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
test "write (use_statistic_sets)" do
|
110
|
+
conf = %q{
|
111
|
+
region ap-northeast-1
|
112
|
+
namespace Test
|
113
|
+
metric_name MetricName
|
114
|
+
unit Count
|
115
|
+
|
116
|
+
use_statistic_sets
|
117
|
+
|
118
|
+
<dimensions>
|
119
|
+
name dim1
|
120
|
+
value dim_value1
|
121
|
+
</dimensions>
|
122
|
+
|
123
|
+
<dimensions>
|
124
|
+
name dim2
|
125
|
+
value dim_value2
|
126
|
+
</dimensions>
|
127
|
+
|
128
|
+
value_key key3
|
129
|
+
|
130
|
+
aws_key_id dummy
|
131
|
+
aws_sec_key dummy
|
132
|
+
}
|
133
|
+
d = create_driver(conf)
|
134
|
+
now = Time.now.to_i
|
135
|
+
|
136
|
+
d.instance.start
|
137
|
+
|
138
|
+
mock(d.instance.cloudwatch).put_metric_data({
|
139
|
+
namespace: "Test",
|
140
|
+
metric_data: [
|
141
|
+
{
|
142
|
+
metric_name: "MetricName",
|
143
|
+
dimensions: [
|
144
|
+
{
|
145
|
+
name: "dim1",
|
146
|
+
value: "dim_value1",
|
147
|
+
},
|
148
|
+
{
|
149
|
+
name: "dim2",
|
150
|
+
value: "dim_value2",
|
151
|
+
},
|
152
|
+
],
|
153
|
+
timestamp: Time.at(now),
|
154
|
+
statistic_values: {
|
155
|
+
sample_count: 3,
|
156
|
+
sum: 6.0,
|
157
|
+
minimum: 1.0,
|
158
|
+
maximum: 3.0,
|
159
|
+
},
|
160
|
+
unit: "Count",
|
161
|
+
storage_resolution: 60,
|
162
|
+
},
|
163
|
+
]
|
164
|
+
})
|
165
|
+
|
166
|
+
d.run do
|
167
|
+
d.feed('tag', now, {"key1" => "val1", "key2" => "val2", "key3" => 1})
|
168
|
+
d.feed('tag', now, {"key1" => "val1", "key2" => "val2", "key3" => 2})
|
169
|
+
d.feed('tag', now, {"key1" => "val1", "key2" => "val2", "key3" => 3})
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
test "write (use_statistic_sets) (placeholder)" do
|
174
|
+
conf = %q{
|
175
|
+
<buffer tag, key1, key2>
|
176
|
+
</buffer>
|
177
|
+
|
178
|
+
region ap-northeast-1
|
179
|
+
namespace ${tag[0]}
|
180
|
+
metric_name ${tag[1]}
|
181
|
+
unit Count
|
182
|
+
|
183
|
+
use_statistic_sets
|
184
|
+
|
185
|
+
<dimensions>
|
186
|
+
name dim1
|
187
|
+
value ${key1}
|
188
|
+
</dimensions>
|
189
|
+
|
190
|
+
<dimensions>
|
191
|
+
name dim2
|
192
|
+
value ${key2}
|
193
|
+
</dimensions>
|
194
|
+
|
195
|
+
value_key key3
|
196
|
+
|
197
|
+
aws_key_id dummy
|
198
|
+
aws_sec_key dummy
|
199
|
+
}
|
200
|
+
d = create_driver(conf)
|
201
|
+
now = Time.now.to_i
|
202
|
+
|
203
|
+
d.instance.start
|
204
|
+
|
205
|
+
mock(d.instance.cloudwatch).put_metric_data({
|
206
|
+
namespace: "namespace",
|
207
|
+
metric_data: [
|
208
|
+
{
|
209
|
+
metric_name: "metric_name",
|
210
|
+
dimensions: [
|
211
|
+
{
|
212
|
+
name: "dim1",
|
213
|
+
value: "val1",
|
214
|
+
},
|
215
|
+
{
|
216
|
+
name: "dim2",
|
217
|
+
value: "val2",
|
218
|
+
},
|
219
|
+
],
|
220
|
+
timestamp: Time.at(now),
|
221
|
+
statistic_values: {
|
222
|
+
sample_count: 3,
|
223
|
+
sum: 6.0,
|
224
|
+
minimum: 1.0,
|
225
|
+
maximum: 3.0,
|
226
|
+
},
|
227
|
+
unit: "Count",
|
228
|
+
storage_resolution: 60,
|
229
|
+
},
|
230
|
+
]
|
231
|
+
})
|
232
|
+
|
233
|
+
d.run do
|
234
|
+
d.feed('namespace.metric_name', now, {"key1" => "val1", "key2" => "val2", "key3" => 1})
|
235
|
+
d.feed('namespace.metric_name', now, {"key1" => "val1", "key2" => "val2", "key3" => 2})
|
236
|
+
d.feed('namespace.metric_name', now, {"key1" => "val1", "key2" => "val2", "key3" => 3})
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
private
|
241
|
+
|
242
|
+
def create_driver(conf = DEFAULT_CONF)
|
243
|
+
Fluent::Test::Driver::Output.new(Fluent::Plugin::CloudWatchPutOutput).configure(conf)
|
244
|
+
end
|
245
|
+
end
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-cloudwatch-put
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- joker1007
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '12.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '12.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: test-unit-rr
|
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
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: fluentd
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.14.10
|
76
|
+
- - "<"
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '2'
|
79
|
+
type: :runtime
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 0.14.10
|
86
|
+
- - "<"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '2'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: aws-sdk
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '2'
|
96
|
+
type: :runtime
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '2'
|
103
|
+
description: Cloudwatch put metric plugin for fluentd.
|
104
|
+
email:
|
105
|
+
- kakyoin.hierophant@gmail.com
|
106
|
+
executables: []
|
107
|
+
extensions: []
|
108
|
+
extra_rdoc_files: []
|
109
|
+
files:
|
110
|
+
- ".gitignore"
|
111
|
+
- ".travis.yml"
|
112
|
+
- Gemfile
|
113
|
+
- LICENSE
|
114
|
+
- README.md
|
115
|
+
- Rakefile
|
116
|
+
- fluent-plugin-cloudwatch-put.gemspec
|
117
|
+
- lib/fluent/plugin/out_cloudwatch_put.rb
|
118
|
+
- test/helper.rb
|
119
|
+
- test/plugin/test_out_cloudwatch_put.rb
|
120
|
+
homepage: https://github.com/joker1007/fluent-plugin-cloudwatch-put
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.6.13
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: Cloudwatch put metric plugin for fluentd.
|
144
|
+
test_files:
|
145
|
+
- test/helper.rb
|
146
|
+
- test/plugin/test_out_cloudwatch_put.rb
|