Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 50f8b61fea
Fetching contributors…

Cannot retrieve contributors at this time

file 45 lines (42 sloc) 1.27 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
class RedisCounters < Scout::Plugin
  needs 'redis'

  OPTIONS = <<-EOS
client_host:
name: Host
notes: "You will generally want this to be 'localhost'"
default: localhost
client_port:
name: Port
notes: Redis port to pass to the client library.
default: 6379
db:
name: Database
notes: Redis database ID to pass to the client library.
default: 0
password:
name: Password
notes: If you're using Redis' password authentication.
attributes: password
keys:
name: Keys to monitor
notes: A comma-separated list of incrementing keys to monitor value of.
EOS

  def build_report
    redis = Redis.new :port => option(:client_port),
                      :db => option(:db),
                      :password => option(:password),
                      :host => option(:client_host)

    if option(:keys)
      keys = option(:keys).split(',')
      keys.each do |key|
        begin
          value = redis.get(key).to_i
          counter(key.to_sym, value, :per => :second)
        rescue Errno::ECONNREFUSED => error
          return error( "Could not connect to Redis.",
                        "Make certain you've specified correct port, DB and password." )
        end
      end
    end
  end
end
Something went wrong with that request. Please try again.