fluent-plugin-mackerel 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjIwZThjMzJiNmNjNjE1ZGU1MWM3YWQwYzJmZjVkYmMzY2Y5MzdkNw==
4
+ ZDg3MGNjYjM5M2QwMzQzYmViODQ5YWZlZGI4OTY0ZDc0ZGI3MTVmMg==
5
5
  data.tar.gz: !binary |-
6
- MjgxN2FjOGIwZWZjMmRjMWNkZDQ0MzJkMzc0N2U3ZGZhZjI3OTAzNw==
6
+ ZTNlZTYwZmNjODUyYTgxOTFjODEyYWVjOGY2NGY1OTkwMjg1YmQyMQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ODAzNWZiYjc4MzU4ODM2NDJhZWY5M2M5MGU3MDU5Yzc3NGNiNmYyMzcyYzNj
10
- N2FjZmY3NWYwZGIwZTMyYmQ4OTg1NGFmYWU2YzE1NzAxODYzMTJjNDI4MzM4
11
- ZDlkNzBkNjc3NGZlYWIyZDVkMzQyZjIwMTk3N2U2NDQyZjlmYzI=
9
+ YjU4Yjk1NDEzMjIyZWJmYjEzMmExNDc1YjQ5NWJmZDU5NjU0OGViMDZjNzJm
10
+ NjYyZDJhOGNmOGNiNGU0NjI4MTY1Nzk4Mjk4YjRjNGI4YmZmNjM3MzA2OTc2
11
+ NjkwMWIwMmJkOWU1MTljYjUzOTFhNjVjZGYyZGE3OWI5NDQ2YTU=
12
12
  data.tar.gz: !binary |-
