right_support 2.0.3 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/right_support/stats/helpers.rb +65 -36
- data/right_support.gemspec +2 -2
- metadata +4 -4
@@ -33,9 +33,6 @@ module RightSupport
|
|
33
33
|
# Maximum characters in sub-stat value line
|
34
34
|
MAX_SUB_STAT_VALUE_WIDTH = 80
|
35
35
|
|
36
|
-
# Maximum characters displayed for exception message
|
37
|
-
MAX_EXCEPTION_MESSAGE_WIDTH = 60
|
38
|
-
|
39
36
|
# Separator between stat name and stat value
|
40
37
|
SEPARATOR = " : "
|
41
38
|
|
@@ -133,37 +130,67 @@ module RightSupport
|
|
133
130
|
end
|
134
131
|
end
|
135
132
|
|
136
|
-
# Wrap string by breaking it into lines at the specified
|
133
|
+
# Wrap string by breaking it into lines at the specified separators
|
134
|
+
# Allow for presence of color encoding when measuring string length
|
137
135
|
#
|
138
136
|
# === Parameters
|
139
137
|
# string(String):: String to be wrapped
|
140
|
-
# max_length(Integer):: Maximum length of a line
|
141
|
-
#
|
142
|
-
#
|
138
|
+
# max_length(Integer|Array):: Maximum length of a line, or array containing
|
139
|
+
# maximum length of first line followed by maximum for any subsequent line
|
140
|
+
# including indent
|
141
|
+
# indent(String):: Indentation for each line after first
|
142
|
+
# separators(Regexp):: Separators where string can wrap
|
143
143
|
#
|
144
144
|
# === Return
|
145
|
-
# (String):: Multi-line string
|
146
|
-
def self.wrap(string, max_length, indent,
|
145
|
+
# (String|Array):: Multi-line string
|
146
|
+
def self.wrap(string, max_length, indent, separators)
|
147
|
+
# Strip color encoding from string
|
148
|
+
strip = lambda { |string| string.gsub(/\e\[[0-9]*m/, "") }
|
149
|
+
|
150
|
+
# Split string at specified separators and return an array of arrays
|
151
|
+
# containing string segments and associated separator
|
152
|
+
split = lambda do |string, separators|
|
153
|
+
head, sep, tail = string.partition(separators)
|
154
|
+
if tail == ""
|
155
|
+
[[head, sep]]
|
156
|
+
else
|
157
|
+
[[head, sep]].concat(split.call(tail, separators))
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
147
161
|
all = []
|
148
|
-
line = ""
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
162
|
+
line = ["", last_sep = ""]
|
163
|
+
limit = max_length.is_a?(Array) ? max_length[0] : max_length
|
164
|
+
length = 0
|
165
|
+
separators = /#{separators}/ if separators.is_a?(String)
|
166
|
+
split.call(string, separators).each do |str, sep|
|
167
|
+
if (length + strip.call(str).size + last_sep.size + sep.size) > limit
|
168
|
+
all.push(line) unless line[0] == ""
|
169
|
+
line = [indent, last_sep = ""]
|
170
|
+
length = indent.size
|
171
|
+
limit = max_length.is_a?(Array) ? max_length[1] : max_length
|
153
172
|
end
|
154
|
-
line +=
|
173
|
+
line[0] += (str = last_sep + str)
|
174
|
+
line[1] = last_sep = sep
|
175
|
+
length += strip.call(str).size
|
155
176
|
end
|
156
|
-
all.push(line)
|
177
|
+
all.push(line)
|
178
|
+
all[0..-2].inject("") { |a, (str, sep)| a + str + sep + "\n" } + all[-1][0]
|
157
179
|
end
|
158
180
|
|
159
181
|
# Format UTC time value
|
160
182
|
#
|
161
183
|
# === Parameters
|
162
184
|
# time(Integer):: Time in seconds in Unix-epoch to be formatted
|
185
|
+
# with_year(Boolean):: Whether to include year, defaults to false
|
163
186
|
#
|
164
187
|
# (String):: Formatted time string
|
165
|
-
def self.time_at(time)
|
166
|
-
|
188
|
+
def self.time_at(time, with_year = false)
|
189
|
+
if with_year
|
190
|
+
Time.at(time).strftime("%a %b %d %H:%M:%S %Y")
|
191
|
+
else
|
192
|
+
Time.at(time).strftime("%a %b %d %H:%M:%S")
|
193
|
+
end
|
167
194
|
end
|
168
195
|
|
169
196
|
# Sort hash elements by key in ascending order into array of key/value pairs
|
@@ -192,9 +219,9 @@ module RightSupport
|
|
192
219
|
# Converts server statistics to a displayable format
|
193
220
|
#
|
194
221
|
# === Parameters
|
195
|
-
# stats(Hash):: Statistics with generic keys "name", "identity", "hostname", "service uptime",
|
222
|
+
# stats(Hash):: Statistics with generic keys "name", "identity", "hostname", "revision", "service uptime",
|
196
223
|
# "machine uptime", "memory KB", "stat time", "last reset time", "version", and "broker" with
|
197
|
-
# the latter two and "machine uptime", "memory KB", "version", and "broker" being optional;
|
224
|
+
# the latter two and "revision", "machine uptime", "memory KB", "version", and "broker" being optional;
|
198
225
|
# any other keys ending with "stats" have an associated hash value that is displayed in sorted
|
199
226
|
# key order, unless "stats" is preceded by a non-blank, in which case that character is prepended
|
200
227
|
# to the key to drive the sort order
|
@@ -202,7 +229,6 @@ module RightSupport
|
|
202
229
|
# :name_width(Integer):: Maximum characters in displayed stat name
|
203
230
|
# :sub_name_width(Integer):: Maximum characters in displayed sub-stat name
|
204
231
|
# :sub_stat_value_width(Integer):: Maximum characters in displayed sub-stat value line
|
205
|
-
# :exception_message_width(Integer):: Maximum characters displayed for exception message
|
206
232
|
#
|
207
233
|
# === Return
|
208
234
|
# (String):: Display string
|
@@ -211,9 +237,12 @@ module RightSupport
|
|
211
237
|
|
212
238
|
str = stats["name"] ? sprintf("%-#{name_width}s#{SEPARATOR}%s\n", "name", stats["name"]) : ""
|
213
239
|
str += sprintf("%-#{name_width}s#{SEPARATOR}%s\n", "identity", stats["identity"]) +
|
214
|
-
sprintf("%-#{name_width}s#{SEPARATOR}%s\n", "hostname", stats["hostname"])
|
215
|
-
|
216
|
-
|
240
|
+
sprintf("%-#{name_width}s#{SEPARATOR}%s\n", "hostname", stats["hostname"])
|
241
|
+
if stats.has_key?("revision")
|
242
|
+
str += sprintf("%-#{name_width}s#{SEPARATOR}%s\n", "revision", stats["revision"])
|
243
|
+
end
|
244
|
+
str += sprintf("%-#{name_width}s#{SEPARATOR}%s\n", "stat time", time_at(stats["stat time"], with_year = true)) +
|
245
|
+
sprintf("%-#{name_width}s#{SEPARATOR}%s\n", "last reset", time_at(stats["last reset time"], with_year = true)) +
|
217
246
|
sprintf("%-#{name_width}s#{SEPARATOR}%s\n", "service up", elapsed(stats["service uptime"]))
|
218
247
|
if stats.has_key?("machine uptime")
|
219
248
|
str += sprintf("%-#{name_width}s#{SEPARATOR}%s\n", "machine up", elapsed(stats["machine uptime"]))
|
@@ -256,7 +285,6 @@ module RightSupport
|
|
256
285
|
# :name_width(Integer):: Fixed width for left-justified name display
|
257
286
|
# :sub_name_width(Integer):: Maximum characters in displayed sub-stat name
|
258
287
|
# :sub_stat_value_width(Integer):: Maximum characters in displayed sub-stat value line
|
259
|
-
# :exception_message_width(Integer):: Maximum characters displayed for exception message
|
260
288
|
#
|
261
289
|
# === Return
|
262
290
|
# str(String):: Broker display with one line per broker plus exceptions
|
@@ -302,7 +330,8 @@ module RightSupport
|
|
302
330
|
str += if brokers["returns"].nil? || brokers["returns"].empty?
|
303
331
|
"none\n"
|
304
332
|
else
|
305
|
-
wrap(activity_str(brokers["returns"]), sub_stat_value_width,
|
333
|
+
wrap(activity_str(brokers["returns"]), [sub_stat_value_width, sub_stat_value_width + sub_value_indent.size],
|
334
|
+
sub_value_indent, /, /) + "\n"
|
306
335
|
end
|
307
336
|
end
|
308
337
|
|
@@ -325,7 +354,6 @@ module RightSupport
|
|
325
354
|
# :name_width(Integer):: Fixed width for left-justified name display
|
326
355
|
# :sub_name_width(Integer):: Maximum characters in displayed sub-stat name
|
327
356
|
# :sub_stat_value_width(Integer):: Maximum characters in displayed sub-stat value line
|
328
|
-
# :exception_message_width(Integer):: Maximum characters displayed for exception message
|
329
357
|
#
|
330
358
|
# === Return
|
331
359
|
# (String):: Single line display of stat
|
@@ -349,13 +377,15 @@ module RightSupport
|
|
349
377
|
if v.empty? || v["total"] == 0
|
350
378
|
"none"
|
351
379
|
elsif v["total"]
|
352
|
-
wrap(activity_str(v), sub_stat_value_width, sub_value_indent,
|
380
|
+
wrap(activity_str(v), [sub_stat_value_width, sub_stat_value_width + sub_value_indent.size],
|
381
|
+
sub_value_indent, ", ")
|
353
382
|
elsif k =~ /last$/
|
354
383
|
last_activity_str(v)
|
355
384
|
elsif k == "exceptions"
|
356
385
|
exceptions_str(v, sub_value_indent, options)
|
357
386
|
else
|
358
|
-
wrap(hash_str(v), sub_stat_value_width, sub_value_indent,
|
387
|
+
wrap(hash_str(v), [sub_stat_value_width, sub_stat_value_width + sub_value_indent.size],
|
388
|
+
sub_value_indent, /, /)
|
359
389
|
end
|
360
390
|
else
|
361
391
|
"#{v || "none"}"
|
@@ -427,20 +457,19 @@ module RightSupport
|
|
427
457
|
# "recent"(Array):: Most recent as a hash of "count", "type", "message", "when", and "where"
|
428
458
|
# indent(String):: Indentation for each line
|
429
459
|
# options(Hash):: Formatting options
|
430
|
-
# :
|
460
|
+
# :sub_stat_value_width(Integer):: Maximum characters in displayed sub-stat value line
|
431
461
|
#
|
432
462
|
# === Return
|
433
463
|
# (String):: Exceptions in displayable format with line separators
|
434
464
|
def self.exceptions_str(exceptions, indent, options = {})
|
435
|
-
|
465
|
+
sub_stat_value_width = options[:sub_stat_value_width] || MAX_SUB_STAT_VALUE_WIDTH
|
436
466
|
indent2 = indent + (" " * 4)
|
437
467
|
exceptions.to_a.sort.map do |k, v|
|
438
468
|
sprintf("%s total: %d, most recent:\n", k, v["total"]) + v["recent"].reverse.map do |e|
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
indent + "(#{e["count"]}) #{time_at(e["when"])} #{e["type"]}: #{message}\n" + indent2 + "#{e["where"]}"
|
469
|
+
where = " IN #{e["where"]}" if e["where"]
|
470
|
+
indent + wrap("(#{e["count"]}) #{time_at(e["when"])} #{e["type"]}: #{e["message"]}#{where}",
|
471
|
+
[sub_stat_value_width, sub_stat_value_width + indent2.size],
|
472
|
+
indent2, / |\/\/|\/|::|\.|-/)
|
444
473
|
end.join("\n")
|
445
474
|
end.join("\n" + indent)
|
446
475
|
end
|
data/right_support.gemspec
CHANGED
@@ -7,8 +7,8 @@ spec = Gem::Specification.new do |s|
|
|
7
7
|
s.required_ruby_version = Gem::Requirement.new(">= 1.8.7")
|
8
8
|
|
9
9
|
s.name = 'right_support'
|
10
|
-
s.version = '2.0.
|
11
|
-
s.date = '2012-
|
10
|
+
s.version = '2.0.4'
|
11
|
+
s.date = '2012-05-01'
|
12
12
|
|
13
13
|
s.authors = ['Tony Spataro', 'Sergey Sergyenko', 'Ryan Williamson', 'Lee Kirchhoff', 'Sergey Enin']
|
14
14
|
s.email = 'support@rightscale.com'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: right_support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 2.0.
|
9
|
+
- 4
|
10
|
+
version: 2.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tony Spataro
|
@@ -19,7 +19,7 @@ autorequire:
|
|
19
19
|
bindir: bin
|
20
20
|
cert_chain: []
|
21
21
|
|
22
|
-
date: 2012-
|
22
|
+
date: 2012-05-01 00:00:00 -07:00
|
23
23
|
default_executable:
|
24
24
|
dependencies: []
|
25
25
|
|