redis-stat 0.3.9-java → 0.4.0-java

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c43d00fe881d9e12b67dea24c74afc9e5ef42327
4
+ data.tar.gz: 52295d48c8affd024635cb8ea896f36899671979
5
+ SHA512:
6
+ metadata.gz: 59f72edc3ffae04250d154c13de131f9eeb291c3e0fec9244870a73804e560b931c825d13774698a55de5ac64984b24366d7882984b3f9ff7f79aad0a833b9e7
7
+ data.tar.gz: 07eae38c39d55883d43f55fd6d2e0096324e645879f26b0a1792515991817cd2d89a71249233663bc0feb27ad8618f5c9aabc66411d15928fd1d6ccbea8f19cb
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,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-stat
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.3.9
4
+ version: 0.4.0
6
5
  platform: java
7
6
  authors:
8
7
  - Junegunn Choi
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-08-28 00:00:00.000000000 Z
11
+ date: 2014-07-03 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: ansi256
@@ -18,13 +17,11 @@ dependencies:
18
17
  - - ~>
19
18
  - !ruby/object:Gem::Version
20
19
  version: 0.2.5
21
- none: false
22
20
  requirement: !ruby/object:Gem::Requirement
23
21
  requirements:
24
22
  - - ~>
25
23
  - !ruby/object:Gem::Version
26
24
  version: 0.2.5
27
- none: false
28
25
  prerelease: false
29
26
  type: :runtime
30
27
  - !ruby/object:Gem::Dependency
@@ -34,13 +31,11 @@ dependencies:
34
31
  - - ~>
35
32
  - !ruby/object:Gem::Version
36
33
  version: 3.0.2
37
- none: false
38
34
  requirement: !ruby/object:Gem::Requirement
39
35
  requirements:
40
36
  - - ~>
41
37
  - !ruby/object:Gem::Version
42
38
  version: 3.0.2
43
- none: false
44
39
  prerelease: false
45
40
  type: :runtime
46
41
  - !ruby/object:Gem::Dependency
@@ -50,13 +45,11 @@ dependencies:
50
45
  - - ~>
51
46
  - !ruby/object:Gem::Version
52
47
  version: 0.2.9
53
- none: false
54
48
  requirement: !ruby/object:Gem::Requirement
55
49
  requirements:
56
50
  - - ~>
57
51
  - !ruby/object:Gem::Version
58
52
  version: 0.2.9
59
- none: false
60
53
  prerelease: false
61
54
  type: :runtime
62
55
  - !ruby/object:Gem::Dependency
@@ -66,13 +59,11 @@ dependencies:
66
59
  - - ~>
67
60
  - !ruby/object:Gem::Version
68
61
  version: 0.3.0
69
- none: false
70
62
  requirement: !ruby/object:Gem::Requirement
71
63
  requirements:
72
64
  - - ~>
73
65
  - !ruby/object:Gem::Version
74
66
  version: 0.3.0
75
- none: false
76
67
  prerelease: false
77
68
  type: :runtime
78
69
  - !ruby/object:Gem::Dependency
@@ -82,13 +73,11 @@ dependencies:
82
73
  - - ~>
83
74
  - !ruby/object:Gem::Version
84
75
  version: 0.4.0
85
- none: false
86
76
  requirement: !ruby/object:Gem::Requirement
87
77
  requirements:
88
78
  - - ~>
89
79
  - !ruby/object:Gem::Version
90
80
  version: 0.4.0
91
- none: false
92
81
  prerelease: false
93
82
  type: :runtime
94
83
  - !ruby/object:Gem::Dependency
@@ -98,13 +87,11 @@ dependencies:
98
87
  - - ~>
99
88
  - !ruby/object:Gem::Version
100
89
  version: 0.1.4
101
- none: false
102
90
  requirement: !ruby/object:Gem::Requirement
103
91
  requirements:
104
92
  - - ~>
105
93
  - !ruby/object:Gem::Version
106
94
  version: 0.1.4
107
- none: false
108
95
  prerelease: false
109
96
  type: :runtime
110
97
  - !ruby/object:Gem::Dependency
@@ -114,13 +101,11 @@ dependencies:
114
101
  - - ~>
115
102
  - !ruby/object:Gem::Version
116
103
  version: 1.3.3
