redis-stat 0.2.0 → 0.2.1
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 +21 -12
- data/lib/redis-stat/option.rb +4 -0
- data/lib/redis-stat/version.rb +1 -1
- data/test/test_redis-stat.rb +2 -1
- metadata +2 -2
data/README.md
CHANGED
data/lib/redis-stat.rb
CHANGED
@@ -12,28 +12,37 @@ class RedisStat
|
|
12
12
|
DEFAULT_TERM_HEIGHT = 25
|
13
13
|
|
14
14
|
def initialize options = {}
|
15
|
-
|
16
|
-
@hosts =
|
15
|
+
options = RedisStat::Option::DEFAULT.merge options
|
16
|
+
@hosts = options[:hosts]
|
17
17
|
@redises = @hosts.map { |e|
|
18
18
|
host, port = e.split(':')
|
19
19
|
Redis.new(Hash[ {:host => host, :port => port}.select { |k, v| v } ])
|
20
20
|
}
|
21
|
-
@
|
21
|
+
@interval = options[:interval]
|
22
|
+
@max_count = options[:count]
|
23
|
+
@colors = options[:colors] || COLORS
|
24
|
+
@csv = options[:csv]
|
25
|
+
@auth = options[:auth]
|
26
|
+
@measures = MEASURES[ options[:verbose] ? :verbose : :default ]
|
22
27
|
@count = 0
|
23
|
-
@colors = @options[:colors] || COLORS
|
24
28
|
end
|
25
29
|
|
26
30
|
def start output_stream
|
27
31
|
@os = output_stream
|
28
32
|
trap('INT') { Thread.main.raise Interrupt }
|
29
33
|
|
30
|
-
csv = File.open(@options[:csv], 'w') if @options[:csv]
|
31
|
-
update_term_size!
|
32
|
-
|
33
|
-
|
34
34
|
begin
|
35
|
-
|
36
|
-
|
35
|
+
csv = File.open(@csv, 'w') if @csv
|
36
|
+
update_term_size!
|
37
|
+
|
38
|
+
# Warm-up / authenticate only when needed
|
39
|
+
@redises.each do |r|
|
40
|
+
begin
|
41
|
+
r.info
|
42
|
+
rescue Redis::CommandError
|
43
|
+
r.auth @auth if @auth
|
44
|
+
end
|
45
|
+
end
|
37
46
|
|
38
47
|
@started_at = Time.now
|
39
48
|
prev_info = nil
|
@@ -60,7 +69,7 @@ class RedisStat
|
|
60
69
|
prev_info = info
|
61
70
|
@count += 1
|
62
71
|
break if @max_count && @count >= @max_count
|
63
|
-
sleep @
|
72
|
+
sleep @interval
|
64
73
|
end
|
65
74
|
@os.puts
|
66
75
|
rescue Interrupt
|
@@ -213,7 +222,7 @@ private
|
|
213
222
|
end
|
214
223
|
|
215
224
|
def process info, prev_info
|
216
|
-
|
225
|
+
@measures.map { |key|
|
217
226
|
[ key, process_how(info, prev_info, key) ]
|
218
227
|
}.select { |pair| pair.last }
|
219
228
|
end
|
data/lib/redis-stat/option.rb
CHANGED
@@ -17,6 +17,10 @@ module Option
|
|
17
17
|
opts.banner = "usage: redis-stat [HOST[:PORT] ...] [INTERVAL [COUNT]]"
|
18
18
|
opts.separator ''
|
19
19
|
|
20
|
+
opts.on('--auth=PASSWORD', 'Password') do |v|
|
21
|
+
options[:auth] = v
|
22
|
+
end
|
23
|
+
|
20
24
|
opts.on('--csv=OUTPUT_CSV_FILE_PATH', 'Save the result in CSV format') do |v|
|
21
25
|
options[:csv] = v
|
22
26
|
end
|
data/lib/redis-stat/version.rb
CHANGED
data/test/test_redis-stat.rb
CHANGED
@@ -96,7 +96,8 @@ class TestRedisStat < Test::Unit::TestCase
|
|
96
96
|
def test_start
|
97
97
|
csv = '/tmp/redis-stat.csv'
|
98
98
|
cnt = 50
|
99
|
-
rs = RedisStat.new :hosts => %w[localhost] * 5, :interval => 0.1, :count => cnt,
|
99
|
+
rs = RedisStat.new :hosts => %w[localhost] * 5, :interval => 0.1, :count => cnt,
|
100
|
+
:verbose => true, :csv => csv, :auth => 'pw'
|
100
101
|
rs.start $stdout
|
101
102
|
|
102
103
|
assert_equal cnt + 1, File.read(csv).lines.to_a.length
|
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.1
|
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-07-
|
12
|
+
date: 2012-07-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ansi
|