redis-stat 0.3.9 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- M2RkODI2MDg1MDYyYTNlN2Y2NTY4N2FiZGQyMWNmODM0NTE2ZTBhYw==
5
- data.tar.gz: !binary |-
6
- NDVmNmQ1MjRiY2FiNTg0YjIxNjRiZjA5NTU5MDRjNTI5NDRhMjY0Mg==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- NDE5OWVhMDQ2NWNlODUxNGUwZGYwNGY0M2EzMTU3ZDQyYWRmMmRlNzNiNzkz
10
- ZDhlMTIwYWY0YTljMTgzYzcyM2JhMWVkOTljY2M4MTg2OTIwODdmYTMyNDky
11
- YWEyZmM3YWZmZjJhZTgwM2EwYmE1ZTRhZmMyZmU3MmY0MmI1MWM=
12
- data.tar.gz: !binary |-
13
- NmQ0YzBkOTcwMGE4NTU5YTNmNDE3MTczNTI2NzFlNDMyNWJkYzcxNWRhZWM5
14
- NzUyMTAxODA3NTg3M2I0NGY3NTMzOThhNjEyM2E1Yjc0MmMzZmFkYzdkYTU2
15
- OGM0YzBmYjYzZDQ0NmUwNmEwMDc0ODlhNWZhMmMyZjAwZjI1MDM=
2
+ SHA1:
3
+ metadata.gz: 88b48d390b0584414c03baf3f3201af816bf89e9
4
+ data.tar.gz: 8cba293490f939431fc0aa82a45f06ae3f7a140b
5
+ SHA512:
6
+ metadata.gz: fc1a3324b2f435c39edb17114fa96714ac3e1e24ba2e1f57a8f9d89ec6ad1c7bb54d209beb9e1f151d391d0ef94a5114850d79f19585f6d38606aba38429f04c
7
+ data.tar.gz: 3fdc739c0858e5830760e2b227a8562e73b611f745f0456de1c150c6a240e9bdc10372ce78eb9b7b278c77b9932db18e88967fe44a0e26e83680b7b67e976728
data/README.md CHANGED
@@ -26,6 +26,7 @@ usage: redis-stat [HOST[:PORT] ...] [INTERVAL [COUNT]]
26
26
  --style=STYLE Output style: unicode|ascii
27
27
  --no-color Suppress ANSI color codes
28
28
  --csv=OUTPUT_CSV_FILE_PATH Save the result in CSV format
29
+ --es=ELASTICSEARCH_URL Send results to Elasticsearch
29
30
 
30
31
  --server[=PORT] Launch redis-stat web server (default port: 63790)
31
32
  --daemon Daemonize redis-stat. Must be used with --server option.
