fluent-plugin-ping-message 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +19 -3
- data/fluent-plugin-ping-message.gemspec +2 -2
- data/lib/fluent/plugin/out_ping_message.rb +107 -0
- metadata +4 -3
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# fluent-plugin-ping-message
|
2
2
|
|
3
|
-
Fluentd
|
3
|
+
Fluentd plugins:
|
4
|
+
|
5
|
+
* to generate ping messages for monitoring of heatbeats
|
6
|
+
* to check ping messages not arrived, and emits notifications
|
4
7
|
|
5
8
|
## Configuration
|
6
9
|
|
@@ -25,10 +28,23 @@ Change ping message interval into 30 seconds, and fix tag and 'data':
|
|
25
28
|
#=> tag: 'ping.webserver'
|
26
29
|
# message: {'data' => 'ping message from your.hostname.local'}
|
27
30
|
|
31
|
+
### PingMessageCheckerOutput
|
32
|
+
|
33
|
+
To receive ping messages and checks ping message in-arrival, use `type ping_message_checker`:
|
34
|
+
|
35
|
+
<match ping.**>
|
36
|
+
type ping_message_checker
|
37
|
+
tag missing.ping
|
38
|
+
check_interval 3600 # 1hour by default
|
39
|
+
notification_times 3 # 3 times by default
|
40
|
+
</match>
|
41
|
+
|
42
|
+
With this configuration, this plugin save the list of ping messages' 'data' field values. And then, at the time of ping message missing, notification message emitted with `tag`.
|
43
|
+
|
28
44
|
## TODO
|
29
45
|
|
30
|
-
*
|
31
|
-
|
46
|
+
* add feature to output ping messages list
|
47
|
+
* patches welcome!
|
32
48
|
|
33
49
|
## Copyright
|
34
50
|
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
Gem::Specification.new do |gem|
|
3
3
|
gem.name = "fluent-plugin-ping-message"
|
4
|
-
gem.version = "0.0.
|
4
|
+
gem.version = "0.0.3"
|
5
5
|
gem.authors = ["TAGOMORI Satoshi"]
|
6
6
|
gem.email = ["tagomoris@gmail.com"]
|
7
7
|
gem.description = %q{for heartbeat monitoring of Fluentd processes}
|
8
|
-
gem.summary = %q{Fluentd plugin to send ping
|
8
|
+
gem.summary = %q{Fluentd plugin to send/check ping messages}
|
9
9
|
gem.homepage = "https://github.com/tagomoris/fluent-plugin-ping-message"
|
10
10
|
|
11
11
|
gem.files = `git ls-files`.split($\)
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'fluent/mixin/config_placeholders'
|
2
|
+
|
3
|
+
class Fluent::PingMessageCheckerOutput < Fluent::Output
|
4
|
+
Fluent::Plugin.register_output('ping_message_checker', self)
|
5
|
+
|
6
|
+
config_param :data_field, :string, :default => 'data'
|
7
|
+
|
8
|
+
config_param :tag, :string
|
9
|
+
|
10
|
+
config_param :notifications, :bool, :default => true
|
11
|
+
# config_param :report_list, :bool, :default => false # not implemented now
|
12
|
+
|
13
|
+
config_param :check_interval, :integer, :default => 3600
|
14
|
+
config_param :notification_times, :integer, :default => 3
|
15
|
+
|
16
|
+
config_param :exclude_pattern, :string, :default => nil
|
17
|
+
|
18
|
+
include Fluent::Mixin::ConfigPlaceholders
|
19
|
+
|
20
|
+
def configure(conf)
|
21
|
+
super
|
22
|
+
@exclude_regex = @exclude_pattern ? Regexp.compile(@exclude_pattern) : nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def start
|
26
|
+
super
|
27
|
+
@checks = {}
|
28
|
+
# 'data' => notification_counts
|
29
|
+
# -1: checked in previous term, but not in this term
|
30
|
+
# 0: checked in this term
|
31
|
+
# 1,2,...: counts of ping missing notifications
|
32
|
+
@mutex = Mutex.new
|
33
|
+
start_watch
|
34
|
+
end
|
35
|
+
|
36
|
+
def shutdown
|
37
|
+
super
|
38
|
+
@watcher.terminate
|
39
|
+
@watcher.join
|
40
|
+
end
|
41
|
+
|
42
|
+
def start_watch
|
43
|
+
@watcher = Thread.new(&method(:watch))
|
44
|
+
end
|
45
|
+
|
46
|
+
def update_state(list)
|
47
|
+
@mutex.synchronize do
|
48
|
+
list.each do |data|
|
49
|
+
if not @checks.has_key?(data) or @checks[data] != 0
|
50
|
+
@checks[data] = 0
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def check_and_flush
|
57
|
+
notifications = []
|
58
|
+
|
59
|
+
@mutex.synchronize do
|
60
|
+
@checks.keys.each do |key|
|
61
|
+
if @checks[key] == 0
|
62
|
+
@checks[key] = -1
|
63
|
+
|
64
|
+
elsif @checks[key] < 0
|
65
|
+
notifications.push(key)
|
66
|
+
@checks[key] = 1
|
67
|
+
|
68
|
+
else # @checks[key] > 0
|
69
|
+
if @checks[key] < @notification_times
|
70
|
+
notifications.push(key)
|
71
|
+
@checks[key] += 1
|
72
|
+
else
|
73
|
+
@checks.delete(key)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
if @notifications
|
80
|
+
notifications.each do |data|
|
81
|
+
Fluent::Engine.emit(@tag, Fluent::Engine.now, data)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def watch
|
87
|
+
@last_checked = Fluent::Engine.now
|
88
|
+
loop do
|
89
|
+
sleep 1
|
90
|
+
if Fluent::Engine.now - @last_checked >= @check_interval
|
91
|
+
check_and_flush()
|
92
|
+
@last_checked = Fluent::Engine.now
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def emit(tag, es, chain)
|
98
|
+
datalist = []
|
99
|
+
es.each do |time,record|
|
100
|
+
datalist.push record[@data_field] if @exclude_regex.nil? or not @exclude_regex.match(record[@data_field])
|
101
|
+
end
|
102
|
+
datalist.uniq!
|
103
|
+
update_state(datalist)
|
104
|
+
|
105
|
+
chain.next
|
106
|
+
end
|
107
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-ping-message
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fluentd
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- Rakefile
|
90
90
|
- fluent-plugin-ping-message.gemspec
|
91
91
|
- lib/fluent/plugin/in_ping_message.rb
|
92
|
+
- lib/fluent/plugin/out_ping_message.rb
|
92
93
|
- test/helper.rb
|
93
94
|
homepage: https://github.com/tagomoris/fluent-plugin-ping-message
|
94
95
|
licenses: []
|
@@ -113,6 +114,6 @@ rubyforge_project:
|
|
113
114
|
rubygems_version: 1.8.21
|
114
115
|
signing_key:
|
115
116
|
specification_version: 3
|
116
|
-
summary: Fluentd plugin to send ping
|
117
|
+
summary: Fluentd plugin to send/check ping messages
|
117
118
|
test_files:
|
118
119
|
- test/helper.rb
|