class Riemann::Tools::Rpush
Public Class Methods
new()
click to toggle source
# File bin/riemann-rpush, line 16 def initialize @redis = ::Redis.new({url: opts[:redis_url]}) @queue_size_warning = opts.fetch(:queue_size_warning) @queue_size_critical = opts.fetch(:queue_size_critical) end
Public Instance Methods
tick()
click to toggle source
# File bin/riemann-rpush, line 22 def tick keys = @redis.smembers('rpush:notifications:all') types_count(keys).each_pair do |type, count| deliver_type_count(type, count) end deliver_total(keys.size) end
Private Instance Methods
deliver_total(total)
click to toggle source
# File bin/riemann-rpush, line 55 def deliver_total(total) state = if total >= @queue_size_critical 'critical' elsif total >= @queue_size_warning 'warning' else 'ok' end msg = { metric: total, service: 'rpush queue size', state: state } report msg end
deliver_type_count(type, count)
click to toggle source
# File bin/riemann-rpush, line 72 def deliver_type_count(type, count) state = if count >= @queue_size_critical 'critical' elsif count >= @queue_size_warning 'warning' else 'ok' end msg = { metric: count, service: "rpush #{type}-queue size", state: state } report msg end
get_notification_type(key)
click to toggle source
# File bin/riemann-rpush, line 48 def get_notification_type(key) type = @redis.hget("rpush:notifications:#{key}", 'type') type.encode("ASCII-8BIT", invalid: :replace, replace: '').match(/Redis::(.*)::Notification/)[1].downcase rescue opts.fetch(:treat_sent_as) end
types_count(keys)
click to toggle source
# File bin/riemann-rpush, line 33 def types_count(keys) keys.inject({ 'apns' => 0, 'gcm' => 0, 'wns' => 0 }) do |h, key| type = get_notification_type(key) if type h[type] ||= 0 h[type] += 1 end h end end