fluent-plugin-mackerel 0.0.7 → 0.0.8

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
- YjlkYmU3MGQ1YTUzNDdmZWYwMDlkMTkwNDk2MGNlY2Y1YjJjNDViMQ==
4
+ OTNiZDMwMGM1MGFhOTdiZGE2NjNkNDJmNjAxMDg1MmIyZDllMTc4Yw==
5
5
  data.tar.gz: !binary |-
6
- MWY0MDkyMWY3YTg0ODgyNTI1ZTFjMzE2Yjc3YTVhNzhiNGUyMzk5NQ==
6
+ Y2Y3MmIwYmIwNzFjMDZhZDhjMTdlZjcyMDBmODI3ZDcyMDQxNDIzYw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Y2M3MjQ3NDIyNjQxZjFlNjRhMDAyNjViYzI1NmRmMmU5NzdhODBkYzUxN2M5
10
- YTBhZTY4MDc4MjhmY2Y2YWM0NWQxZGQyNmU4MGQzOGRhMGMxNzliMTkxOGE4
11
- MzQ1N2YzNmNkOWI0NTUzMzVmMDI5ZWRkMWUwNzliNDY2NGI4NzM=
9
+ MDFhODQ4ZjI5NGFiYTQ0YzZmZWM4YTI0NTkyYTYyZjRhZDkwMmI5NTZiNzYx
10
+ ZDVlMDkwODNiMjViMTI2N2UxYzE4NDVhMmJhMzFmZmRhNmMwYTRmYzVlMzRj
11
+ YjFkNDZjYmM4MGIxOWVhY2MyMTg2MmVhNmUzNzM0ZjE3YzliZTU=
12
12
  data.tar.gz: !binary |-
13
- MzBjZjYxOThmNjhlNzY5NmFjOWNkOTdmYzg0NTY0ZTFiYWI3N2EzZTg2YmVi
14
- MDNkYTJjY2IwY2U5NWUyNTk3ZjZhZDIwNTgzZjA3MzJmNGQxMzhhMThjMWUy
15
- MzIxMzE0YmFkY2VjZjhhODYxNTZiOGYyMmEwODg2MDBhMGJhNTk=
13
+ NDNkOTdiYTFmZmMyZTYzMWU0OTc4Zjk2Y2FiNGMyZjEzMTdhOTRkZTg4MjE1
14
+ OWI1OWRkY2Q4ZWM4NGIyNjI3OWE4NjVmYWFjYmYzODA0NWIxMGQ3MGM3M2Q0
15
+ Nzg3ZGMzYjIzODI2NTQzODdlZjk4MmViZmFjMTAyNTc0ODlkODE=
data/README.md CHANGED
@@ -55,7 +55,7 @@ You can use `out_key_pattern` instead of `out_keys`. Input records whose key mat
55
55
  out_key_pattern [2-5]xx_count
56
56
  ```
57
57
 
58
- You can use `${[n]}` for `mackerel_name` where `n` represents any decimal number including negative value,
58
+ You can use `${[n]}` for `metrics_name` where `n` represents any decimal number including negative value,
59
59
 
60
60
  ```
61
61
  <match mackerel.*>
@@ -129,6 +129,16 @@ To run tests, do the following.
129
129
  $ VERBOSE=1 bundle exec rake test
130
130
  ```
131
131
 
132
+ If you want to run a certain file, run rake like this
133
+ ```
134
+ $ VERBOSE=1 bundle exec rake test TEST=test/plugin/test_out_mackerel.rb
135
+ ```
136
+
137
+ In addition, you can run specific method like this.
138
+ ```
139
+ $ VERBOSE=1 bundle exec rake test TEST=test/plugin/test_out_mackerel.rb TESTOPTS="--name=test_configure"
140
+ ```
141
+
132
142
  When releasing, call rake release as follows.
133
143
  ```
134
144
  $ bundle exec rake release
@@ -148,6 +158,7 @@ For debugging purpose, you can change Mackerel endpoint by `origin` parameter li
148
158
 
149
159
  ## References
150
160
 
161
+ * [Send service and host metric to Mackerel by using fluentd (Japanese, Official Document)](http://help-ja.mackerel.io/entry/advanced/fluentd)
151
162
  * [How to use fluent-plugin-mackerel (Japanese)](http://qiita.com/tksmd/items/1212331a5a18afe520df)
152
163
 
153
164
  ## Copyright
@@ -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.7"
7
+ spec.version = "0.0.8"
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}
@@ -67,17 +67,15 @@ module Fluent
67
67
 
68
68
  if @metrics_name
69
69
  @name_processor = @metrics_name.split('.').map{ |token|
70
- if token.start_with?('$')
71
- token = token[2..-2]
72
- if token == 'out_key'
73
- Proc.new{ |args| args[:out_key] }
74
- else
75
- idx = token.match(/\[(-?\d+)\]/)[1].to_i
76
- Proc.new{ |args| args[:tokens][idx] }
77
- end
78
- else
79
- Proc.new{ token }
80
- end
70
+ Proc.new{ |args|
71
+ token.gsub(/\${(out_key|\[(-?\d+)\])}/) {
72
+ if $1 == 'out_key'
73
+ args[:out_key]
74
+ else
75
+ args[:tokens][$1[1..-1].to_i]
76
+ end
77
+ }
78
+ }
81
79
  }
82
80
  end
83
81
  end
@@ -116,7 +114,6 @@ module Fluent
116
114
  'name' => "%s.%s" % ['custom', name]
117
115
  }
