kcluster 1.1.0 → 1.1.1
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.
- data/bin/kcluster +59 -49
- metadata +4 -4
data/bin/kcluster
CHANGED
@@ -22,40 +22,59 @@ def verbose(s)
|
|
22
22
|
puts s if $options[:verbose]
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
done = false
|
30
|
-
while !done && line = sock.gets.chomp
|
31
|
-
if (line == 'END') then
|
32
|
-
done = true
|
33
|
-
elsif line =~ /STAT queue_([\w\+\-]+) (\d+)/
|
34
|
-
key = $1
|
35
|
-
value = $2.to_i
|
36
|
-
(stat, queue_name) = case key
|
37
|
-
when /([\w\+\-]+)_total_items/ then [:total_items, $1]
|
38
|
-
when /([\w\+\-]+)_expired_items/ then [:expired_items, $1]
|
39
|
-
when /([\w\+\-]+)_mem_items/ then [:mem_items, $1]
|
40
|
-
when /([\w\+\-]+)_items/ then [:items, $1]
|
41
|
-
when /([\w\+\-]+)_mem_bytes/ then [:mem_bytes, $1]
|
42
|
-
when /([\w\+\-]+)_bytes/ then [:bytes, $1]
|
43
|
-
when /([\w\+\-]+)_age/ then [:age, $1]
|
44
|
-
end
|
25
|
+
def status(s)
|
26
|
+
print s
|
27
|
+
STDOUT.flush
|
28
|
+
end
|
45
29
|
|
46
|
-
|
47
|
-
|
30
|
+
def with_server(hostname, port, &block)
|
31
|
+
begin
|
32
|
+
sock = TCPSocket.open(hostname, port)
|
33
|
+
rescue
|
34
|
+
puts "WARNING: Unable to connect to #{hostname}:#{port}"
|
35
|
+
return
|
36
|
+
end
|
37
|
+
begin
|
38
|
+
yield sock
|
39
|
+
ensure
|
40
|
+
sock.close
|
41
|
+
end
|
42
|
+
end
|
48
43
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
44
|
+
def fetch_stats(hostname, port, data)
|
45
|
+
verbose "--- Fetching stats from #{hostname}:#{port}"
|
46
|
+
with_server(hostname, port) do |sock|
|
47
|
+
sock.puts("stats")
|
48
|
+
done = false
|
49
|
+
while !done && line = sock.gets.chomp
|
50
|
+
if (line == 'END') then
|
51
|
+
done = true
|
52
|
+
elsif line =~ /STAT queue_([\w\+\-]+) (\d+)/
|
53
|
+
key = $1
|
54
|
+
value = $2.to_i
|
55
|
+
(stat, queue_name) = case key
|
56
|
+
when /([\w\+\-]+)_total_items/ then [:total_items, $1]
|
57
|
+
when /([\w\+\-]+)_expired_items/ then [:expired_items, $1]
|
58
|
+
when /([\w\+\-]+)_mem_items/ then [:mem_items, $1]
|
59
|
+
when /([\w\+\-]+)_items/ then [:items, $1]
|
60
|
+
when /([\w\+\-]+)_mem_bytes/ then [:mem_bytes, $1]
|
61
|
+
when /([\w\+\-]+)_bytes/ then [:bytes, $1]
|
62
|
+
when /([\w\+\-]+)_age/ then [:age, $1]
|
63
|
+
end
|
64
|
+
|
65
|
+
if (queue_name)
|
66
|
+
queue_name = queue_name.split('+', 2).first if $options[:rollup_fanouts]
|
67
|
+
|
68
|
+
if (stat == :age)
|
69
|
+
data[:min_age][queue_name] = value if value < data[:min_age][queue_name]
|
70
|
+
data[:max_age][queue_name] = value if value > data[:max_age][queue_name]
|
71
|
+
else
|
72
|
+
data[stat][queue_name] += value
|
73
|
+
end
|
54
74
|
end
|
55
75
|
end
|
56
76
|
end
|
57
77
|
end
|
58
|
-
sock.close
|
59
78
|
end
|
60
79
|
|
61
80
|
def fetch_all
|
@@ -65,11 +84,7 @@ def fetch_all
|
|
65
84
|
end
|
66
85
|
end
|
67
86
|
$options[:server_list].each do |server|
|
68
|
-
|
69
|
-
fetch_stats(server, $options[:port], data)
|
70
|
-
rescue => e
|
71
|
-
puts "Could not connect to host #{server}: #{e}"
|
72
|
-
end
|
87
|
+
fetch_stats(server, $options[:port], data)
|
73
88
|
end
|
74
89
|
data
|
75
90
|
end
|
@@ -94,28 +109,23 @@ def report_all(data, keys)
|
|
94
109
|
puts ""
|
95
110
|
end
|
96
111
|
|
97
|
-
def
|
112
|
+
def broadcast(command, queue_name, verb)
|
98
113
|
$options[:server_list].each do |server|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
sock.close
|
114
|
+
status "--- #{verb} queue #{queue_name} from #{server}:#{$options[:port]} ... "
|
115
|
+
with_server(server, $options[:port]) do |sock|
|
116
|
+
sock.puts("#{command} " + queue_name)
|
117
|
+
puts sock.readline.chomp
|
118
|
+
end
|
105
119
|
end
|
106
120
|
puts "Done."
|
107
121
|
end
|
108
122
|
|
123
|
+
def delete_all(queue_name)
|
124
|
+
broadcast("delete", queue_name, "Deleting")
|
125
|
+
end
|
126
|
+
|
109
127
|
def flush_all(queue_name)
|
110
|
-
|
111
|
-
print "--- Flushing queue #{queue_name} from #{server}:#{$options[:port]} ... "
|
112
|
-
STDOUT.flush
|
113
|
-
sock = TCPSocket.open(server, $options[:port])
|
114
|
-
sock.puts("flush " + queue_name)
|
115
|
-
puts sock.readline.chomp
|
116
|
-
sock.close
|
117
|
-
end
|
118
|
-
puts "Done."
|
128
|
+
broadcast("flush", queue_name, "Flushing")
|
119
129
|
end
|
120
130
|
|
121
131
|
def keep_unchanged_data(last, current)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kcluster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 1
|
10
|
+
version: 1.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Robey Pointer
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-03-
|
18
|
+
date: 2012-03-16 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: json
|