fluent-plugin-mackerel 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +11 -0
- data/fluent-plugin-mackerel.gemspec +1 -1
- data/lib/fluent/plugin/out_mackerel.rb +18 -4
- data/test/plugin/test_out_mackerel.rb +36 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YjlkYmU3MGQ1YTUzNDdmZWYwMDlkMTkwNDk2MGNlY2Y1YjJjNDViMQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MWY0MDkyMWY3YTg0ODgyNTI1ZTFjMzE2Yjc3YTVhNzhiNGUyMzk5NQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Y2M3MjQ3NDIyNjQxZjFlNjRhMDAyNjViYzI1NmRmMmU5NzdhODBkYzUxN2M5
|
10
|
+
YTBhZTY4MDc4MjhmY2Y2YWM0NWQxZGQyNmU4MGQzOGRhMGMxNzliMTkxOGE4
|
11
|
+
MzQ1N2YzNmNkOWI0NTUzMzVmMDI5ZWRkMWUwNzliNDY2NGI4NzM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MzBjZjYxOThmNjhlNzY5NmFjOWNkOTdmYzg0NTY0ZTFiYWI3N2EzZTg2YmVi
|
14
|
+
MDNkYTJjY2IwY2U5NWUyNTk3ZjZhZDIwNTgzZjA3MzJmNGQxMzhhMThjMWUy
|
15
|
+
MzIxMzE0YmFkY2VjZjhhODYxNTZiOGYyMmEwODg2MDBhMGJhNTk=
|
data/README.md
CHANGED
@@ -44,6 +44,17 @@ Then the sent metric data will look like this:
|
|
44
44
|
```
|
45
45
|
As shown above, `${out_key}` will be replaced with out_key like "2xx_count" when sending metrics.
|
46
46
|
|
47
|
+
You can use `out_key_pattern` instead of `out_keys`. Input records whose key matches the pattern set to `out_key_pattern` will be sent. Either `out_keys` or `out_key_pattern` is required.
|
48
|
+
|
49
|
+
```
|
50
|
+
<match ...>
|
51
|
+
type mackerel
|
52
|
+
api_key 123456
|
53
|
+
service yourservice
|
54
|
+
metrics_name http_status.${out_key}
|
55
|
+
out_key_pattern [2-5]xx_count
|
56
|
+
```
|
57
|
+
|
47
58
|
You can use `${[n]}` for `mackerel_name` where `n` represents any decimal number including negative value,
|
48
59
|
|
49
60
|
```
|
@@ -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
|
+
spec.version = "0.0.7"
|
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}
|
@@ -9,7 +9,8 @@ module Fluent
|
|
9
9
|
config_param :hostid_path, :string, :default => nil
|
10
10
|
config_param :service, :string, :default => nil
|
11
11
|
config_param :metrics_name, :string, :default => nil
|
12
|
-
config_param :out_keys, :string
|
12
|
+
config_param :out_keys, :string, :default => nil
|
13
|
+
config_param :out_key_pattern, :string, :default => nil
|
13
14
|
config_param :origin, :string, :default => nil
|
14
15
|
|
15
16
|
attr_reader :mackerel
|
@@ -27,7 +28,16 @@ module Fluent
|
|
27
28
|
super
|
28
29
|
|
29
30
|
@mackerel = Mackerel::Client.new(:mackerel_api_key => conf['api_key'], :mackerel_origin => conf['origin'])
|
30
|
-
|
31
|
+
|
32
|
+
if @out_keys
|
33
|
+
@out_keys = @out_keys.split(',')
|
34
|
+
end
|
35
|
+
if @out_key_pattern
|
36
|
+
@out_key_pattern = Regexp.new(@out_key_pattern)
|
37
|
+
end
|
38
|
+
if @out_keys.nil? and @out_key_pattern.nil?
|
39
|
+
raise Fluent::ConfigError, "Either 'out_keys' or 'out_key_pattern' must be specifed."
|
40
|
+
end
|
31
41
|
|
32
42
|
if @flush_interval < 60
|
33
43
|
log.info("flush_interval less than 60s is not allowed and overwritten to 60s")
|
@@ -89,10 +99,14 @@ module Fluent
|
|
89
99
|
chunk.msgpack_each do |(tag,time,record)|
|
90
100
|
|
91
101
|
tokens = tag.split('.')
|
92
|
-
out_keys.map do |key|
|
93
102
|
|
94
|
-
|
103
|
+
if @out_keys
|
104
|
+
out_keys = @out_keys.select{|key| record.has_key?(key)}
|
105
|
+
else # @out_key_pattern
|
106
|
+
out_keys = record.keys.select{|key| @out_key_pattern.match(key)}
|
107
|
+
end
|
95
108
|
|
109
|
+
out_keys.map do |key|
|
96
110
|
name = @name_processor.nil? ? key :
|
97
111
|
@name_processor.map{ |p| p.call(:out_key => key, :tokens => tokens) }.join('.')
|
98
112
|
|
@@ -46,6 +46,21 @@ class MackerelOutputTest < Test::Unit::TestCase
|
|
46
46
|
origin example.domain
|
47
47
|
]
|
48
48
|
|
49
|
+
CONFIG_NO_OUT_KEYS = %[
|
50
|
+
type mackerel
|
51
|
+
api_key 123456
|
52
|
+
hostid xyz
|
53
|
+
metrics_name service.${out_key}
|
54
|
+
]
|
55
|
+
|
56
|
+
CONFIG_OUT_KEY_PATTERN = %[
|
57
|
+
type mackerel
|
58
|
+
api_key 123456
|
59
|
+
hostid xyz
|
60
|
+
metrics_name service.${out_key}
|
61
|
+
out_key_pattern ^val[0-9]$
|
62
|
+
]
|
63
|
+
|
49
64
|
def create_driver(conf = CONFIG, tag='test')
|
50
65
|
Fluent::Test::BufferedOutputTestDriver.new(Fluent::MackerelOutput, tag).configure(conf)
|
51
66
|
end
|
@@ -64,6 +79,10 @@ class MackerelOutputTest < Test::Unit::TestCase
|
|
64
79
|
d = create_driver(CONFIG_BLANK_METRICS)
|
65
80
|
}
|
66
81
|
|
82
|
+
assert_raise(Fluent::ConfigError) {
|
83
|
+
d = create_driver(CONFIG_NO_OUT_KEYS)
|
84
|
+
}
|
85
|
+
|
67
86
|
d = create_driver(CONFIG_SMALL_FLUSH_INTERVAL)
|
68
87
|
assert_equal d.instance.instance_variable_get(:@flush_interval), 60
|
69
88
|
|
@@ -76,6 +95,10 @@ class MackerelOutputTest < Test::Unit::TestCase
|
|
76
95
|
assert_equal d.instance.instance_variable_get(:@metrics_name), 'service.${out_key}'
|
77
96
|
assert_equal d.instance.instance_variable_get(:@out_keys), ['val1','val2','val3']
|
78
97
|
assert_equal d.instance.instance_variable_get(:@flush_interval), 60
|
98
|
+
|
99
|
+
d = create_driver(CONFIG_OUT_KEY_PATTERN)
|
100
|
+
assert_match d.instance.instance_variable_get(:@out_key_pattern), "val1"
|
101
|
+
assert_no_match d.instance.instance_variable_get(:@out_key_pattern), "foo"
|
79
102
|
end
|
80
103
|
|
81
104
|
def test_write
|
@@ -99,4 +122,17 @@ class MackerelOutputTest < Test::Unit::TestCase
|
|
99
122
|
d.run()
|
100
123
|
end
|
101
124
|
|
125
|
+
def test_write_pattern
|
126
|
+
d = create_driver(CONFIG_OUT_KEY_PATTERN)
|
127
|
+
mock(d.instance.mackerel).post_metrics([
|
128
|
+
{"hostId"=>"xyz", "value"=>1.0, "time"=>1399997498, "name"=>"custom.service.val1"},
|
129
|
+
{"hostId"=>"xyz", "value"=>2.0, "time"=>1399997498, "name"=>"custom.service.val2"},
|
130
|
+
])
|
131
|
+
|
132
|
+
ENV["TZ"]="Asia/Tokyo"
|
133
|
+
t = Time.strptime('2014-05-14 01:11:38', '%Y-%m-%d %T')
|
134
|
+
d.emit({'val1' => 1, 'val2' => 2, 'foo' => 3}, t)
|
135
|
+
d.run()
|
136
|
+
end
|
137
|
+
|
102
138
|
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.
|
4
|
+
version: 0.0.7
|
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-
|
12
|
+
date: 2014-09-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mackerel-client
|