fluent-plugin-cloudwatch-put 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -1
- data/fluent-plugin-cloudwatch-put.gemspec +1 -1
- data/lib/fluent/plugin/out_cloudwatch_put.rb +39 -14
- data/test/plugin/test_out_cloudwatch_put.rb +89 -0
- 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: fe04a863ed1a5b6c693fbc94a04d6b0f6f3d8fec
|
4
|
+
data.tar.gz: 78061618a796fbec0514aad7e9cb81e655abad51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67430ddd315340edf6d02888536074183b90e0a1cfa1eb0a00f294af1603cf750785259f00f4cbf49d44066436f9445de281d12ce7c434274d976cf6936be0ee
|
7
|
+
data.tar.gz: 40a9fa68966a9c7bd4c60507cf65863efcda4ac37ba5d23991a73b13ed7f12f8e697734b5f24242549faaa44a5657beb7aa95d7e8ee2624e8e004caff050c827
|
data/README.md
CHANGED
@@ -72,11 +72,17 @@ CloudWatch metric namespace (support placeholder)
|
|
72
72
|
|
73
73
|
CloudWatch metric name (support placeholder)
|
74
74
|
|
75
|
+
### key_as_metric_name (bool) (optional)
|
76
|
+
|
77
|
+
Use record key as metric name
|
78
|
+
|
79
|
+
Default value: `false`
|
80
|
+
|
75
81
|
### unit (string) (required)
|
76
82
|
|
77
83
|
CloudWatch metric unit (support placeholder)
|
78
84
|
|
79
|
-
### value_key (string) (required)
|
85
|
+
### value_key (array\<string\>) (required)
|
80
86
|
|
81
87
|
Use this key as metric value
|
82
88
|
|
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |spec|
|
5
5
|
spec.name = "fluent-plugin-cloudwatch-put"
|
6
|
-
spec.version = "0.
|
6
|
+
spec.version = "0.2.0"
|
7
7
|
spec.authors = ["joker1007"]
|
8
8
|
spec.email = ["kakyoin.hierophant@gmail.com"]
|
9
9
|
|
@@ -61,7 +61,9 @@ module Fluent
|
|
61
61
|
desc "CloudWatch metric namespace (support placeholder)"
|
62
62
|
config_param :namespace, :string
|
63
63
|
desc "CloudWatch metric name (support placeholder)"
|
64
|
-
config_param :metric_name, :string
|
64
|
+
config_param :metric_name, :string, default: nil
|
65
|
+
desc "Use keyname as metric name"
|
66
|
+
config_param :key_as_metric_name, :bool, default: false
|
65
67
|
desc "CloudWatch metric unit (support placeholder)"
|
66
68
|
config_param :unit, :string
|
67
69
|
|
@@ -76,7 +78,7 @@ module Fluent
|
|
76
78
|
end
|
77
79
|
|
78
80
|
desc "Use this key as metric value"
|
79
|
-
config_param :value_key, :string
|
81
|
+
config_param :value_key, :array, value_type: :string
|
80
82
|
|
81
83
|
desc "Cloudwatch storage resolution"
|
82
84
|
config_param :storage_resolution, :integer, default: 60
|
@@ -94,6 +96,10 @@ module Fluent
|
|
94
96
|
def configure(conf)
|
95
97
|
super
|
96
98
|
|
99
|
+
unless !!@metric_name ^ @key_as_metric_name
|
100
|
+
raise Fluent::ConfigError, "'Either 'metric_name'' or 'key_as_metric_name' must be set"
|
101
|
+
end
|
102
|
+
|
97
103
|
@dimensions.each do |d|
|
98
104
|
unless d.key.nil? ^ d.value.nil?
|
99
105
|
raise Fluent::ConfigError, "'Either dimensions[key]' or 'dimensions[value]' must be set"
|
@@ -102,6 +108,15 @@ module Fluent
|
|
102
108
|
if @use_statistic_sets && d.key
|
103
109
|
raise Fluent::ConfigError, "If 'use_statistic_sets' is true, dimensions[key] is not supportted"
|
104
110
|
end
|
111
|
+
|
112
|
+
if @use_statistic_sets && @key_as_metric_name
|
113
|
+
raise Fluent::ConfigError, "If 'use_statistic_sets' is true, 'key_as_metric_name' is not supportted"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
@send_all_key = false
|
118
|
+
if @value_key.size == 1 && @value_key[0] == "*"
|
119
|
+
@send_all_key = true
|
105
120
|
end
|
106
121
|
|
107
122
|
placeholder_params = "namespace=#{@namespace}/metric_name=#{@metric_name}/unit=#{@unit}/dimensions[name]=#{@dimensions.map(&:name).join(",")}/dimensions[value]=#{@dimensions.map(&:value).join(",")}"
|
@@ -144,7 +159,6 @@ module Fluent
|
|
144
159
|
|
145
160
|
def base_metric_data(meta)
|
146
161
|
{
|
147
|
-
metric_name: extract_placeholders(@metric_name, meta),
|
148
162
|
unit: extract_placeholders(@unit, meta),
|
149
163
|
storage_resolution: @storage_resolution,
|
150
164
|
}
|
@@ -154,16 +168,23 @@ module Fluent
|
|
154
168
|
meta = chunk.metadata
|
155
169
|
metric_data = []
|
156
170
|
chunk.msgpack_each do |(timestamp, record)|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
171
|
+
record.each do |k, v|
|
172
|
+
next unless @value_key.include?(k) || @send_all_key
|
173
|
+
|
174
|
+
metric_data << {
|
175
|
+
metric_name: @key_as_metric_name ? k : extract_placeholders(@metric_name, meta),
|
176
|
+
unit: extract_placeholders(@unit, meta),
|
177
|
+
storage_resolution: @storage_resolution,
|
178
|
+
dimensions: @dimensions.map { |d|
|
179
|
+
{
|
180
|
+
name: extract_placeholders(d.name, meta),
|
181
|
+
value: d.key ? record[d.key] : extract_placeholders(d.value, meta),
|
182
|
+
}
|
183
|
+
},
|
184
|
+
value: v.to_f,
|
185
|
+
timestamp: Time.at(timestamp)
|
186
|
+
}
|
187
|
+
end
|
167
188
|
end
|
168
189
|
metric_data
|
169
190
|
end
|
@@ -173,12 +194,16 @@ module Fluent
|
|
173
194
|
values = []
|
174
195
|
timestamps = []
|
175
196
|
chunk.msgpack_each do |(timestamp, record)|
|
176
|
-
|
197
|
+
record.each do |k, v|
|
198
|
+
next unless @value_key.include?(k) || @send_all_key
|
199
|
+
values << v.to_f
|
200
|
+
end
|
177
201
|
timestamps << timestamp
|
178
202
|
end
|
179
203
|
|
180
204
|
[
|
181
205
|
base_metric_data(meta).merge({
|
206
|
+
metric_name: extract_placeholders(@metric_name, meta),
|
182
207
|
dimensions: @dimensions.map { |d|
|
183
208
|
{
|
184
209
|
name: extract_placeholders(d.name, meta),
|
@@ -106,6 +106,95 @@ class CloudWatchPutOutputTest < Test::Unit::TestCase
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
+
test "write (multi value_key)" do
|
110
|
+
conf = %q{
|
111
|
+
region ap-northeast-1
|
112
|
+
namespace Test
|
113
|
+
key_as_metric_name true
|
114
|
+
unit Count
|
115
|
+
|
116
|
+
<dimensions>
|
117
|
+
name dim1
|
118
|
+
value dim_value1
|
119
|
+
</dimensions>
|
120
|
+
|
121
|
+
<dimensions>
|
122
|
+
name dim2
|
123
|
+
value dim_value2
|
124
|
+
</dimensions>
|
125
|
+
|
126
|
+
value_key key1, key2, key3
|
127
|
+
|
128
|
+
aws_key_id dummy
|
129
|
+
aws_sec_key dummy
|
130
|
+
}
|
131
|
+
d = create_driver(conf)
|
132
|
+
now = Time.now.to_i
|
133
|
+
|
134
|
+
d.instance.start
|
135
|
+
|
136
|
+
mock(d.instance.cloudwatch).put_metric_data({
|
137
|
+
namespace: "Test",
|
138
|
+
metric_data: [
|
139
|
+
{
|
140
|
+
metric_name: "key1",
|
141
|
+
dimensions: [
|
142
|
+
{
|
143
|
+
name: "dim1",
|
144
|
+
value: "dim_value1",
|
145
|
+
},
|
146
|
+
{
|
147
|
+
name: "dim2",
|
148
|
+
value: "dim_value2",
|
149
|
+
},
|
150
|
+
],
|
151
|
+
timestamp: Time.at(now),
|
152
|
+
value: 1.0,
|
153
|
+
unit: "Count",
|
154
|
+
storage_resolution: 60,
|
155
|
+
},
|
156
|
+
{
|
157
|
+
metric_name: "key2",
|
158
|
+
dimensions: [
|
159
|
+
{
|
160
|
+
name: "dim1",
|
161
|
+
value: "dim_value1",
|
162
|
+
},
|
163
|
+
{
|
164
|
+
name: "dim2",
|
165
|
+
value: "dim_value2",
|
166
|
+
},
|
167
|
+
],
|
168
|
+
timestamp: Time.at(now),
|
169
|
+
value: 2.0,
|
170
|
+
unit: "Count",
|
171
|
+
storage_resolution: 60,
|
172
|
+
},
|
173
|
+
{
|
174
|
+
metric_name: "key3",
|
175
|
+
dimensions: [
|
176
|
+
{
|
177
|
+
name: "dim1",
|
178
|
+
value: "dim_value1",
|
179
|
+
},
|
180
|
+
{
|
181
|
+
name: "dim2",
|
182
|
+
value: "dim_value2",
|
183
|
+
},
|
184
|
+
],
|
185
|
+
timestamp: Time.at(now),
|
186
|
+
value: 3.0,
|
187
|
+
unit: "Count",
|
188
|
+
storage_resolution: 60,
|
189
|
+
},
|
190
|
+
]
|
191
|
+
})
|
192
|
+
|
193
|
+
d.run do
|
194
|
+
d.feed('tag', now, {"key1" => 1, "key2" => 2, "key3" => 3})
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
109
198
|
test "write (use_statistic_sets)" do
|
110
199
|
conf = %q{
|
111
200
|
region ap-northeast-1
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-cloudwatch-put
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- joker1007
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|