fluent-plugin-mackerel 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/fluent-plugin-mackerel.gemspec +1 -1
- data/lib/fluent/plugin/out_mackerel.rb +32 -10
- data/test/plugin/test_out_mackerel.rb +22 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fba2647b6e58433c48d7f479da35206aa0f0ef4e
|
4
|
+
data.tar.gz: d775a6c6c53739eb1e3503968b5780de18773133
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ce5fea01ec17d19e7587a8ec46f116827f27ab1ecb7d7eca5cd2b9cdf72a09b741e4f902e7c3af6327e8e8f5b9f21318a169bf4eb1ea9b1e1bdc6d7c20c69b3
|
7
|
+
data.tar.gz: ad0c53ceaf70db022eb3a5cea4b2ccd5fbdb2c5797d145f4568992fc8cf0a94a93e36b4c04f84b671a78395e323815d82cd538750277f2c514b8742f696c76c8
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# fluent-plugin-mackerel [](https://travis-ci.org/mackerelio/fluent-plugin-mackerel)
|
2
2
|
|
3
3
|
## Overview
|
4
4
|
|
@@ -29,6 +29,7 @@ This plugin uses [APIv0](http://help-ja.mackerel.io/entry/spec/api/v0) of macker
|
|
29
29
|
api_key 123456
|
30
30
|
hostid xyz
|
31
31
|
metrics_name http_status.${out_key}
|
32
|
+
use_zero_for_empty
|
32
33
|
out_keys 2xx_count,3xx_count,4xx_count,5xx_count
|
33
34
|
</match>
|
34
35
|
```
|
@@ -44,6 +45,9 @@ Then the sent metric data will look like this:
|
|
44
45
|
```
|
45
46
|
As shown above, `${out_key}` will be replaced with out_key like "2xx_count" when sending metrics.
|
46
47
|
|
48
|
+
In the case some outkeys do not have any value, the value will be set to `0` with `use_zero_for_empty`, the default of which is true.
|
49
|
+
For example, you set `out_keys 2xx_count,3xx_count,4xx_count,5xx_count`, but you only get `2xx_count`, `3xx_count` and `4xx_count`, then `5xx_count` will be set to `0` with `use_zero_for_empty`.
|
50
|
+
|
47
51
|
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
52
|
|
49
53
|
```
|
@@ -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.1.
|
7
|
+
spec.version = "0.1.2"
|
8
8
|
spec.authors = ["tksmd","hatz48","stanaka","Songmu"]
|
9
9
|
spec.email = ["developers@mackerel.io"]
|
10
10
|
spec.description = %q{fluent plugin to send metrics to mackerel.io}
|
@@ -13,6 +13,7 @@ module Fluent
|
|
13
13
|
config_param :out_keys, :string, :default => nil
|
14
14
|
config_param :out_key_pattern, :string, :default => nil
|
15
15
|
config_param :origin, :string, :default => nil
|
16
|
+
config_param :use_zero_for_empty, :bool, :default => true
|
16
17
|
|
17
18
|
MAX_BUFFER_CHUNK_LIMIT = 100 * 1024
|
18
19
|
config_set_default :buffer_chunk_limit, MAX_BUFFER_CHUNK_LIMIT
|
@@ -101,10 +102,26 @@ module Fluent
|
|
101
102
|
[tag, time, record].to_msgpack
|
102
103
|
end
|
103
104
|
|
105
|
+
def generate_metric(key, tokens, time, value)
|
106
|
+
name = @name_processor.nil? ? key :
|
107
|
+
@name_processor.map{ |p| p.call(:out_key => key, :tokens => tokens) }.join('.')
|
108
|
+
|
109
|
+
metric = {
|
110
|
+
'value' => value,
|
111
|
+
'time' => time,
|
112
|
+
'name' => @remove_prefix ? name : "%s.%s" % ['custom', name]
|
113
|
+
}
|
114
|
+
metric['hostId'] = @hostid_processor.call(:tokens => tokens) if @hostid
|
115
|
+
return metric
|
116
|
+
end
|
117
|
+
|
104
118
|
def write(chunk)
|
105
119
|
metrics = []
|
120
|
+
processed = {}
|
121
|
+
tags = {}
|
122
|
+
time_latest = 0
|
106
123
|
chunk.msgpack_each do |(tag,time,record)|
|
107
|
-
|
124
|
+
tags[tag] = true
|
108
125
|
tokens = tag.split('.')
|
109
126
|
|
110
127
|
if @out_keys
|
@@ -114,16 +131,20 @@ module Fluent
|
|
114
131
|
end
|
115
132
|
|
116
133
|
out_keys.map do |key|
|
117
|
-
|
118
|
-
|
134
|
+
metrics << generate_metric(key, tokens, time, record[key].to_f)
|
135
|
+
time_latest = time if time_latest == 0 || time_latest < time
|
136
|
+
processed[tag + "." + key] = true
|
137
|
+
end
|
138
|
+
end
|
119
139
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
140
|
+
if @out_keys && @use_zero_for_empty
|
141
|
+
tags.each_key do |tag|
|
142
|
+
tokens = tag.split('.')
|
143
|
+
@out_keys.each do |key|
|
144
|
+
unless processed[tag + "." + key]
|
145
|
+
metrics << generate_metric(key, tokens, time_latest, 0.0)
|
146
|
+
end
|
147
|
+
end
|
127
148
|
end
|
128
149
|
end
|
129
150
|
|
@@ -132,6 +153,7 @@ module Fluent
|
|
132
153
|
end
|
133
154
|
|
134
155
|
def send(metrics)
|
156
|
+
log.debug("out_mackerel: #{metrics}")
|
135
157
|
begin
|
136
158
|
if @hostid
|
137
159
|
@mackerel.post_metrics(metrics)
|
@@ -106,6 +106,14 @@ class MackerelOutputTest < Test::Unit::TestCase
|
|
106
106
|
out_keys val1,val2,val3
|
107
107
|
]
|
108
108
|
|
109
|
+
CONFIG_SERVICE_USE_ZERO = %[
|
110
|
+
type mackerel
|
111
|
+
api_key 123456
|
112
|
+
service xyz
|
113
|
+
use_zero_for_empty
|
114
|
+
out_keys val1,val2,val3
|
115
|
+
]
|
116
|
+
|
109
117
|
def create_driver(conf = CONFIG, tag='test')
|
110
118
|
Fluent::Test::BufferedOutputTestDriver.new(Fluent::MackerelOutput, tag).configure(conf)
|
111
119
|
end
|
@@ -231,6 +239,20 @@ end
|
|
231
239
|
d.run()
|
232
240
|
end
|
233
241
|
|
242
|
+
def test_service_use_zero
|
243
|
+
d = create_driver(CONFIG_SERVICE_USE_ZERO)
|
244
|
+
mock(d.instance.mackerel).post_service_metrics('xyz', [
|
245
|
+
{"value"=>1.0, "time"=>1399997498, "name"=>"custom.val1"},
|
246
|
+
{"value"=>2.0, "time"=>1399997498, "name"=>"custom.val2"},
|
247
|
+
{"value"=>0.0, "time"=>1399997498, "name"=>"custom.val3"},
|
248
|
+
])
|
249
|
+
|
250
|
+
ENV["TZ"]="Asia/Tokyo"
|
251
|
+
t = Time.strptime('2014-05-14 01:11:38', '%Y-%m-%d %T')
|
252
|
+
d.emit({'val1' => 1, 'val2' => 2, 'foo' => 3}, t)
|
253
|
+
d.run()
|
254
|
+
end
|
255
|
+
|
234
256
|
def test_name_processor
|
235
257
|
[
|
236
258
|
{metrics_name: "${out_key}", expected: "val1"},
|
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.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tksmd
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2015-
|
14
|
+
date: 2015-04-14 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: mackerel-client
|
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
137
|
version: '0'
|
138
138
|
requirements: []
|
139
139
|
rubyforge_project:
|
140
|
-
rubygems_version: 2.
|
140
|
+
rubygems_version: 2.4.5
|
141
141
|
signing_key:
|
142
142
|
specification_version: 4
|
143
143
|
summary: fluent plugin to send metrics to mackerel.io
|