redis-stat 0.2.5 → 0.2.6
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/README.md +1 -0
- data/lib/redis-stat.rb +19 -16
- data/lib/redis-stat/option.rb +4 -0
- data/lib/redis-stat/version.rb +1 -1
- data/test/test_redis-stat.rb +39 -3
- metadata +2 -2
data/README.md
CHANGED
@@ -17,6 +17,7 @@ usage: redis-stat [HOST[:PORT] ...] [INTERVAL [COUNT]]
|
|
17
17
|
--csv=OUTPUT_CSV_FILE_PATH Save the result in CSV format
|
18
18
|
-v, --verbose Show more info
|
19
19
|
--style=STYLE Output style: unicode|ascii
|
20
|
+
--no-color Suppress ANSI color codes
|
20
21
|
--version Show version
|
21
22
|
--help Show this message
|
22
23
|
```
|
data/lib/redis-stat.rb
CHANGED
@@ -22,6 +22,7 @@ class RedisStat
|
|
22
22
|
}
|
23
23
|
@interval = options[:interval]
|
24
24
|
@max_count = options[:count]
|
25
|
+
@mono = options[:mono]
|
25
26
|
@colors = options[:colors] || COLORS
|
26
27
|
@csv = options[:csv]
|
27
28
|
@auth = options[:auth]
|
@@ -49,6 +50,7 @@ class RedisStat
|
|
49
50
|
end
|
50
51
|
|
51
52
|
@started_at = Time.now
|
53
|
+
all_measures = MEASURES.values.inject(:+).uniq - [:at]
|
52
54
|
prev_info = nil
|
53
55
|
loop do
|
54
56
|
info = {}.insensitive
|
@@ -62,9 +64,9 @@ class RedisStat
|
|
62
64
|
@redises.pmap(@redises.length) { |redis|
|
63
65
|
redis.info.insensitive
|
64
66
|
}.each do |rinfo|
|
65
|
-
|
67
|
+
all_measures.each do |k|
|
66
68
|
info[k] ||= []
|
67
|
-
info[k] <<
|
69
|
+
info[k] << rinfo[k]
|
68
70
|
end
|
69
71
|
end
|
70
72
|
|
@@ -191,18 +193,8 @@ private
|
|
191
193
|
)
|
192
194
|
tab << [nil] + @hosts.map { |h| ansi(:bold, :green) { h } }
|
193
195
|
tab.separator!
|
194
|
-
[
|
195
|
-
:
|
196
|
-
:process_id,
|
197
|
-
:uptime_in_seconds,
|
198
|
-
:uptime_in_days,
|
199
|
-
:gcc_version,
|
200
|
-
:role,
|
201
|
-
:connected_slaves,
|
202
|
-
:aof_enabled,
|
203
|
-
:vm_enabled
|
204
|
-
].each do |key|
|
205
|
-
tab << [ansi(:bold) { key }] + info[key] if info[key]
|
196
|
+
MEASURES[:static].each do |key|
|
197
|
+
tab << [ansi(:bold) { key }] + info[key] unless info[key].compact.empty?
|
206
198
|
end
|
207
199
|
@os.puts tab
|
208
200
|
end
|
@@ -211,7 +203,7 @@ private
|
|
211
203
|
table = Tabularize.new :unicode => false,
|
212
204
|
:align => :right,
|
213
205
|
:border_style => @style,
|
214
|
-
:border_color => ANSI::Code.red,
|
206
|
+
:border_color => @mono ? nil : ANSI::Code.red,
|
215
207
|
:vborder => ' ',
|
216
208
|
:pad_left => 0,
|
217
209
|
:pad_right => 0,
|
@@ -295,7 +287,7 @@ private
|
|
295
287
|
end
|
296
288
|
|
297
289
|
def ansi *args, &block
|
298
|
-
if args.empty?
|
290
|
+
if @mono || args.empty?
|
299
291
|
block.call
|
300
292
|
else
|
301
293
|
ANSI::Code.ansi *args, &block
|
@@ -303,6 +295,17 @@ private
|
|
303
295
|
end
|
304
296
|
|
305
297
|
MEASURES = {
|
298
|
+
:static => [
|
299
|
+
:redis_version,
|
300
|
+
:process_id,
|
301
|
+
:uptime_in_seconds,
|
302
|
+
:uptime_in_days,
|
303
|
+
:gcc_version,
|
304
|
+
:role,
|
305
|
+
:connected_slaves,
|
306
|
+
:aof_enabled,
|
307
|
+
:vm_enabled
|
308
|
+
],
|
306
309
|
:default => [
|
307
310
|
:at,
|
308
311
|
:used_cpu_user,
|
data/lib/redis-stat/option.rb
CHANGED
data/lib/redis-stat/version.rb
CHANGED
data/test/test_redis-stat.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
2
3
|
|
3
4
|
require 'rubygems'
|
4
|
-
require 'test
|
5
|
+
require 'test-unit'
|
5
6
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
7
|
require 'redis-stat'
|
8
|
+
require 'redis'
|
9
|
+
require 'stringio'
|
7
10
|
|
8
11
|
class TestRedisStat < Test::Unit::TestCase
|
9
12
|
def test_humanize_number
|
@@ -87,6 +90,9 @@ class TestRedisStat < Test::Unit::TestCase
|
|
87
90
|
:csv => '/tmp/a.csv',
|
88
91
|
:style => :ascii
|
89
92
|
}.sort, options.sort)
|
93
|
+
|
94
|
+
options = RedisStat::Option.parse(%w[--no-color])
|
95
|
+
assert_equal true, options[:mono]
|
90
96
|
end
|
91
97
|
|
92
98
|
def test_option_parse_invalid
|
@@ -107,7 +113,7 @@ class TestRedisStat < Test::Unit::TestCase
|
|
107
113
|
def test_start
|
108
114
|
csv = '/tmp/redis-stat.csv'
|
109
115
|
cnt = 100
|
110
|
-
rs = RedisStat.new :hosts => %w[localhost] * 5, :interval => 0.
|
116
|
+
rs = RedisStat.new :hosts => %w[localhost] * 5, :interval => 0.01, :count => cnt,
|
111
117
|
:verbose => true, :csv => csv, :auth => 'pw'
|
112
118
|
rs.start $stdout
|
113
119
|
|
@@ -115,6 +121,36 @@ class TestRedisStat < Test::Unit::TestCase
|
|
115
121
|
ensure
|
116
122
|
File.unlink csv
|
117
123
|
end
|
118
|
-
end
|
119
124
|
|
125
|
+
def test_mono
|
126
|
+
[true, false].each do |mono|
|
127
|
+
rs = RedisStat.new :hosts => %w[localhost] * 5, :interval => 0.02, :count => 20,
|
128
|
+
:verbose => true, :auth => 'pw', :mono => mono
|
129
|
+
output = StringIO.new
|
130
|
+
rs.start output
|
131
|
+
puts output.string
|
132
|
+
assert_equal mono, output.string !~ /\e\[\d*(;\d+)*m/
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_static_info_of_mixed_versions
|
137
|
+
# prerequisite
|
138
|
+
r1 = Redis.new(:host => 'localhost')
|
139
|
+
r2 = Redis.new(:host => 'localhost', :port => 6380)
|
140
|
+
|
141
|
+
if r1.info['redis_version'] =~ /^2\.4/ && r2.info['redis_version'] =~ /^2\.2/
|
142
|
+
rs = RedisStat.new :hosts => %w[localhost:6380 localhost], :interval => 1, :count => 1,
|
143
|
+
:auth => 'pw', :style => :ascii
|
144
|
+
output = StringIO.new
|
145
|
+
rs.start output
|
146
|
+
vline = output.string.lines.select { |line| line =~ /gcc_version/ }.first
|
147
|
+
puts vline.gsub(/ +/, ' ')
|
148
|
+
assert vline.gsub(/ +/, ' ').include?('| | 4.2.1 |')
|
149
|
+
else
|
150
|
+
raise NotImplementedError.new # FIXME
|
151
|
+
end
|
152
|
+
rescue Redis::CannotConnectError, NotImplementedError
|
153
|
+
pend "redises not ready"
|
154
|
+
end
|
155
|
+
end
|
120
156
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-stat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ansi
|