redis-stat 0.2.1 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -1
- data/lib/redis-stat.rb +30 -25
- data/lib/redis-stat/option.rb +32 -17
- data/lib/redis-stat/version.rb +1 -1
- data/redis-stat.gemspec +2 -2
- data/test/test_redis-stat.rb +18 -7
- metadata +6 -6
data/README.md
CHANGED
@@ -16,6 +16,7 @@ usage: redis-stat [HOST[:PORT] ...] [INTERVAL [COUNT]]
|
|
16
16
|
--auth=PASSWORD Password
|
17
17
|
--csv=OUTPUT_CSV_FILE_PATH Save the result in CSV format
|
18
18
|
-v, --verbose Show more info
|
19
|
+
--style=STYLE Output style: unicode|ascii
|
19
20
|
--version Show version
|
20
21
|
--help Show this message
|
21
22
|
```
|
@@ -38,7 +39,7 @@ redis-stat localhost localhost:6380 1 10 --csv=/tmp/output.csv --verbose
|
|
38
39
|
|
39
40
|
## Screenshot
|
40
41
|
|
41
|
-
![](https://github.com/junegunn/redis-stat/raw/master/screenshots/redis-stat-0.
|
42
|
+
![](https://github.com/junegunn/redis-stat/raw/master/screenshots/redis-stat-0.2.4.png)
|
42
43
|
|
43
44
|
|
44
45
|
## Contributing
|
data/lib/redis-stat.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require "redis-stat/version"
|
2
4
|
require "redis-stat/option"
|
3
5
|
require 'insensitive_hash'
|
@@ -12,19 +14,21 @@ class RedisStat
|
|
12
14
|
DEFAULT_TERM_HEIGHT = 25
|
13
15
|
|
14
16
|
def initialize options = {}
|
15
|
-
options
|
16
|
-
@hosts
|
17
|
-
@redises
|
17
|
+
options = RedisStat::Option::DEFAULT.merge options
|
18
|
+
@hosts = options[:hosts]
|
19
|
+
@redises = @hosts.map { |e|
|
18
20
|
host, port = e.split(':')
|
19
21
|
Redis.new(Hash[ {:host => host, :port => port}.select { |k, v| v } ])
|
20
22
|
}
|
21
|
-
@interval
|
22
|
-
@max_count
|
23
|
-
@colors
|
24
|
-
@csv
|
25
|
-
@auth
|
26
|
-
@measures
|
27
|
-
@count
|
23
|
+
@interval = options[:interval]
|
24
|
+
@max_count = options[:count]
|
25
|
+
@colors = options[:colors] || COLORS
|
26
|
+
@csv = options[:csv]
|
27
|
+
@auth = options[:auth]
|
28
|
+
@measures = MEASURES[ options[:verbose] ? :verbose : :default ]
|
29
|
+
@count = 0
|
30
|
+
@style = options[:style]
|
31
|
+
@first_batch = true
|
28
32
|
end
|
29
33
|
|
30
34
|
def start output_stream
|
@@ -126,7 +130,7 @@ private
|
|
126
130
|
def output info, prev_info, file
|
127
131
|
info_output = process info, prev_info
|
128
132
|
|
129
|
-
init_table info_output
|
133
|
+
@table ||= init_table info_output
|
130
134
|
|
131
135
|
movement = nil
|
132
136
|
if @count == 0
|
@@ -139,9 +143,10 @@ private
|
|
139
143
|
})
|
140
144
|
end
|
141
145
|
elsif @count % @term_height == 0
|
146
|
+
@first_batch = false
|
142
147
|
movement = -1
|
143
148
|
update_term_size!
|
144
|
-
init_table info_output
|
149
|
+
@table = init_table info_output
|
145
150
|
end
|
146
151
|
|
147
152
|
# Build output table
|
@@ -149,6 +154,7 @@ private
|
|
149
154
|
ansi(*@colors[pair.first]) { [*pair.last].first }
|
150
155
|
}
|
151
156
|
lines = @table.to_s.lines.map(&:chomp)
|
157
|
+
lines.delete_at @first_batch ? 1 : 0
|
152
158
|
width = lines.first.length
|
153
159
|
height = lines.length
|
154
160
|
|
@@ -181,9 +187,7 @@ private
|
|
181
187
|
def output_static_info info
|
182
188
|
tab = Tabularize.new(
|
183
189
|
:unicode => false, :align => :right,
|
184
|
-
:
|
185
|
-
:vborder => ansi(:black, :bold) { '|' },
|
186
|
-
:iborder => ansi(:black, :bold) { '+' }
|
190
|
+
:border_style => @style
|
187
191
|
)
|
188
192
|
tab << [nil] + @hosts.map { |h| ansi(:bold, :green) { h } }
|
189
193
|
tab.separator!
|
@@ -204,21 +208,22 @@ private
|
|
204
208
|
end
|
205
209
|
|
206
210
|
def init_table info_output
|
207
|
-
|
208
|
-
:align
|
209
|
-
:
|
210
|
-
:
|
211
|
-
:vborder
|
212
|
-
:
|
213
|
-
:
|
214
|
-
:pad_right => 0,
|
211
|
+
table = Tabularize.new :unicode => false,
|
212
|
+
:align => :right,
|
213
|
+
:border_style => @style,
|
214
|
+
:border_color => ANSI::Code.red,
|
215
|
+
:vborder => ' ',
|
216
|
+
:pad_left => 0,
|
217
|
+
:pad_right => 0,
|
215
218
|
:screen_width => @term_width
|
216
|
-
|
219
|
+
table.separator!
|
220
|
+
table << info_output.map { |pair|
|
217
221
|
ansi(*((@colors[pair.first] || []) + [:underline])) {
|
218
222
|
LABELS[pair.first] || pair.first
|
219
223
|
}
|
220
224
|
}
|
221
|
-
|
225
|
+
table.separator!
|
226
|
+
table
|
222
227
|
end
|
223
228
|
|
224
229
|
def process info, prev_info
|
data/lib/redis-stat/option.rb
CHANGED
@@ -6,7 +6,8 @@ module Option
|
|
6
6
|
:hosts => ['127.0.0.1:6379'],
|
7
7
|
:interval => 2,
|
8
8
|
:count => nil,
|
9
|
-
:csv => nil
|
9
|
+
:csv => nil,
|
10
|
+
:style => :unicode
|
10
11
|
}
|
11
12
|
|
12
13
|
def self.parse argv
|
@@ -29,6 +30,10 @@ module Option
|
|
29
30
|
options[:verbose] = v
|
30
31
|
end
|
31
32
|
|
33
|
+
opts.on('--style=STYLE', 'Output style: unicode|ascii') do |v|
|
34
|
+
options[:style] = v.downcase.to_sym
|
35
|
+
end
|
36
|
+
|
32
37
|
opts.on('--version', 'Show version') do
|
33
38
|
puts RedisStat::VERSION
|
34
39
|
exit 0
|
@@ -65,30 +70,40 @@ module Option
|
|
65
70
|
end
|
66
71
|
|
67
72
|
def self.validate options
|
68
|
-
|
69
|
-
|
70
|
-
|
73
|
+
options[:interval].tap do |interval|
|
74
|
+
unless interval.is_a?(Numeric) && interval > 0
|
75
|
+
raise ArgumentError.new("Invalid interval: #{interval}")
|
76
|
+
end
|
71
77
|
end
|
72
78
|
|
73
|
-
|
74
|
-
|
75
|
-
|
79
|
+
options[:count].tap do |count|
|
80
|
+
unless count.nil? || (count.is_a?(Numeric) && count > 0)
|
81
|
+
raise ArgumentError.new("Invalid count: #{count}")
|
82
|
+
end
|
76
83
|
end
|
77
84
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
85
|
+
options[:hosts].tap do |hosts|
|
86
|
+
if hosts.empty?
|
87
|
+
raise ArgumentError.new("Redis host not given")
|
88
|
+
end
|
82
89
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
90
|
+
hosts.each do |host|
|
91
|
+
host, port = host.split(':')
|
92
|
+
if port
|
93
|
+
port = port.to_i
|
94
|
+
unless port > 0 && port < 65536
|
95
|
+
raise ArgumentError.new("Invalid port: #{port}")
|
96
|
+
end
|
89
97
|
end
|
90
98
|
end
|
91
99
|
end
|
100
|
+
|
101
|
+
options[:style].tap do |style|
|
102
|
+
unless [:unicode, :ascii].include?(style)
|
103
|
+
raise ArgumentError.new("Invalid style")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
92
107
|
end
|
93
108
|
end
|
94
109
|
end
|
data/lib/redis-stat/version.rb
CHANGED
data/redis-stat.gemspec
CHANGED
@@ -17,8 +17,8 @@ Gem::Specification.new do |gem|
|
|
17
17
|
|
18
18
|
gem.add_runtime_dependency "ansi", '~> 1.4.3'
|
19
19
|
gem.add_runtime_dependency "redis", '~> 3.0.1'
|
20
|
-
gem.add_runtime_dependency "tabularize", '~> 0.2.
|
21
|
-
gem.add_runtime_dependency "insensitive_hash", '~> 0.
|
20
|
+
gem.add_runtime_dependency "tabularize", '~> 0.2.8'
|
21
|
+
gem.add_runtime_dependency "insensitive_hash", '~> 0.3.0'
|
22
22
|
gem.add_runtime_dependency "parallelize", '~> 0.4.0'
|
23
23
|
|
24
24
|
gem.add_development_dependency 'test-unit'
|
data/test/test_redis-stat.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
1
3
|
require 'rubygems'
|
2
4
|
require 'test/unit'
|
3
5
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
@@ -46,7 +48,8 @@ class TestRedisStat < Test::Unit::TestCase
|
|
46
48
|
:hosts => ['localhost:1000'],
|
47
49
|
:interval => 20,
|
48
50
|
:count => nil,
|
49
|
-
:csv => nil
|
51
|
+
:csv => nil,
|
52
|
+
:style => :unicode
|
50
53
|
}.sort, options.sort)
|
51
54
|
|
52
55
|
options = RedisStat::Option.parse(%w[localhost:1000 20 30])
|
@@ -54,7 +57,8 @@ class TestRedisStat < Test::Unit::TestCase
|
|
54
57
|
:hosts => ['localhost:1000'],
|
55
58
|
:interval => 20,
|
56
59
|
:count => 30,
|
57
|
-
:csv => nil
|
60
|
+
:csv => nil,
|
61
|
+
:style => :unicode
|
58
62
|
}.sort, options.sort)
|
59
63
|
|
60
64
|
options = RedisStat::Option.parse(%w[20])
|
@@ -62,7 +66,8 @@ class TestRedisStat < Test::Unit::TestCase
|
|
62
66
|
:hosts => ['127.0.0.1:6379'],
|
63
67
|
:interval => 20,
|
64
68
|
:count => nil,
|
65
|
-
:csv => nil
|
69
|
+
:csv => nil,
|
70
|
+
:style => :unicode
|
66
71
|
}.sort, options.sort)
|
67
72
|
|
68
73
|
options = RedisStat::Option.parse(%w[20 30])
|
@@ -70,15 +75,17 @@ class TestRedisStat < Test::Unit::TestCase
|
|
70
75
|
:hosts => ['127.0.0.1:6379'],
|
71
76
|
:interval => 20,
|
72
77
|
:count => 30,
|
73
|
-
:csv => nil
|
78
|
+
:csv => nil,
|
79
|
+
:style => :unicode
|
74
80
|
}.sort, options.sort)
|
75
81
|
|
76
|
-
options = RedisStat::Option.parse(%w[localhost:8888 10 --csv=/tmp/a.csv])
|
82
|
+
options = RedisStat::Option.parse(%w[localhost:8888 10 --csv=/tmp/a.csv --style=ascii])
|
77
83
|
assert_equal({
|
78
84
|
:hosts => ['localhost:8888'],
|
79
85
|
:interval => 10,
|
80
86
|
:count => nil,
|
81
87
|
:csv => '/tmp/a.csv',
|
88
|
+
:style => :ascii
|
82
89
|
}.sort, options.sort)
|
83
90
|
end
|
84
91
|
|
@@ -91,12 +98,16 @@ class TestRedisStat < Test::Unit::TestCase
|
|
91
98
|
options = RedisStat::Option.parse(argv)
|
92
99
|
}
|
93
100
|
end
|
101
|
+
|
102
|
+
assert_raise(SystemExit) {
|
103
|
+
RedisStat::Option.parse(%w[--style=html])
|
104
|
+
}
|
94
105
|
end
|
95
106
|
|
96
107
|
def test_start
|
97
108
|
csv = '/tmp/redis-stat.csv'
|
98
|
-
cnt =
|
99
|
-
rs = RedisStat.new :hosts => %w[localhost] * 5, :interval => 0.
|
109
|
+
cnt = 100
|
110
|
+
rs = RedisStat.new :hosts => %w[localhost] * 5, :interval => 0.02, :count => cnt,
|
100
111
|
:verbose => true, :csv => csv, :auth => 'pw'
|
101
112
|
rs.start $stdout
|
102
113
|
|
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.4
|
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-
|
12
|
+
date: 2012-08-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ansi
|
@@ -50,7 +50,7 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: 0.2.
|
53
|
+
version: 0.2.8
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -58,7 +58,7 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.2.
|
61
|
+
version: 0.2.8
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: insensitive_hash
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
requirements:
|
67
67
|
- - ~>
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: 0.
|
69
|
+
version: 0.3.0
|
70
70
|
type: :runtime
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -74,7 +74,7 @@ dependencies:
|
|
74
74
|
requirements:
|
75
75
|
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version: 0.
|
77
|
+
version: 0.3.0
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
79
|
name: parallelize
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|