@@ -102,3 +103,7 @@ the original [redis-stat](https://github.com/antirez/redis-tools/blob/master/red
102
103
  included in [redis-tools](https://github.com/antirez/redis-tools) written by the creator of Redis himself. (My bad)
103
104
  Although the original C-version hasn't been updated for the past couple of years, you might want to check it out first.
104
105
 
106
+
107
+
108
+ [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/junegunn/redis-stat/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
109
+
data/lib/redis-stat.rb CHANGED
@@ -4,6 +4,7 @@ require 'redis-stat/version'
4
4
  require 'redis-stat/constants'
5
5
  require 'redis-stat/option'
6
6
  require 'redis-stat/server'
7
+ require 'redis-stat/elasticsearch'
7
8
  require 'insensitive_hash'
8
9
  require 'redis'
9
10
  require 'tabularize'
@@ -24,27 +25,28 @@ class RedisStat
24
25
  Ansi256.enabled = STDOUT.tty? && !(windows || options[:mono])
25
26
  options[:style] = :ascii if windows
26
27
 
27
- @hosts = options[:hosts]
28
- @redises = @hosts.map { |e|
29
- host, port = e.split(':')
28
+ @hosts = options[:hosts]
29
+ @redises = @hosts.map { |e|
30
+ host, port = e.split(':')
30
31
  Redis.new(Hash[ {:host => host, :port => port, :timeout => DEFAULT_REDIS_TIMEOUT}.select { |k, v| v } ])
31
32
  }
32
- @interval = options[:interval]
33
- @max_count = options[:count]
34
- @colors = options[:colors] || COLORS
35
- @csv = options[:csv]
36
- @auth = options[:auth]
37
- @verbose = options[:verbose]
38
- @measures = MEASURES[ @verbose ? :verbose : :default ].map { |m| [*m].first }
39
- @tab_measures= MEASURES[:static].map { |m| [*m].first }
40
- @all_measures= MEASURES.values.inject(:+).uniq - [:at]
41
- @count = 0
42
- @style = options[:style]
43
- @varwidth = STDOUT.tty? && !windows
44
- @first_batch = true
45
- @server_port = options[:server_port]
46
- @server_thr = nil
47
- @daemonized = options[:daemon]
33
+ @interval = options[:interval]
34
+ @max_count = options[:count]
35
+ @colors = options[:colors] || COLORS
36
+ @csv = options[:csv]
37
+ @auth = options[:auth]
38
+ @verbose = options[:verbose]
39
+ @measures = MEASURES[ @verbose ? :verbose : :default ].map { |m| [*m].first }
40
+ @tab_measures = MEASURES[:static].map { |m| [*m].first }
41
+ @all_measures = MEASURES.values.inject(:+).uniq - [:at]
42
+ @count = 0
43
+ @style = options[:style]
44
+ @varwidth = STDOUT.tty? && !windows
45
+ @first_batch = true
46
+ @server_port = options[:server_port]
47
+ @server_thr = nil
48
+ @daemonized = options[:daemon]
49
+ @elasticsearch = options[:es] && ElasticsearchSink.new(@hosts, options[:es])
48
50
  end
49
51
 
50
52
  def info
@@ -89,7 +91,7 @@ class RedisStat
89
91
  end
90
92
  end
91
93
  info_output = process info, prev_info
92
- output info, info_output, csv unless @daemonized
94
+ output info, info_output, csv
93
95
  server.push info, Hash[info_output] if server
94
96
  prev_info = info
95
97
 
@@ -105,6 +107,7 @@ class RedisStat
105
107
  @server_thr.join
106
108
  end
107
109
  rescue Exception => e
110
+ @os.puts
108
111
  @os.puts e.to_s.red.bold
109
112
  raise
110
113
  ensure
@@ -262,8 +265,15 @@ private
262
265
  end
263
266
 
264
267
  def output info, info_output, file
265
- output_term info_output
268
+ output_term info_output unless @daemonized
266
269
  output_file info_output, file if file
270
+ output_es info if @elasticsearch
271
+ end
272
+
273
+ def output_es info
274
+ @elasticsearch.output info
275
+ rescue Exception
276
+ raise unless @daemonized
267
277
  end
268
278
 
269
279
  def init_table info_output
@@ -0,0 +1,84 @@
1
+ require 'elasticsearch'
2
+ require 'date'
3
+ require 'uri'
4
+
5
+ class RedisStat
6
+ class ElasticsearchSink
7
+ attr_reader :hosts, :info, :index, :client
8
+
9
+ TO_I = {
10
+ :process_id => true,
11
+ :uptime_in_seconds => true,
12
+ :uptime_in_days => true,
13
+ :connected_slaves => true,
14
+ :aof_enabled => true,
15
+ :rdb_bgsave_in_progress => true,
16
+ :rdb_last_save_time => true,
17
+ }
18
+
19
+ DEFAULT_INDEX = 'redis-stat'
20
+
21
+ def self.parse_url elasticsearch
22
+ unless elasticsearch.match(%r[^https?://])
23
+ elasticsearch = "http://#{elasticsearch}"
24
+ end
25
+
26
+ uri = URI.parse elasticsearch
27
+ path = uri.path
28
+ index = path == '' ? DEFAULT_INDEX : path.split('/').last
29
+ uri.path = ''
30
+
31
+ [uri.to_s, index]
32
+ end
33
+
34
+ def initialize hosts, elasticsearch
35
+ url, @index = elasticsearch
36
+ @hosts = hosts
37
+ @client = Elasticsearch::Client.new :url => url
38
+ end
39
+
40
+ def output info
41
+ results = convert_to_i info
42
+ results.map do |host, entries|
43
+ time = entries[:at]
44
+ entry = {
45
+ :index => index,
46
+ :type => "redis",
47
+ :body => entries.merge({
48
+ :@timestamp => Time.at(time).strftime("%FT%T%:z"),
49
+ :host => host
50
+ }),
51
+ }
52
+
53
+ client.index entry
54
+ end
55
+ end
56
+
57
+ private
58
+ def link_hosts_to_info info
59
+ {}.tap do |output|
60
+ hosts.each_with_index do |host, index|
61
+ output[host] = {}.tap do |host_output|
62
+ info.each do |name, entries|
63
+ value = name == :at ? entries : entries[index]
64
+ host_output[name] = value
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ def convert_to_i info
72
+ info = link_hosts_to_info info
73
+ info.each do |host, entries|
74
+ entries.each do |name, value|
75
+ convert = RedisStat::LABELS[name] || TO_I[name]
76
+ if convert
77
+ entries[name] = value.to_i
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+
@@ -38,6 +38,10 @@ module Option
38
38
  options[:csv] = v
39
39
  end
40
40
 
41
+ opts.on('--es=ELASTICSEARCH_URL', 'Send results to Elasticsearch') do |v|
42
+ options[:es] = RedisStat::ElasticsearchSink.parse_url v
43
+ end
44
+
41
45
  opts.separator ''
42
46
 
43
47
  opts.on('--server[=PORT]', "Launch redis-stat web server (default port: #{RedisStat::DEFAULT_SERVER_PORT})") do |v|
@@ -1,3 +1,3 @@
1
1
  class RedisStat
2
- VERSION = "0.3.9"
2
+ VERSION = "0.4.0"
3
3
  end
data/redis-stat.gemspec CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |gem|
26
26
  gem.add_runtime_dependency "sinatra", '~> 1.3.3'
27
27
  gem.add_runtime_dependency "json", '~> 1.7.5'
28
28
  gem.add_runtime_dependency "lps", '~> 0.2.0'
29
+ gem.add_runtime_dependency "elasticsearch", '~> 1.0.0'
29
30
 
30
31
  if RUBY_PLATFORM == 'java'
31
32
  gem.add_runtime_dependency "puma", '~> 2.3.2'
@@ -33,6 +34,4 @@ Gem::Specification.new do |gem|
33
34
  gem.add_runtime_dependency "thin", '~> 1.5.0'
34
35
  gem.add_runtime_dependency "daemons", '~> 1.1.9'
35
36
  end
36
-
37
- gem.add_development_dependency 'test-unit'
38
37
  end
data/test/bin_helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: utf-8
3
3
 
4
- # DISCLAIMER:
4
+ # DISCLAIMER:
5
5
  # Not a real test!
6
6
  # Just a helper script for running scripts with local source
7
7
 
@@ -1,14 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: utf-8
3
3
 
4
- require 'rubygems'
5
- require 'test-unit'
4
+ $VERBOSE = true
6
5
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ require 'rubygems'
7
7
  require 'redis-stat'
8
8
  require 'redis'
9
9
  require 'stringio'
10
+ require 'minitest/autorun'
10
11
 
11
- class TestRedisStat < Test::Unit::TestCase
12
+ class TestRedisStat < MiniTest::Unit::TestCase
12
13
  def test_humanize_number
13
14
  rs = RedisStat.new
14
15
  assert_equal '0', rs.send(:humanize_number, 0.00)
@@ -102,9 +103,20 @@ class TestRedisStat < Test::Unit::TestCase
102
103
  :style => :ascii
103
104
  }.sort, options.sort)
104
105
 
106
+ options = RedisStat::Option.parse(%w[-h localhost:8888 10 -a password --csv=/tmp/a.csv --style=ascii --es=localhost/index])
107
+ assert_equal({
108
+ :auth => 'password',
109
+ :hosts => ['localhost:8888'],
110
+ :interval => 10,
111
+ :count => nil,
112
+ :csv => '/tmp/a.csv',
113
+ :style => :ascii,
114
+ :es => %w[http://localhost index]
115
+ }.sort, options.sort)
116
+
105
117
  # Server
106
118
  if RUBY_PLATFORM == 'java'
107
- assert_raise(SystemExit) {
119
+ assert_raises(SystemExit) {
108
120
  RedisStat::Option.parse(%w[-h localhost:8888 10 -a password --csv=/tmp/a.csv --style=ascii --server=5555 --daemon])
109
121
  }
110
122
  else
@@ -130,16 +142,16 @@ class TestRedisStat < Test::Unit::TestCase
130
142
  %w[localhost 0],
131
143
  %w[localhost 5 0]
132
144
  ].each do |argv|
133
- assert_raise(SystemExit) {
145
+ assert_raises(SystemExit) {
134
146
  options = RedisStat::Option.parse(argv)
135
147
  }
136
148
  end
137
149
 
138
- assert_raise(SystemExit) {
150
+ assert_raises(SystemExit) {
139
151
  RedisStat::Option.parse(%w[--style=html])
140
152
  }
141
153
 
142
- assert_raise(SystemExit) {
154
+ assert_raises(SystemExit) {
143
155
  RedisStat::Option.parse(%w[--daemon])
144
156
  }
145
157
  end
@@ -183,8 +195,19 @@ class TestRedisStat < Test::Unit::TestCase
183
195
  else
184
196
  raise NotImplementedError.new # FIXME
185
197
  end
186
- rescue Redis::CannotConnectError, NotImplementedError
187
- pend "redises not ready"
198
+ rescue Redis::CannotConnectError, NotImplementedError
199
+ skip "redises not ready"
200
+ end
201
+
202
+ def test_elasticsearch_url
203
+ {
204
+ 'localhost/index' => %w[http://localhost index],
205
+ 'https://localhost/index' => %w[https://localhost index],
206
+ 'https://localhost' => %w[https://localhost services],
207
+ 'httpserver:9200/index' => %w[http://httpserver:9200 index],
208
+ }.each do |arg, ret|
209
+ assert_equal ret, RedisStat::ElasticsearchSink.parse_url(arg)
210
+ end
188
211
  end
189
212
  end
190
213
 
metadata CHANGED
@@ -1,183 +1,183 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-stat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.9
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Junegunn Choi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-28 00:00:00.000000000 Z
11
+ date: 2014-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ansi256
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.2.5
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.2.5
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: redis
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: 3.0.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 3.0.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: tabularize
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: 0.2.9
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.2.9
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: insensitive_hash
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: 0.3.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.3.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: parallelize
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: 0.4.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.4.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: si
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: 0.1.4
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 0.1.4
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: sinatra
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ~>
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
103
  version: 1.3.3
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ~>
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: 1.3.3
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: json
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ~>
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
117
  version: 1.7.5
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ~>
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: 1.7.5
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: lps
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ~>
129
+ - - "~>"
130
130
  - !ruby/object:Gem::Version
131
131
  version: 0.2.0
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ~>
136
+ - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: 0.2.0
139
139
  - !ruby/object:Gem::Dependency
140
- name: thin
140
+ name: elasticsearch
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ~>
143
+ - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: 1.5.0
145
+ version: 1.0.0
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ~>
150
+ - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: 1.5.0
152
+ version: 1.0.0
153
153
  - !ruby/object:Gem::Dependency
154
- name: daemons
154
+ name: thin
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - ~>
157
+ - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: 1.1.9
159
+ version: 1.5.0
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - ~>
164
+ - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: 1.1.9
166
+ version: 1.5.0
167
167
  - !ruby/object:Gem::Dependency
168
- name: test-unit
168
+ name: daemons
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - ! '>='
171
+ - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: '0'
174
- type: :development
173
+ version: 1.1.9
174
+ type: :runtime
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - ! '>='
178
+ - - "~>"
179
179
  - !ruby/object:Gem::Version
180
- version: '0'
180
+ version: 1.1.9
181
181
  description: A real-time Redis monitoring tool written in Ruby
182
182
  email:
183
183
  - junegunn.c@gmail.com
@@ -186,7 +186,7 @@ executables:
186
186
  extensions: []
187
187
  extra_rdoc_files: []
188
188
  files:
189
- - .gitignore
189
+ - ".gitignore"
190
190
  - Gemfile
191
191
  - LICENSE
192
192
  - README.md
@@ -194,6 +194,7 @@ files:
194
194
  - bin/redis-stat
195
195
  - lib/redis-stat.rb
196
196
  - lib/redis-stat/constants.rb
197
+ - lib/redis-stat/elasticsearch.rb
197
198
  - lib/redis-stat/option.rb
198
199
  - lib/redis-stat/server.rb
199
200
  - lib/redis-stat/server/public/bootstrap/css/bootstrap-responsive.min.css
@@ -227,17 +228,17 @@ require_paths:
227
228
  - lib
228
229
  required_ruby_version: !ruby/object:Gem::Requirement
229
230
  requirements:
230
- - - ! '>='
231
+ - - ">="
231
232
  - !ruby/object:Gem::Version
232
233
  version: '0'
233
234
  required_rubygems_version: !ruby/object:Gem::Requirement
234
235
  requirements:
235
- - - ! '>='
236
+ - - ">="
236
237
  - !ruby/object:Gem::Version
237
238
  version: '0'
238
239
  requirements: []
239
240
  rubyforge_project:
240
- rubygems_version: 2.0.7
241
+ rubygems_version: 2.2.2
241
242
  signing_key:
242
243
  specification_version: 4
243
244
  summary: A real-time Redis monitoring tool written in Ruby