fluent-plugin-mackerel 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +4 -2
- data/fluent-plugin-mackerel.gemspec +1 -1
- data/lib/fluent/plugin/out_mackerel.rb +18 -4
- data/test/plugin/test_out_mackerel.rb +21 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NTY0NzJkZjgzMDMwNzNkNGY1MjdkYmQ5ZTNlNzA2ZTAwZjg2N2I3Nw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MzAyNDI3MTdlODNlMzhhNGMwMzEyNmJhOTdkODdlYzY0ZDNiOTc0MQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OWU4YzZlM2Q1Zjk5MzY5OGI2ZWVjODUzYWU0YjY3ZmU0M2Y4YjAzMDVkMjRk
|
10
|
+
Yjk5N2U1NzNlNzQwYWI1YjQyNmVmMGM3NzFkM2Q3NDQ3OTg1Y2E3ODYzZDdh
|
11
|
+
MjljZDg0MmU1YWUyNzhkNDJjMDQ2YTkxYmRjNmI0ZTI0YjM1YmY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OTYwYjM0ZGUwMmRjMzRlMjNjYjg2ODIyMWIwMjc5ZWI0OGNlZTkwZmFjNWEx
|
14
|
+
MjYwZWZjZWRiNjE4Yzc0NTkyZmY0NjhjZjc3YTkyZjU5ODA3NTU1MTI5MmMz
|
15
|
+
YmM1NjFmODBkOGYwMzcwOTY1MWRhZTU5ZTdiNWQ3MTlkNzhiNGI=
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
## Overview
|
4
4
|
|
5
|
-
[Fluentd](http://fluentd.org) plugin to send metrics to [mackerel](http://mackerel.io/).
|
5
|
+
[Fluentd](http://fluentd.org) plugin to send metrics to [mackerel.io](http://mackerel.io/).
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -40,7 +40,9 @@ Then the sent metric data will look like this:
|
|
40
40
|
"value": 100.0
|
41
41
|
}
|
42
42
|
```
|
43
|
-
As shown above, metric name will be a concatenation of metrics_prefix and out_keys values.
|
43
|
+
As shown above, metric name will be a concatenation of `metrics_prefix` and `out_keys` values.
|
44
|
+
|
45
|
+
`flush_interval` is not allowed to set less than 60 secs not to send API requests more than once in a minute.
|
44
46
|
|
45
47
|
## TODO
|
46
48
|
|
@@ -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.2"
|
8
8
|
spec.authors = ["tksmd"]
|
9
9
|
spec.email = ["someda@isenshi.com"]
|
10
10
|
spec.description = %q{fluent plugin to send metrics to mackerel.io}
|
@@ -8,8 +8,6 @@ module Fluent
|
|
8
8
|
config_param :metrics_prefix, :string
|
9
9
|
config_param :out_keys, :string
|
10
10
|
|
11
|
-
config_param :flush_interval, :time, :default => 1
|
12
|
-
|
13
11
|
attr_reader :mackerel
|
14
12
|
|
15
13
|
# Define `log` method for v0.10.42 or earlier
|
@@ -27,6 +25,11 @@ module Fluent
|
|
27
25
|
@mackerel = Mackerel.new(conf['api_key'])
|
28
26
|
@out_keys = @out_keys.split(',')
|
29
27
|
|
28
|
+
if @flush_interval < 60
|
29
|
+
log.info("flush_interval less than 60s is not allowed and overwriteen to 60s")
|
30
|
+
@flush_interval = 60
|
31
|
+
end
|
32
|
+
|
30
33
|
if @hostid.nil? and @hostid_path.nil?
|
31
34
|
raise Fluent::ConfigError, "Either 'hostid' or 'hostid_path' must be specifed."
|
32
35
|
end
|
@@ -63,12 +66,12 @@ module Fluent
|
|
63
66
|
end
|
64
67
|
|
65
68
|
begin
|
66
|
-
@mackerel.post_metrics(metrics)
|
69
|
+
@mackerel.post_metrics(metrics) unless metrics.empty?
|
67
70
|
rescue => e
|
68
71
|
log.error("out_mackerel:", :error_class => e.class, :error => e.message)
|
69
72
|
end
|
73
|
+
metrics.clear
|
70
74
|
end
|
71
|
-
|
72
75
|
end
|
73
76
|
|
74
77
|
class Mackerel
|
@@ -85,6 +88,9 @@ module Fluent
|
|
85
88
|
end
|
86
89
|
|
87
90
|
def post_metrics(metrics)
|
91
|
+
|
92
|
+
wait_for_minute
|
93
|
+
|
88
94
|
req = Net::HTTP::Post.new('/api/v0/tsdb', initheader = {
|
89
95
|
'X-Api-Key' => @api_key,
|
90
96
|
'Content-Type' =>'application/json',
|
@@ -102,6 +108,14 @@ module Fluent
|
|
102
108
|
end
|
103
109
|
end
|
104
110
|
|
111
|
+
def wait_for_minute
|
112
|
+
# limit request once per minute
|
113
|
+
wait_secs = @last_posted ? @last_posted + 60 - Time.now.to_i : 0
|
114
|
+
sleep wait_secs if wait_secs > 0
|
115
|
+
@last_posted = Time.now.to_i
|
116
|
+
wait_secs > 0
|
117
|
+
end
|
118
|
+
|
105
119
|
end
|
106
120
|
|
107
121
|
class MackerelError < RuntimeError; end
|
@@ -21,6 +21,15 @@ class MackerelOutputTest < Test::Unit::TestCase
|
|
21
21
|
out_keys val1,val2,val3
|
22
22
|
]
|
23
23
|
|
24
|
+
CONFIG_SMALL_FLUSH_INTERVAL = %[
|
25
|
+
type mackerel
|
26
|
+
api_key 123456
|
27
|
+
hostid xyz
|
28
|
+
metrics_prefix service
|
29
|
+
out_keys val1,val2,val3
|
30
|
+
flush_interval 1s
|
31
|
+
]
|
32
|
+
|
24
33
|
def create_driver(conf = CONFIG, tag='test')
|
25
34
|
Fluent::Test::BufferedOutputTestDriver.new(Fluent::MackerelOutput, tag).configure(conf)
|
26
35
|
end
|
@@ -35,11 +44,15 @@ class MackerelOutputTest < Test::Unit::TestCase
|
|
35
44
|
d = create_driver(CONFIG_NOHOST)
|
36
45
|
}
|
37
46
|
|
47
|
+
d = create_driver(CONFIG_SMALL_FLUSH_INTERVAL)
|
48
|
+
assert_equal d.instance.instance_variable_get(:@flush_interval), 60
|
49
|
+
|
38
50
|
d = create_driver()
|
39
51
|
assert_equal d.instance.instance_variable_get(:@api_key), '123456'
|
40
52
|
assert_equal d.instance.instance_variable_get(:@hostid), 'xyz'
|
41
53
|
assert_equal d.instance.instance_variable_get(:@metrics_prefix), 'service'
|
42
54
|
assert_equal d.instance.instance_variable_get(:@out_keys), ['val1','val2','val3']
|
55
|
+
assert_equal d.instance.instance_variable_get(:@flush_interval), 60
|
43
56
|
end
|
44
57
|
|
45
58
|
def test_write
|
@@ -60,5 +73,13 @@ class MackerelOutputTest < Test::Unit::TestCase
|
|
60
73
|
d.run()
|
61
74
|
end
|
62
75
|
|
76
|
+
def test_wait_for_minute
|
77
|
+
d = create_driver()
|
78
|
+
mackerel = d.instance.mackerel
|
79
|
+
assert_equal mackerel.wait_for_minute, false
|
80
|
+
assert_equal mackerel.wait_for_minute, true
|
81
|
+
sleep 60
|
82
|
+
assert_equal mackerel.wait_for_minute, false
|
83
|
+
end
|
63
84
|
|
64
85
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tksmd
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|