redis_status 0.1.0

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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.0"
12
+ gem "rcov", ">= 0"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.6.0)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rake (0.8.7)
10
+ rcov (0.9.9)
11
+ shoulda (2.11.3)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (~> 1.0.0)
18
+ jeweler (~> 1.6.0)
19
+ rcov
20
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Justin Thibault
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = redis_status
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to redis_status
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Justin Thibault. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "redis_status"
18
+ gem.homepage = "http://github.com/justinvt/redis_status"
19
+ gem.license = "MIT"
20
+ gem.summary = "Provides information about redis-server"
21
+ gem.description = "redis-status combines information from redis-cli info, redis.conf, and other sources to give a snapshot of the current state of redis-server"
22
+ gem.email = "jvthibault@gmail.com"
23
+ gem.authors = ["Justin Thibault"]
24
+ # dependencies defined in Gemfile
25
+ gem.executables = ['redis-status']
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ test.rcov_opts << '--exclude "gems/*"'
42
+ end
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "redis_status #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/redis-status ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'redis_status'
5
+
6
+
7
+ puts RedisStatus.status.inspect
@@ -0,0 +1,117 @@
1
+ class RedisStatus
2
+
3
+ @@redis_status = {}
4
+
5
+ SERVER_PROCESS_NAME="redis-server"
6
+ CLIENT_PROCESS_NAME="redis-cli"
7
+ GUESS_HOST=`ifconfig | grep -o -P "(192|127)\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" | head -n 1`.strip
8
+ CONFIG_LOCATIONS=["/etc/redis.conf", "/etc/redis/redis.conf", "/usr/local/etc/redis.conf"]
9
+
10
+ def self.process_info
11
+ @info = `ps aux | grep "#{SERVER_PROCESS_NAME}" | grep -v "grep"`.strip.split(/\s+/)
12
+ {
13
+ :user => @info[0],
14
+ :pid => @info[1],
15
+ :cpu=> @info[2],
16
+ :mem=> @info[3],
17
+ :vsz=> @info[4],
18
+ :rss=> @info[5],
19
+ :tt=> @info[6],
20
+ :stat=> @info[7],
21
+ :started=> @info[8],
22
+ :time=> @info[9],
23
+ :command=> @info[10],
24
+ :args=> @info[11..-1]
25
+ }
26
+ end
27
+
28
+ def self.pid
29
+ process_info[:pid]
30
+ end
31
+
32
+ def self.running?
33
+ !self.pid.nil?
34
+ end
35
+
36
+ def self.find_config
37
+ CONFIG_LOCATIONS.select{|f| File.exist?(f) }.first
38
+ end
39
+
40
+ def self.config_filename
41
+ process_info[:args].nil? ? self.find_config : process_info[:args][0]
42
+ end
43
+
44
+ def self.conf
45
+ parse_settings(`cat #{config_filename || "/dev/null"}`)
46
+ end
47
+
48
+ def self.set_status(*args)
49
+ if args.size == 1 && args[0].is_a?(Hash)
50
+ @@redis_status.merge!(args[0])
51
+ elsif args.size == 2 && [Symbol, String].include?(args[0].class)
52
+ @@redis_status[args[0].to_sym] = args[1]
53
+ end
54
+ end
55
+
56
+ # Accepts output from `redis-cli info` or the contents of redis.conf and parses it, populating a hash with the results
57
+ def self.parse_settings(settings)
58
+ set = {}
59
+ settings.split(/\n|\r/).reject{|line| line =~ /^#/ || line.strip == ""}.map{|line| line.split(/:|\s+/)}.reject{|kv| kv.size != 2 }.each do |keypair|
60
+ set[keypair[0].to_sym] = keypair[1]
61
+ end
62
+ set
63
+ end
64
+
65
+ def self.status(key=nil)
66
+ key.nil? ? @@redis_status : @@redis_status[key.to_sym]
67
+ end
68
+
69
+ def self.cli_exec(command, *args)
70
+ `#{CLIENT_PROCESS_NAME} -h #{status[:bind] || GUESS_HOST} #{command.to_s} #{args.join}`
71
+ end
72
+
73
+ def self.cli_info
74
+ parse_settings(cli_exec :info)
75
+ end
76
+
77
+ def self.config(key)
78
+ output = cli_exec "config get", key
79
+ result = output.split(/\n|\r/)[1]
80
+ set_status(key, result)
81
+ return result
82
+ end
83
+
84
+ def self.db_file
85
+ File.join(config(:dir),config(:dbfilename))
86
+ end
87
+
88
+ def self.dbs
89
+ self.cli_info.select{|k,v| k.to_s =~ /db/}
90
+ end
91
+
92
+ def self.tail
93
+ `tail -n 50 #{self.conf[:logfile] || "/dev/null"}`.split(/\n|\r/)
94
+ end
95
+
96
+ def self.recent_errors
97
+ tail.select{|line| line.match(/#/)}
98
+ end
99
+
100
+ def self.last_save
101
+ Time.at(cli_exec(:lastsave).match(/\d+$/).to_s.to_i)
102
+ end
103
+
104
+ def self.errors?
105
+ !recent_errors.empty?
106
+ end
107
+
108
+ def self.memory_allocation
109
+ self.cli_info[:allocation_stats].split(",").map{|e| e.split("=").select{|i| i =~ /\d+/}}
110
+ end
111
+
112
+ def self.method_missing(m, *args, &block)
113
+ return @@redis_status[m.to_sym]
114
+ end
115
+
116
+
117
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'redis_status'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestRedisStatus < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redis_status
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Justin Thibault
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-05-17 00:00:00 -07:00
19
+ default_executable: redis-status
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 3
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ version_requirements: *id001
32
+ name: shoulda
33
+ prerelease: false
34
+ type: :development
35
+ - !ruby/object:Gem::Dependency
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ hash: 23
42
+ segments:
43
+ - 1
44
+ - 0
45
+ - 0
46
+ version: 1.0.0
47
+ version_requirements: *id002
48
+ name: bundler
49
+ prerelease: false
50
+ type: :development
51
+ - !ruby/object:Gem::Dependency
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ hash: 15
58
+ segments:
59
+ - 1
60
+ - 6
61
+ - 0
62
+ version: 1.6.0
63
+ version_requirements: *id003
64
+ name: jeweler
65
+ prerelease: false
66
+ type: :development
67
+ - !ruby/object:Gem::Dependency
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ version_requirements: *id004
78
+ name: rcov
79
+ prerelease: false
80
+ type: :development
81
+ description: redis-status combines information from redis-cli info, redis.conf, and other sources to give a snapshot of the current state of redis-server
82
+ email: jvthibault@gmail.com
83
+ executables:
84
+ - redis-status
85
+ extensions: []
86
+
87
+ extra_rdoc_files:
88
+ - LICENSE.txt
89
+ - README.rdoc
90
+ files:
91
+ - .document
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - LICENSE.txt
95
+ - README.rdoc
96
+ - Rakefile
97
+ - VERSION
98
+ - bin/redis-status
99
+ - lib/redis_status.rb
100
+ - test/helper.rb
101
+ - test/test_redis_status.rb
102
+ has_rdoc: true
103
+ homepage: http://github.com/justinvt/redis_status
104
+ licenses:
105
+ - MIT
106
+ post_install_message:
107
+ rdoc_options: []
108
+
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ hash: 3
117
+ segments:
118
+ - 0
119
+ version: "0"
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ hash: 3
126
+ segments:
127
+ - 0
128
+ version: "0"
129
+ requirements: []
130
+
131
+ rubyforge_project:
132
+ rubygems_version: 1.6.1
133
+ signing_key:
134
+ specification_version: 3
135
+ summary: Provides information about redis-server
136
+ test_files: []
137
+