118
116
  metric['hostId'] = @hostid_processor.call(:tokens => tokens) if @hostid
119
-
120
117
  metrics << metric
121
118
  end
122
119
  end
@@ -61,6 +61,14 @@ class MackerelOutputTest < Test::Unit::TestCase
61
61
  out_key_pattern ^val[0-9]$
62
62
  ]
63
63
 
64
+ CONFIG_FOR_ISSUE_4 = %[
65
+ type mackerel
66
+ api_key 123456
67
+ hostid xyz
68
+ metrics_name a-${[1]}-b.${out_key}
69
+ out_keys val1,val2
70
+ ]
71
+
64
72
  def create_driver(conf = CONFIG, tag='test')
65
73
  Fluent::Test::BufferedOutputTestDriver.new(Fluent::MackerelOutput, tag).configure(conf)
66
74
  end
@@ -135,4 +143,53 @@ class MackerelOutputTest < Test::Unit::TestCase
135
143
  d.run()
136
144
  end
137
145
 
146
+ def test_write_issue4
147
+ d = create_driver(CONFIG_FOR_ISSUE_4, tag='test.status')
148
+ mock(d.instance.mackerel).post_metrics([
149
+ {"hostId"=>"xyz", "value"=>1.0, "time"=>1399997498, "name"=>"custom.a-status-b.val1"},
150
+ {"hostId"=>"xyz", "value"=>2.0, "time"=>1399997498, "name"=>"custom.a-status-b.val2"},
151
+ ])
152
+
153
+ ENV["TZ"]="Asia/Tokyo"
154
+ t = Time.strptime('2014-05-14 01:11:38', '%Y-%m-%d %T')
155
+ d.emit({'val1' => 1, 'val2' => 2, 'foo' => 3}, t)
156
+ d.run()
157
+ end
158
+
159
+ def test_name_processor
160
+ [
161
+ {metrics_name: "${out_key}", expected: "val1"},
162
+ {metrics_name: "name.${out_key}", expected: "name.val1"},
163
+ {metrics_name: "a-${out_key}", expected: "a-val1"},
164
+ {metrics_name: "${out_key}-b", expected: "val1-b"},
165
+ {metrics_name: "a-${out_key}-b", expected: "a-val1-b"},
166
+ {metrics_name: "name.a-${out_key}-b", expected: "name.a-val1-b"},
167
+ {metrics_name: "${out_key}-a-${out_key}", expected: "val1-a-val1"},
168
+ {metrics_name: "${out_keyx}", expected: "${out_keyx}"},
169
+ {metrics_name: "${[1]}", expected: "status"},
170
+ {metrics_name: "${[-1]}", expected: "status"},
171
+ {metrics_name: "name.${[1]}", expected: "name.status"},
172
+ {metrics_name: "a-${[1]}", expected: "a-status"},
173
+ {metrics_name: "${[1]}-b", expected: "status-b"},
174
+ {metrics_name: "a-${[1]}-b", expected: "a-status-b"},
175
+ {metrics_name: "${[0]}.${[1]}", expected: "test.status"},
176
+ {metrics_name: "${[0]}-${[1]}", expected: "test-status"},
177
+ {metrics_name: "${[0]}-${[1]}-${out_key}", expected: "test-status-val1"},
178
+ {metrics_name: "${[2]}", expected: ""},
179
+ ].map { |obj|
180
+ test_config = %[
181
+ type mackerel
182
+ api_key 123456
183
+ hostid xyz
184
+ metrics_name #{obj[:metrics_name]}
185
+ out_keys val1,val2
186
+ ]
187
+ d = create_driver(test_config, tag='test.status')
188
+ name_processor = d.instance.instance_variable_get(:@name_processor)
189
+ actual = name_processor.map{ |p| p.call(:out_key => 'val1', :tokens => ['test', 'status']) }.join('.')
190
+ assert_equal obj[:expected], actual
191
+ }
192
+ end
193
+
194
+
138
195
  end
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.7
4
+ version: 0.0.8
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: 2014-09-27 00:00:00.000000000 Z
12
+ date: 2014-10-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mackerel-client