class Fluent::Plugin::RedisListMonitorInput

Input plugin which will monitor the size of a redis list and periodically output metrics to the login pipeline. @since 0.1.0

Public Class Methods

new() click to toggle source

Initialize new input plugin @since 0.1.0 @return [NilClass]

Calls superclass method Fluent::PluginMixin::Redis::new
# File lib/fluent/plugin/in_redis_list_monitor.rb, line 21
def initialize
  super
end

Public Instance Methods

action_poll() click to toggle source

Action to execute when the monitor event watcher executes

The monitor is simply responsible for outputting the queue length to the logs as well as detecting zero length lists.

@since 0.1.0 @return [NilClass]

# File lib/fluent/plugin/in_redis_list_monitor.rb, line 107
def action_poll
  now = Engine.now

  if sleeping?
    log.trace "redis worker is sleeping"
    return
  end

  list_size = @redis.llen(@key)

  event = {
    "timestamp" => now,
    "message" => "redis queue monitor",
    "hostname" => @host,
    "key" => @key,
    "size" => list_size
  }

  router.emit @tag, now, event
rescue => e
  log.error "error monitoring queue", :error => e
  log.error_backtrace
  sleep!(@retry_interval)
end
configure(config) click to toggle source

Initialize attributes and parameters @since 0.1.0 @return [NilClass]

Calls superclass method
# File lib/fluent/plugin/in_redis_list_monitor.rb, line 28
def configure(config)
  super

  configure_params(config)
  configure_locking(config)

  @queue_length = 0
  @retry_at     = nil
end
configure_locking(config) click to toggle source

Configure locking @since 0.1.0 @return [NilClass]

# File lib/fluent/plugin/in_redis_list_monitor.rb, line 51
def configure_locking(config)
  @storage  = storage_create(type: 'local')
  @lock_key = "redis:#{@key}:lock"
end
configure_params(config) click to toggle source

Configure plugin parameters @since 0.1.0 @return [NilClass]

# File lib/fluent/plugin/in_redis_list_monitor.rb, line 41
def configure_params(config)
  %w(host port key tag).each do |key|
    next if instance_variable_get("@#{key}")
    raise Fluent::ConfigError, "configuration key missing: #{key}"
  end
end
shutdown() click to toggle source

Tear down the plugin @since 0.1.0 @return [NilClass]

Calls superclass method
# File lib/fluent/plugin/in_redis_list_monitor.rb, line 79
def shutdown
  super
  shutdown_redis
end
sleep!(delay = @sleep_interval) click to toggle source

Set a sleep delay, ensuring that we will not attempt to fetch messages @since 0.1.0 @param [Integer] delay, the amount of seconds to wait @return [Integer] timestamp when this expires

# File lib/fluent/plugin/in_redis_list_monitor.rb, line 96
def sleep!(delay = @sleep_interval)
  @retry_at = Engine.now + delay
end
sleeping?() click to toggle source

Wether the poller has been temporarily disabled or should fetch messages been temporarily disabled @since 0.1.0 @return [TrueClass, FalseClass]

# File lib/fluent/plugin/in_redis_list_monitor.rb, line 88
def sleeping?
  @retry_at and @retry_at >= Engine.now
end
start() click to toggle source

Prepare the plugin event loop

This method will initialize the Redis connection object, create any required Redis structures as well as define and begin the event pollers.

@since 0.1.0 @return [NilClass]

Calls superclass method
# File lib/fluent/plugin/in_redis_list_monitor.rb, line 63
def start
  super

  start_redis
  start_poller
end
start_poller() click to toggle source
# File lib/fluent/plugin/in_redis_list_monitor.rb, line 70
def start_poller
  timer_execute(:poll, @poll_interval) do
    action_poll
  end
end