117
- none: false
118
104
  requirement: !ruby/object:Gem::Requirement
119
105
  requirements:
120
106
  - - ~>
121
107
  - !ruby/object:Gem::Version
122
108
  version: 1.3.3
123
- none: false
124
109
  prerelease: false
125
110
  type: :runtime
126
111
  - !ruby/object:Gem::Dependency
@@ -130,13 +115,11 @@ dependencies:
130
115
  - - ~>
131
116
  - !ruby/object:Gem::Version
132
117
  version: 1.7.5
133
- none: false
134
118
  requirement: !ruby/object:Gem::Requirement
135
119
  requirements:
136
120
  - - ~>
137
121
  - !ruby/object:Gem::Version
138
122
  version: 1.7.5
139
- none: false
140
123
  prerelease: false
141
124
  type: :runtime
142
125
  - !ruby/object:Gem::Dependency
@@ -146,47 +129,41 @@ dependencies:
146
129
  - - ~>
147
130
  - !ruby/object:Gem::Version
148
131
  version: 0.2.0
149
- none: false
150
132
  requirement: !ruby/object:Gem::Requirement
151
133
  requirements:
152
134
  - - ~>
153
135
  - !ruby/object:Gem::Version
154
136
  version: 0.2.0
155
- none: false
156
137
  prerelease: false
157
138
  type: :runtime
158
139
  - !ruby/object:Gem::Dependency
159
- name: puma
140
+ name: elasticsearch
160
141
  version_requirements: !ruby/object:Gem::Requirement
161
142
  requirements:
162
143
  - - ~>
163
144
  - !ruby/object:Gem::Version
164
- version: 2.3.2
165
- none: false
145
+ version: 1.0.0
166
146
  requirement: !ruby/object:Gem::Requirement
167
147
  requirements:
168
148
  - - ~>
169
149
  - !ruby/object:Gem::Version
170
- version: 2.3.2
171
- none: false
150
+ version: 1.0.0
172
151
  prerelease: false
173
152
  type: :runtime
174
153
  - !ruby/object:Gem::Dependency
175
- name: test-unit
154
+ name: puma
176
155
  version_requirements: !ruby/object:Gem::Requirement
177
156
  requirements:
178
- - - '>='
157
+ - - ~>
179
158
  - !ruby/object:Gem::Version
180
- version: '0'
181
- none: false
159
+ version: 2.3.2
182
160
  requirement: !ruby/object:Gem::Requirement
183
161
  requirements:
184
- - - '>='
162
+ - - ~>
185
163
  - !ruby/object:Gem::Version
186
- version: '0'
187
- none: false
164
+ version: 2.3.2
188
165
  prerelease: false
189
- type: :development
166
+ type: :runtime
190
167
  description: A real-time Redis monitoring tool written in Ruby
191
168
  email:
192
169
  - junegunn.c@gmail.com
@@ -203,6 +180,7 @@ files:
203
180
  - bin/redis-stat
204
181
  - lib/redis-stat.rb
205
182
  - lib/redis-stat/constants.rb
183
+ - lib/redis-stat/elasticsearch.rb
206
184
  - lib/redis-stat/option.rb
207
185
  - lib/redis-stat/server.rb
208
186
  - lib/redis-stat/server/public/bootstrap/css/bootstrap-responsive.min.css
@@ -229,6 +207,7 @@ files:
229
207
  homepage: https://github.com/junegunn/redis-stat
230
208
  licenses:
231
209
  - MIT
210
+ metadata: {}
232
211
  post_install_message:
233
212
  rdoc_options: []
234
213
  require_paths:
@@ -238,18 +217,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
238
217
  - - '>='
239
218
  - !ruby/object:Gem::Version
240
219
  version: '0'
241
- none: false
242
220
  required_rubygems_version: !ruby/object:Gem::Requirement
243
221
  requirements:
244
222
  - - '>='
245
223
  - !ruby/object:Gem::Version
246
224
  version: '0'
247
- none: false
248
225
  requirements: []
249
226
  rubyforge_project:
250
- rubygems_version: 1.8.24
227
+ rubygems_version: 2.2.2
251
228
  signing_key:
252
- specification_version: 3
229
+ specification_version: 4
253
230
  summary: A real-time Redis monitoring tool written in Ruby
254
231
  test_files:
255
232
  - test/bin_helper.rb