13
- NjA1NzE2MmVlY2YyZmFmYzU4NmJhMGJkZTNiYjE3MjU2NDk3ZmJiZDBlOGI4
14
- MmQzMDg3ZTBiOGRjNjI1ZDljMzY2YjFjZWFlNDAxNDVlNWVhOTdmMTNjODZj
15
- NTU5YWI2YThlZTg2YTExZjVkNDY2ZWY1YTU2YzZhNDc0MGIwMzU=
13
+ N2EzZTFhNTIxNmI1YjA1ZmQ2MzgyMjExMDExMTEwZmQ1MDE4YzJhN2UyZjlk
14
+ NTFkYjViZmNiYzI0YWNmYzA2MzJlNjQ4ZGYxZjlhYzJkZTdjYzBjNWU3MmQ5
15
+ MWRhZjg2NTAzZjQ1ZGU5ZWZhZjA3Njg5NzBjYzY3NmJhMGQzMjY=
data/README.md CHANGED
@@ -88,6 +88,21 @@ You can also send ["service" metric](http://help-ja.mackerel.io/entry/spec/api/v
88
88
  out_keys 2xx_count,3xx_count,4xx_count,5xx_count
89
89
  </match>
90
90
  ```
91
+
92
+ When you send service metric, "custom" can be removed with `remove_prefix` as follows.
93
+ This option is not availabe when sending host metric.
94
+
95
+ ```
96
+ <match ...>
97
+ type mackerel
98
+ api_key 123456
99
+ service yourservice
100
+ remove_prefix
101
+ metrics_name http_status.${out_key}
102
+ out_keys 2xx_count,3xx_count,4xx_count,5xx_count
103
+ </match>
104
+ ```
105
+
91
106
  `flush_interval` is not allowed to be set less than 60 secs not to send API requests more than once in a minute.
92
107
 
93
108
  This plugin overwrites the default value of `buffer_queue_limit` and `buffer_chunk_limit` as follows.
@@ -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-mackerel"
7
- spec.version = "0.0.9"
7
+ spec.version = "0.1.0"
8
8
  spec.authors = ["tksmd","hatz48"]
9
9
  spec.email = ["someda@isenshi.com"]
10
10
  spec.description = %q{fluent plugin to send metrics to mackerel.io}
@@ -8,6 +8,7 @@ module Fluent
8
8
  config_param :hostid, :string, :default => nil
9
9
  config_param :hostid_path, :string, :default => nil
10
10
  config_param :service, :string, :default => nil
11
+ config_param :remove_prefix, :bool, :default => false
11
12
  config_param :metrics_name, :string, :default => nil
12
13
  config_param :out_keys, :string, :default => nil
13
14
  config_param :out_key_pattern, :string, :default => nil
@@ -60,6 +61,10 @@ module Fluent
60
61
  raise Fluent::ConfigError, "Niether 'hostid' and 'service' cannot be specifed."
61
62
  end
62
63
 
64
+ if @remove_prefix and @service.nil?
65
+ raise Fluent::ConfigError, "'remove_prefix' must be used with 'service'."
66
+ end
67
+
63
68
  unless @hostid.nil?
64
69
  if matched = @hostid.match(/^\${tag_parts\[(\d+)\]}$/)
65
70
  hostid_idx = matched[1].to_i
@@ -115,7 +120,7 @@ module Fluent
115
120
  metric = {
116
121
  'value' => record[key].to_f,
117
122
  'time' => time,
118
- 'name' => "%s.%s" % ['custom', name]
123
+ 'name' => @remove_prefix ? name : "%s.%s" % ['custom', name]
119
124
  }
120
125
  metric['hostId'] = @hostid_processor.call(:tokens => tokens) if @hostid
121
126
  metrics << metric
@@ -84,6 +84,28 @@ class MackerelOutputTest < Test::Unit::TestCase
84
84
  buffer_chunk_limit 1k
85
85
  ]
86
86
 
87
+ CONFIG_SERVICE = %[
88
+ type mackerel
89
+ api_key 123456
90
+ service xyz
91
+ out_keys val1,val2,val3
92
+ ]
93
+
94
+ CONFIG_SERVICE_REMOVE_PREFIX = %[
95
+ type mackerel
96
+ api_key 123456
97
+ service xyz
98
+ remove_prefix
99
+ out_keys val1,val2,val3
100
+ ]
101
+
102
+ CONFIG_INVALID_REMOVE_PREFIX = %[
103
+ type mackerel
104
+ api_key 123456
105
+ remove_prefix
106
+ out_keys val1,val2,val3
107
+ ]
108
+
87
109
  def create_driver(conf = CONFIG, tag='test')
88
110
  Fluent::Test::BufferedOutputTestDriver.new(Fluent::MackerelOutput, tag).configure(conf)
89
111
  end
@@ -106,6 +128,10 @@ class MackerelOutputTest < Test::Unit::TestCase
106
128
  d = create_driver(CONFIG_NO_OUT_KEYS)
107
129
  }
108
130
 
131
+ assert_raise(Fluent::ConfigError) {
132
+ d = create_driver(CONFIG_INVALID_REMOVE_PREFIX)
133
+ }
134
+
109
135
  d = create_driver(CONFIG_SMALL_FLUSH_INTERVAL)
110
136
  assert_equal d.instance.instance_variable_get(:@flush_interval), 60
111
137
 
@@ -129,7 +155,8 @@ class MackerelOutputTest < Test::Unit::TestCase
129
155
 
130
156
  d = create_driver(CONFIG_BUFFER_LIMIT_IGNORE)
131
157
  assert_equal d.instance.instance_variable_get(:@buffer_chunk_limit), Fluent::MackerelOutput::MAX_BUFFER_CHUNK_LIMIT
132
- end
158
+
159
+ end
133
160
 
134
161
  def test_write
135
162
  d = create_driver()
@@ -172,6 +199,32 @@ class MackerelOutputTest < Test::Unit::TestCase
172
199
  {"hostId"=>"xyz", "value"=>2.0, "time"=>1399997498, "name"=>"custom.a-status-b.val2"},
173
200
  ])
174
201
 
202
+ ENV["TZ"]="Asia/Tokyo"
203
+ t = Time.strptime('2014-05-14 01:11:38', '%Y-%m-%d %T')
204
+ d.emit({'val1' => 1, 'val2' => 2}, t)
205
+ d.run()
206
+ end
207
+
208
+ def test_service
209
+ d = create_driver(CONFIG_SERVICE)
210
+ mock(d.instance.mackerel).post_service_metrics('xyz', [
211
+ {"value"=>1.0, "time"=>1399997498, "name"=>"custom.val1"},
212
+ {"value"=>2.0, "time"=>1399997498, "name"=>"custom.val2"},
213
+ ])
214
+
215
+ ENV["TZ"]="Asia/Tokyo"
216
+ t = Time.strptime('2014-05-14 01:11:38', '%Y-%m-%d %T')
217
+ d.emit({'val1' => 1, 'val2' => 2, 'foo' => 3}, t)
218
+ d.run()
219
+ end
220
+
221
+ def test_service_remove_prefix
222
+ d = create_driver(CONFIG_SERVICE_REMOVE_PREFIX)
223
+ mock(d.instance.mackerel).post_service_metrics('xyz', [
224
+ {"value"=>1.0, "time"=>1399997498, "name"=>"val1"},
225
+ {"value"=>2.0, "time"=>1399997498, "name"=>"val2"},
226
+ ])
227
+
175
228
  ENV["TZ"]="Asia/Tokyo"
176
229
  t = Time.strptime('2014-05-14 01:11:38', '%Y-%m-%d %T')
177
230
  d.emit({'val1' => 1, 'val2' => 2, 'foo' => 3}, t)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-mackerel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tksmd
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-29 00:00:00.000000000 Z
12
+ date: 2015-02-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mackerel-client