class RedisStatus
Constants
- CLIENT_PROCESS_NAME
- CONFIG_LOCATIONS
- GUESS_HOST
- SERVER_PROCESS_NAME
Public Class Methods
cli_exec(command, *args)
click to toggle source
# File lib/redis_status.rb, line 69 def self.cli_exec(command, *args) `#{CLIENT_PROCESS_NAME} -h #{status[:bind] || GUESS_HOST} #{command.to_s} #{args.join}` end
cli_info()
click to toggle source
# File lib/redis_status.rb, line 73 def self.cli_info parse_settings(cli_exec :info) end
conf()
click to toggle source
# File lib/redis_status.rb, line 44 def self.conf parse_settings(`cat #{self.config_filename}`) end
config(key)
click to toggle source
# File lib/redis_status.rb, line 77 def self.config(key) output = cli_exec "config get", key result = output.split(/\n|\r/)[1] set_status(key, result) return result end
config_filename()
click to toggle source
# File lib/redis_status.rb, line 40 def self.config_filename process_info[:args].nil? ? self.find_config : process_info[:args][0] end
db_file()
click to toggle source
# File lib/redis_status.rb, line 84 def self.db_file File.join(config(:dir),config(:dbfilename)) end
dbs()
click to toggle source
# File lib/redis_status.rb, line 88 def self.dbs self.cli_info.select{|k,v| k.to_s =~ /db/} end
errors?()
click to toggle source
# File lib/redis_status.rb, line 104 def self.errors? !recent_errors.empty? end
find_config()
click to toggle source
# File lib/redis_status.rb, line 36 def self.find_config CONFIG_LOCATIONS.select{|f| File.exist?(f) }.first end
last_save()
click to toggle source
# File lib/redis_status.rb, line 100 def self.last_save Time.at(cli_exec(:lastsave).match(/\d+$/).to_s.to_i) end
memory_allocation()
click to toggle source
# File lib/redis_status.rb, line 108 def self.memory_allocation self.cli_info[:allocation_stats].split(",").map{|e| e.split("=").select{|i| i =~ /\d+/}} end
method_missing(m, *args, &block)
click to toggle source
# File lib/redis_status.rb, line 112 def self.method_missing(m, *args, &block) return @@redis_status[m.to_sym] end
parse_settings(settings)
click to toggle source
Accepts output from ‘redis-cli info` or the contents of redis.conf and parses it, populating a hash with the results
# File lib/redis_status.rb, line 57 def self.parse_settings(settings) set = {} settings.split(/\n|\r/).reject{|line| line =~ /^#/ || line.strip == ""}.map{|line| line.split(/:|\s+/)}.reject{|kv| kv.size != 2 }.each do |keypair| set[keypair[0].to_sym] = keypair[1] end set end
pid()
click to toggle source
# File lib/redis_status.rb, line 28 def self.pid process_info[:pid] end
process_info()
click to toggle source
# File lib/redis_status.rb, line 10 def self.process_info @info = `ps aux | grep "#{SERVER_PROCESS_NAME}" | grep -v "grep"`.strip.split(/\s+/) { :user => @info[0], :pid => @info[1], :cpu=> @info[2], :mem=> @info[3], :vsz=> @info[4], :rss=> @info[5], :tt=> @info[6], :stat=> @info[7], :started=> @info[8], :time=> @info[9], :command=> @info[10], :args=> @info[11..-1] } end
recent_errors()
click to toggle source
# File lib/redis_status.rb, line 96 def self.recent_errors tail.select{|line| line.match(/#/)} end
running?()
click to toggle source
# File lib/redis_status.rb, line 32 def self.running? !self.pid.nil? end
set_status(*args)
click to toggle source
# File lib/redis_status.rb, line 48 def self.set_status(*args) if args.size == 1 && args[0].is_a?(Hash) @@redis_status.merge!(args[0]) elsif args.size == 2 && [Symbol, String].include?(args[0].class) @@redis_status[args[0].to_sym] = args[1] end end
status(key=nil)
click to toggle source
# File lib/redis_status.rb, line 65 def self.status(key=nil) key.nil? ? @@redis_status : @@redis_status[key.to_sym] end
tail()
click to toggle source
# File lib/redis_status.rb, line 92 def self.tail `tail -n 50 #{self.conf[:logfile]}`.split(/\n|\r/) end