redis-stat 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -13,6 +13,7 @@ gem install redis-stat
13
13
  ```
14
14
  usage: redis-stat [HOST[:PORT] ...] [INTERVAL [COUNT]]
15
15
 
16
+ --auth=PASSWORD Password
16
17
  --csv=OUTPUT_CSV_FILE_PATH Save the result in CSV format
17
18
  -v, --verbose Show more info
18
19
  --version Show version
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
- @options = RedisStat::Option::DEFAULT.merge options
16
- @hosts = @options[: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
- @max_count = @options[:count]
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
- # Warm-up
36
- @redises.each { |r| r.info }
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 @options[:interval]
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
- MEASURES[@options[:verbose] ? :verbose : :default].map { |key|
225
+ @measures.map { |key|
217
226
  [ key, process_how(info, prev_info, key) ]
218
227
  }.select { |pair| pair.last }
219
228
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  class RedisStat
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -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, :verbose => true, :csv => csv
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.0
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-25 00:00:00.000000000 Z
12
+ date: 2012-07-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ansi