fluent-plugin-redis-list-source 1.0 → 1.1
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6d3799e69a5c4d79623983db23059316520bed9825ed2ff4f7c7f7ef1779b6d
|
4
|
+
data.tar.gz: 2af48197fd04f15b79b3bc8b8cc330fdbb1b1ae5765de54983fa5518b6ed820d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5579f414de308e733cb6e8fdfa5e7b2102b59ee3caa9db634cc4de05d5dabab60b77d602fb9af54c38c11adc783372fb14e72eebaaf4e86e2e17f39781b3e390
|
7
|
+
data.tar.gz: c2fa38977a67523d865e28ed09b2768381f903af5f33bdc0c802bfc4eb6826c8e70830f67bfd55cd852c46e88d091213eccc3a83b9daaa2d813a05ad7a31146d
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-redis-list-source
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.1'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikita Kazeichev
|
@@ -89,7 +89,6 @@ files:
|
|
89
89
|
- ".gitignore"
|
90
90
|
- README.md
|
91
91
|
- fluent-plugin-redis-list-source.gemspec
|
92
|
-
- lib/fluent/plugin/in_redis_list_monitor.rb
|
93
92
|
- lib/fluent/plugin/in_redis_list_poller.rb
|
94
93
|
- lib/fluent/plugin_mixin/redis.rb
|
95
94
|
homepage: https://github.com/kazeichev/fluent-plugin-redis_list_poller
|
@@ -1,133 +0,0 @@
|
|
1
|
-
require "fluent/plugin/input"
|
2
|
-
require "fluent/plugin_mixin/redis"
|
3
|
-
|
4
|
-
module Fluent
|
5
|
-
module Plugin
|
6
|
-
# Input plugin which will monitor the size of a redis list and periodically
|
7
|
-
# output metrics to the login pipeline.
|
8
|
-
# @since 0.1.0
|
9
|
-
class RedisListMonitorInput < Input
|
10
|
-
Plugin.register_input('redis_list_monitor', self)
|
11
|
-
|
12
|
-
include Fluent::PluginMixin::Redis
|
13
|
-
helpers :timer
|
14
|
-
|
15
|
-
# input plugin parameters
|
16
|
-
config_param :tag, :string, :default => nil
|
17
|
-
|
18
|
-
# Initialize new input plugin
|
19
|
-
# @since 0.1.0
|
20
|
-
# @return [NilClass]
|
21
|
-
def initialize
|
22
|
-
super
|
23
|
-
end
|
24
|
-
|
25
|
-
# Initialize attributes and parameters
|
26
|
-
# @since 0.1.0
|
27
|
-
# @return [NilClass]
|
28
|
-
def configure(config)
|
29
|
-
super
|
30
|
-
|
31
|
-
configure_params(config)
|
32
|
-
configure_locking(config)
|
33
|
-
|
34
|
-
@queue_length = 0
|
35
|
-
@retry_at = nil
|
36
|
-
end
|
37
|
-
|
38
|
-
# Configure plugin parameters
|
39
|
-
# @since 0.1.0
|
40
|
-
# @return [NilClass]
|
41
|
-
def configure_params(config)
|
42
|
-
%w(host port key tag).each do |key|
|
43
|
-
next if instance_variable_get("@#{key}")
|
44
|
-
raise Fluent::ConfigError, "configuration key missing: #{key}"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
# Configure locking
|
49
|
-
# @since 0.1.0
|
50
|
-
# @return [NilClass]
|
51
|
-
def configure_locking(config)
|
52
|
-
@storage = storage_create(type: 'local')
|
53
|
-
@lock_key = "redis:#{@key}:lock"
|
54
|
-
end
|
55
|
-
|
56
|
-
# Prepare the plugin event loop
|
57
|
-
#
|
58
|
-
# This method will initialize the Redis connection object, create any required Redis structures as well
|
59
|
-
# as define and begin the event pollers.
|
60
|
-
#
|
61
|
-
# @since 0.1.0
|
62
|
-
# @return [NilClass]
|
63
|
-
def start
|
64
|
-
super
|
65
|
-
|
66
|
-
start_redis
|
67
|
-
start_poller
|
68
|
-
end
|
69
|
-
|
70
|
-
def start_poller
|
71
|
-
timer_execute(:poll, @poll_interval) do
|
72
|
-
action_poll
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# Tear down the plugin
|
77
|
-
# @since 0.1.0
|
78
|
-
# @return [NilClass]
|
79
|
-
def shutdown
|
80
|
-
super
|
81
|
-
shutdown_redis
|
82
|
-
end
|
83
|
-
|
84
|
-
# Wether the poller has been temporarily disabled or should fetch messages
|
85
|
-
# been temporarily disabled
|
86
|
-
# @since 0.1.0
|
87
|
-
# @return [TrueClass, FalseClass]
|
88
|
-
def sleeping?
|
89
|
-
@retry_at and @retry_at >= Engine.now
|
90
|
-
end
|
91
|
-
|
92
|
-
# Set a sleep delay, ensuring that we will not attempt to fetch messages
|
93
|
-
# @since 0.1.0
|
94
|
-
# @param [Integer] delay, the amount of seconds to wait
|
95
|
-
# @return [Integer] timestamp when this expires
|
96
|
-
def sleep!(delay = @sleep_interval)
|
97
|
-
@retry_at = Engine.now + delay
|
98
|
-
end
|
99
|
-
|
100
|
-
# Action to execute when the monitor event watcher executes
|
101
|
-
#
|
102
|
-
# The monitor is simply responsible for outputting the queue length to
|
103
|
-
# the logs as well as detecting zero length lists.
|
104
|
-
#
|
105
|
-
# @since 0.1.0
|
106
|
-
# @return [NilClass]
|
107
|
-
def action_poll
|
108
|
-
now = Engine.now
|
109
|
-
|
110
|
-
if sleeping?
|
111
|
-
log.trace "redis worker is sleeping"
|
112
|
-
return
|
113
|
-
end
|
114
|
-
|
115
|
-
list_size = @redis.llen(@key)
|
116
|
-
|
117
|
-
event = {
|
118
|
-
"timestamp" => now,
|
119
|
-
"message" => "redis queue monitor",
|
120
|
-
"hostname" => @host,
|
121
|
-
"key" => @key,
|
122
|
-
"size" => list_size
|
123
|
-
}
|
124
|
-
|
125
|
-
router.emit @tag, now, event
|
126
|
-
rescue => e
|
127
|
-
log.error "error monitoring queue", :error => e
|
128
|
-
log.error_backtrace
|
129
|
-
sleep!(@retry_interval)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|