redis-stat 0.4.1-java → 0.4.2-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 +4 -4
- data/lib/redis-stat.rb +74 -29
- data/lib/redis-stat/elasticsearch.rb +6 -6
- data/lib/redis-stat/server.rb +5 -2
- data/lib/redis-stat/server/public/js/site.js +1 -1
- data/lib/redis-stat/server/views/index.erb +14 -8
- data/lib/redis-stat/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0c766e709203cbbc8fe84956b58024190103ae0
|
4
|
+
data.tar.gz: 38c293db9116acf3334ff68e8948a9a46fe5002c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f00650709f31aa0778396c7a5c9c56e89b66a9c327c8fdd6a5f9fb4fd324cd15c6edbf6186a0755a628dbf35bf17a7a728a9ce76bddad55656a9c8704b66435
|
7
|
+
data.tar.gz: 5b9a39596bfd0460ca30a410e298e14b5ce78b8122a64d2a8502e148282bf2d02ad3e1efab54e53229d1795563ed2ae7a74cb4647ea78e48eefdfe4d2c5d9f1a
|
data/lib/redis-stat.rb
CHANGED
@@ -52,6 +52,7 @@ class RedisStat
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def start output_stream
|
55
|
+
@started_at = Time.now
|
55
56
|
@os = output_stream
|
56
57
|
trap('INT') { Thread.main.raise Interrupt }
|
57
58
|
|
@@ -60,11 +61,28 @@ class RedisStat
|
|
60
61
|
update_term_size!
|
61
62
|
authenticate!
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
# Initial info collection
|
65
|
+
info, x = collect
|
66
|
+
unless x.empty?
|
67
|
+
output_term_errors! format_exceptions(x)
|
68
|
+
exit 1
|
69
|
+
end
|
70
|
+
|
71
|
+
# Check elasticsearch status
|
72
|
+
if @elasticsearch
|
73
|
+
begin
|
74
|
+
output_es info
|
75
|
+
rescue Exception => e
|
76
|
+
output_term_errors! format_exceptions({ :elasticsearch => e })
|
77
|
+
exit 1
|
78
|
+
end
|
79
|
+
end
|
67
80
|
|
81
|
+
# Start web servers
|
82
|
+
server = start_server(info) if @server_port
|
83
|
+
|
84
|
+
# Main loop
|
85
|
+
prev_info = nil
|
68
86
|
LPS.interval(@interval).loop do
|
69
87
|
info, exceptions =
|
70
88
|
begin
|
@@ -78,26 +96,23 @@ class RedisStat
|
|
78
96
|
next
|
79
97
|
end
|
80
98
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
msgs = exceptions.map { |h, x| "[#{now}@#{h}] #{x}" }
|
86
|
-
@os.puts if (errors += 1) == 1
|
87
|
-
@os.puts msgs.join($/).red.bold
|
88
|
-
server.alert msgs.first if server
|
89
|
-
sleep @interval
|
90
|
-
next
|
99
|
+
begin
|
100
|
+
output_es info if @elasticsearch && @count > 0
|
101
|
+
rescue Exception => e
|
102
|
+
exceptions[:elasticsearch] = e.to_s
|
91
103
|
end
|
92
|
-
|
104
|
+
error_messages = format_exceptions(exceptions)
|
93
105
|
info_output = process info, prev_info
|
94
|
-
|
95
|
-
|
96
|
-
|
106
|
+
unless @daemonized
|
107
|
+
output_static_info info if @count == 0
|
108
|
+
output_term info_output, error_messages
|
109
|
+
end
|
110
|
+
server.push @hosts, info, Hash[info_output], error_messages if server
|
111
|
+
output_file info_output, csv if csv
|
112
|
+
|
97
113
|
prev_info = info
|
98
114
|
|
99
115
|
@count += 1
|
100
|
-
errors = 0
|
101
116
|
break if @max_count && @count >= @max_count
|
102
117
|
end
|
103
118
|
@os.puts
|
@@ -108,6 +123,8 @@ class RedisStat
|
|
108
123
|
@server_thr.raise Interrupt
|
109
124
|
@server_thr.join
|
110
125
|
end
|
126
|
+
rescue SystemExit
|
127
|
+
raise
|
111
128
|
rescue Exception => e
|
112
129
|
@os.puts e.to_s.red.bold
|
113
130
|
raise
|
@@ -118,11 +135,16 @@ class RedisStat
|
|
118
135
|
end
|
119
136
|
|
120
137
|
private
|
121
|
-
def start_server
|
138
|
+
def start_server info
|
122
139
|
RedisStat::Server.set :port, @server_port
|
123
140
|
RedisStat::Server.set :redis_stat, self
|
124
|
-
RedisStat::Server.set :last_info,
|
125
|
-
@server_thr = Thread.new {
|
141
|
+
RedisStat::Server.set :last_info, info
|
142
|
+
@server_thr = Thread.new {
|
143
|
+
begin
|
144
|
+
RedisStat::Server.run!
|
145
|
+
rescue Interrupt
|
146
|
+
end
|
147
|
+
}
|
126
148
|
RedisStat::Server.wait_until_running
|
127
149
|
trap('INT') { Thread.main.raise Interrupt }
|
128
150
|
RedisStat::Server
|
@@ -135,7 +157,7 @@ private
|
|
135
157
|
}
|
136
158
|
class << info
|
137
159
|
def sumf label
|
138
|
-
self[:instances].values.map { |hash| hash[label].to_f }.inject(:+)
|
160
|
+
self[:instances].values.map { |hash| hash[label].to_f }.inject(:+) || 0
|
139
161
|
end
|
140
162
|
end
|
141
163
|
exceptions = {}
|
@@ -191,6 +213,15 @@ private
|
|
191
213
|
)
|
192
214
|
end
|
193
215
|
|
216
|
+
def format_exceptions exceptions
|
217
|
+
if exceptions.empty?
|
218
|
+
[]
|
219
|
+
else
|
220
|
+
now = Time.now.strftime('%Y/%m/%d %H:%M:%S')
|
221
|
+
exceptions.map { |h, x| "[#{now}@#{h}] #{x}" }
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
194
225
|
def output_file info_output, file
|
195
226
|
file.puts CSV.generate_line(info_output.map { |pair|
|
196
227
|
LABELS[pair.first] || pair.first
|
@@ -202,7 +233,26 @@ private
|
|
202
233
|
file.flush
|
203
234
|
end
|
204
235
|
|
205
|
-
def
|
236
|
+
def output_term_errors error_messages
|
237
|
+
@_term_error_reported ||= false
|
238
|
+
if error_messages.empty?
|
239
|
+
@_term_error_reported = false
|
240
|
+
else
|
241
|
+
unless @_term_error_reported
|
242
|
+
@os.puts
|
243
|
+
end
|
244
|
+
output_term_errors! error_messages
|
245
|
+
@_term_error_reported = true
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
def output_term_errors! error_messages
|
250
|
+
@os.puts error_messages.join($/).red.bold
|
251
|
+
end
|
252
|
+
|
253
|
+
def output_term info_output, error_messages
|
254
|
+
return if output_term_errors error_messages
|
255
|
+
|
206
256
|
@table ||= init_table info_output
|
207
257
|
|
208
258
|
movement = nil
|
@@ -265,11 +315,6 @@ private
|
|
265
315
|
@os.puts tab
|
266
316
|
end
|
267
317
|
|
268
|
-
def output info_output, file
|
269
|
-
output_term info_output unless @daemonized
|
270
|
-
output_file info_output, file if file
|
271
|
-
end
|
272
|
-
|
273
318
|
def output_es info
|
274
319
|
@elasticsearch.output info
|
275
320
|
rescue Exception
|
@@ -38,14 +38,15 @@ class ElasticsearchSink
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def output info
|
41
|
-
convert_to_i(info).
|
42
|
-
time =
|
41
|
+
convert_to_i(info).each do |host, entries|
|
42
|
+
time = info[:at].to_i
|
43
43
|
entry = {
|
44
44
|
:index => index,
|
45
45
|
:type => "redis",
|
46
46
|
:body => entries.merge({
|
47
47
|
:@timestamp => format_time(time),
|
48
|
-
:host => host
|
48
|
+
:host => host,
|
49
|
+
:at => time
|
49
50
|
}),
|
50
51
|
}
|
51
52
|
|
@@ -68,15 +69,14 @@ private
|
|
68
69
|
def convert_to_i info
|
69
70
|
Hash[info[:instances].map { |host, entries|
|
70
71
|
output = {}
|
71
|
-
output[:at] = info[:at].to_i
|
72
72
|
entries.each do |name, value|
|
73
73
|
convert = RedisStat::LABELS[name] || TO_I[name]
|
74
74
|
if convert
|
75
75
|
output[name] = value.to_i
|
76
76
|
end
|
77
77
|
end
|
78
|
-
[host, output]
|
79
|
-
}]
|
78
|
+
output.empty? ? nil : [host, output]
|
79
|
+
}.compact]
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
data/lib/redis-stat/server.rb
CHANGED
@@ -83,11 +83,14 @@ class Server < Sinatra::Base
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
def push hosts, info, data
|
86
|
+
def push hosts, info, data, error
|
87
87
|
static = Hash[settings.redis_stat.tab_measures.map { |stat|
|
88
88
|
[stat, hosts.map { |h| info[:instances][h][stat] }]
|
89
89
|
}]
|
90
|
-
data = {:at
|
90
|
+
data = {:at => (Time.now.to_f * 1000).to_i,
|
91
|
+
:static => static,
|
92
|
+
:dynamic => data,
|
93
|
+
:error => error}
|
91
94
|
|
92
95
|
settings.mutex.synchronize do
|
93
96
|
settings.last_error = nil
|
@@ -152,7 +152,7 @@ var updateTable = function() {
|
|
152
152
|
for (var stat in js) {
|
153
153
|
$("#" + stat).replaceWith(
|
154
154
|
"<tr id='" + stat + "'>" +
|
155
|
-
js[stat].map(function(e) { return "<td>" + (e == null ? "" : e) + "</td>" }).join() +
|
155
|
+
js[stat].map(function(e) { return "<td>" + (e == null ? "<span class='label label-warning'>N/A</span>" : e) + "</td>" }).join() +
|
156
156
|
"</tr>"
|
157
157
|
)
|
158
158
|
}
|
@@ -27,7 +27,6 @@
|
|
27
27
|
<div class="span12">
|
28
28
|
<h3>Dashboard</h3>
|
29
29
|
<div class="alert alert-error hide">
|
30
|
-
<h4></h4>
|
31
30
|
</div>
|
32
31
|
</div>
|
33
32
|
</div>
|
@@ -142,20 +141,27 @@
|
|
142
141
|
|
143
142
|
var source = new EventSource("/pull")
|
144
143
|
source.onmessage = function(e) {
|
144
|
+
var alert = $(".alert");
|
145
145
|
var json = JSON.parse(e.data);
|
146
|
-
if (json.error) {
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
146
|
+
if (json.error && json.error.length > 0) {
|
147
|
+
alert.html(
|
148
|
+
$.map(json.error, function(e, _) {
|
149
|
+
return "<h4>" + e + "</h4>";
|
150
|
+
}).join(''));
|
151
|
+
alert.fadeIn();
|
152
|
+
} else {
|
153
|
+
alert.fadeOut();
|
154
|
+
}
|
155
|
+
if (appendToHistory(json)) {
|
151
156
|
updateTable()
|
152
157
|
updatePlot()
|
153
158
|
}
|
154
159
|
}
|
155
160
|
<% unless RUBY_PLATFORM == 'java' %>
|
156
161
|
source.onerror = function(e) {
|
157
|
-
$(".alert
|
158
|
-
|
162
|
+
var alert = $(".alert");
|
163
|
+
alert.html("<h4>Lost connection to redis-stat</h4>");
|
164
|
+
alert.fadeIn();
|
159
165
|
// source.close()
|
160
166
|
}
|
161
167
|
<% end %>
|
data/lib/redis-stat/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-stat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Junegunn Choi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ansi256
|
@@ -224,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
224
224
|
version: '0'
|
225
225
|
requirements: []
|
226
226
|
rubyforge_project:
|
227
|
-
rubygems_version: 2.
|
227
|
+
rubygems_version: 2.2.2
|
228
228
|
signing_key:
|
229
229
|
specification_version: 4
|
230
230
|
summary: A real-time Redis monitoring tool written in Ruby
|