fluent-plugin-stats-notifier 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +3 -3
- data/fluent-plugin-stats-notifier.gemspec +1 -1
- data/lib/fluent/plugin/out_stats_notifier.rb +44 -9
- data/spec/out_stats_notifier_spec.rb +29 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20ebee510eb1403230e4baee3b2b302e9d5a82dd
|
4
|
+
data.tar.gz: 64c9831470b6871e9f7df06efeb61d7c2d14466c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f5b4655b1d325fa5bfcb018f82ccc78e01815a5a7b2e7e8d57d042e3f48a0713eb6bd3671f36967f1910401b019ab4a04b4e091b69c150c8899e3e620dfa7ab
|
7
|
+
data.tar.gz: 0172ea3071a0713239147954b68818b8f57ccf8505c043f51a47977930b4ac3093a5452153ae2eadaf737cb695464612b1549967c39e524dfc9d2cdaffa605d5
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -55,15 +55,15 @@ then this plugin emits an message because the max of `4xx_count` is greater than
|
|
55
55
|
|
56
56
|
- tag
|
57
57
|
|
58
|
-
The output tag name.
|
58
|
+
The output tag name. Required for `aggregate all`.
|
59
59
|
|
60
60
|
- add_tag_prefix
|
61
61
|
|
62
|
-
|
62
|
+
Add tag prefix for output message. Required for `aggregate tag`.
|
63
63
|
|
64
64
|
- aggragate
|
65
65
|
|
66
|
-
|
66
|
+
Do calculation for each `tag` or `all`. The defaultis `all`.
|
67
67
|
|
68
68
|
- store_file
|
69
69
|
|
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "fluent-plugin-stats-notifier"
|
6
|
-
s.version = "0.0.
|
6
|
+
s.version = "0.0.3"
|
7
7
|
s.authors = ["Naotoshi Seo"]
|
8
8
|
s.email = ["sonots@gmail.com"]
|
9
9
|
s.homepage = "https://github.com/sonots/fluent-plugin-stats-notifier"
|
@@ -15,6 +15,9 @@ class Fluent::StatsNotifierOutput < Fluent::Output
|
|
15
15
|
config_param :greater_equal, :float, :default => nil
|
16
16
|
config_param :compare_with, :string, :default => "max"
|
17
17
|
config_param :tag, :string
|
18
|
+
config_param :add_tag_prefix, :string, :default => nil
|
19
|
+
config_param :remove_tag_prefix, :string, :default => nil
|
20
|
+
config_param :aggregate, :string, :default => 'all'
|
18
21
|
config_param :store_file, :string, :default => nil
|
19
22
|
|
20
23
|
attr_accessor :counts
|
@@ -48,6 +51,30 @@ class Fluent::StatsNotifierOutput < Fluent::Output
|
|
48
51
|
raise Fluent::ConfigError, "out_stats_notiifer: `compare_with` must be one of `sum`, `max`, `min`, `avg`"
|
49
52
|
end
|
50
53
|
|
54
|
+
case @aggregate
|
55
|
+
when 'all'
|
56
|
+
raise Fluent::ConfigError, "anomalydetect: `tag` must be specified with aggregate all" if @tag.nil?
|
57
|
+
when 'tag'
|
58
|
+
raise Fluent::ConfigError, "anomalydetect: `add_tag_prefix` must be specified with aggregate tag" if @add_tag_prefix.nil?
|
59
|
+
else
|
60
|
+
raise Fluent::ConfigError, "anomalydetect: aggregate allows tag/all"
|
61
|
+
end
|
62
|
+
|
63
|
+
@tag_prefix = "#{@add_tag_prefix}." if @add_tag_prefix
|
64
|
+
@tag_prefix_match = "#{@remove_tag_prefix}." if @remove_tag_prefix
|
65
|
+
@tag_proc =
|
66
|
+
if @tag_prefix and @tag_prefix_match
|
67
|
+
Proc.new {|tag| "#{@tag_prefix}#{lstrip(tag, @tag_prefix_match)}" }
|
68
|
+
elsif @tag_prefix_match
|
69
|
+
Proc.new {|tag| lstrip(tag, @tag_prefix_match) }
|
70
|
+
elsif @tag_prefix
|
71
|
+
Proc.new {|tag| "#{@tag_prefix}#{tag}" }
|
72
|
+
elsif @tag
|
73
|
+
Proc.new {|tag| @tag }
|
74
|
+
else
|
75
|
+
Proc.new {|tag| tag }
|
76
|
+
end
|
77
|
+
|
51
78
|
@counts = {}
|
52
79
|
@matches = {}
|
53
80
|
@mutex = Mutex.new
|
@@ -74,7 +101,7 @@ class Fluent::StatsNotifierOutput < Fluent::Output
|
|
74
101
|
count = 0; matches = {}
|
75
102
|
es.each do |time,record|
|
76
103
|
if record[key]
|
77
|
-
# @todo: make an option for
|
104
|
+
# @todo: make an option for calcuation in the same tag. now only sum is supported
|
78
105
|
matches[key] = (matches[key] ? matches[key] + record[key] : record[key])
|
79
106
|
end
|
80
107
|
count += 1
|
@@ -85,7 +112,7 @@ class Fluent::StatsNotifierOutput < Fluent::Output
|
|
85
112
|
@matches[tag] ||= {}
|
86
113
|
@mutex.synchronize do
|
87
114
|
if matches[key]
|
88
|
-
# @todo: make an option for
|
115
|
+
# @todo: make an option for calcuation in the same tag. now only sum is supported
|
89
116
|
@matches[tag][key] = (@matches[tag][key] ? @matches[tag][key] + matches[key] : matches[key])
|
90
117
|
end
|
91
118
|
@counts[tag] += count
|
@@ -119,15 +146,23 @@ class Fluent::StatsNotifierOutput < Fluent::Output
|
|
119
146
|
# This method is the real one to emit
|
120
147
|
def flush_emit(step)
|
121
148
|
time = Fluent::Engine.now
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
149
|
+
counts, matches, @counts, @matches = @counts, @matches, {}, {}
|
150
|
+
|
151
|
+
if @aggregate == 'all'
|
152
|
+
values = matches.values.map {|match| match[@target_key] }.compact
|
153
|
+
output = generate_output(values)
|
154
|
+
Fluent::Engine.emit(@tag, time, output) if output
|
155
|
+
else # aggregate tag
|
156
|
+
matches.each do |tag, match|
|
157
|
+
values = [match[@target_key]]
|
158
|
+
output = generate_output(values)
|
159
|
+
emit_tag = @tag_proc.call(tag)
|
160
|
+
Fluent::Engine.emit(emit_tag, time, output) if output
|
161
|
+
end
|
162
|
+
end
|
126
163
|
end
|
127
164
|
|
128
|
-
def generate_output(
|
129
|
-
values = matches.values.map {|match| match[@target_key] }.compact
|
130
|
-
|
165
|
+
def generate_output(values)
|
131
166
|
case @compare_with
|
132
167
|
when :sum
|
133
168
|
target_value = values.inject(:+)
|
@@ -145,6 +145,35 @@ describe Fluent::StatsNotifierOutput do
|
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
|
+
context 'aggregate' do
|
149
|
+
let(:emit) do
|
150
|
+
driver.run do
|
151
|
+
driver.emit_with_tag({"5xx_count"=>2}, time, 'foo.bar1')
|
152
|
+
driver.emit_with_tag({"5xx_count"=>6}, time, 'foo.bar2')
|
153
|
+
end
|
154
|
+
driver.instance.flush_emit(0)
|
155
|
+
end
|
156
|
+
|
157
|
+
context 'all' do
|
158
|
+
let(:config) { CONFIG + %[aggregate all \n tag foo \n compare_with sum] }
|
159
|
+
before do
|
160
|
+
Fluent::Engine.stub(:now).and_return(time)
|
161
|
+
Fluent::Engine.should_receive(:emit).with("foo", time, {"5xx_count"=>8.0})
|
162
|
+
end
|
163
|
+
it { emit }
|
164
|
+
end
|
165
|
+
|
166
|
+
context 'tag' do
|
167
|
+
let(:config) { CONFIG + %[aggregate tag \n add_tag_prefix add] }
|
168
|
+
before do
|
169
|
+
Fluent::Engine.stub(:now).and_return(time)
|
170
|
+
Fluent::Engine.should_receive(:emit).with("add.foo.bar1", time, {"5xx_count"=>2.0})
|
171
|
+
Fluent::Engine.should_receive(:emit).with("add.foo.bar2", time, {"5xx_count"=>6.0})
|
172
|
+
end
|
173
|
+
it { emit }
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
148
177
|
context 'compare_with' do
|
149
178
|
let(:emit) do
|
150
179
|
driver.run do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-stats-notifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naotoshi Seo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|