flare-tools 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/flare/tools.rb +1 -1
- data/lib/flare/tools/cli/partition_setting.rb +7 -14
- data/lib/flare/tools/cli/stats.rb +53 -51
- data/lib/flare/tools/core.rb +20 -5
- metadata +4 -4
data/lib/flare/tools.rb
CHANGED
@@ -11,29 +11,22 @@ module FlareTools
|
|
11
11
|
class PartitionSetting < Core
|
12
12
|
# {{{ constractor
|
13
13
|
def initialize()
|
14
|
-
super
|
15
14
|
@partition = 0
|
16
15
|
@run_flag = true
|
17
|
-
|
16
|
+
super
|
18
17
|
end
|
19
18
|
# }}}
|
20
|
-
# {{{
|
21
|
-
def
|
19
|
+
# {{{ option_on
|
20
|
+
def option_on
|
22
21
|
super
|
23
22
|
@option.on("-n", '--dry-run', "dry run") {@run_flag = false}
|
24
23
|
@option.on( '--partition=partition', "partition") {|v| @partition = v.to_i}
|
25
|
-
|
26
|
-
|
27
|
-
rescue OptionParser::ParseError => err
|
28
|
-
puts err.message
|
29
|
-
puts @option.to_s
|
30
|
-
exit 1
|
31
|
-
end
|
32
|
-
self.param_check
|
24
|
+
@option.on( '--index-server=[HOSTNAME]', "index server hostname(default:#{@index_server_hostname})") {|v| @index_server_hostname = v}
|
25
|
+
@option.on( '--index-server-port=[PORT]', "index server port(default:#{@index_server_port})") {|v| @index_server_port = v.to_i}
|
33
26
|
end
|
34
27
|
# }}}
|
35
|
-
# {{{
|
36
|
-
def
|
28
|
+
# {{{ option_param_check
|
29
|
+
def option_param_check
|
37
30
|
flag = false
|
38
31
|
if @partition == 0
|
39
32
|
self.error "specifies the number of partitions"
|
@@ -11,19 +11,63 @@ module FlareTools
|
|
11
11
|
class Stats < Core
|
12
12
|
# {{{ constractor
|
13
13
|
def initialize()
|
14
|
+
# {{{ @format
|
15
|
+
@format = "%20.20s:%5.5s" # hostname:port
|
16
|
+
@format += " %6s" # state
|
17
|
+
@format += " %6s" # role
|
18
|
+
@format += " %9s" # partition
|
19
|
+
@format += " %7s" # balance
|
20
|
+
@format += " %8.8s" # items
|
21
|
+
@format += " %4s" # connection
|
22
|
+
@format += " %6.6s" # behind
|
23
|
+
@format += " %3.3s" # hit
|
24
|
+
@format += " %4.4s" # size
|
25
|
+
@format += " %6.6s" # uptime
|
26
|
+
@format += " %7s" # version
|
27
|
+
@format += "\n"
|
28
|
+
# }}}
|
29
|
+
|
30
|
+
# {{{ @label
|
31
|
+
@label = @format % [
|
32
|
+
"hostname",
|
33
|
+
"port",
|
34
|
+
"state",
|
35
|
+
"role",
|
36
|
+
"partition",
|
37
|
+
"balance",
|
38
|
+
"items",
|
39
|
+
"conn",
|
40
|
+
"behind",
|
41
|
+
"hit",
|
42
|
+
"size",
|
43
|
+
"uptime",
|
44
|
+
"version",
|
45
|
+
]
|
46
|
+
# }}}
|
14
47
|
super
|
15
|
-
|
48
|
+
end
|
49
|
+
# }}}
|
50
|
+
# {{{ option_on
|
51
|
+
def option_on
|
52
|
+
super
|
53
|
+
@option.on( '--index-server=[HOSTNAME]', "index server hostname(default:#{@index_server_hostname})") {|v| @index_server_hostname = v}
|
54
|
+
@option.on( '--index-server-port=[PORT]', "index server port(default:#{@index_server_port})") {|v| @index_server_port = v.to_i}
|
16
55
|
end
|
17
56
|
# }}}
|
18
57
|
# {{{ sort_node
|
19
58
|
def sort_node(nodes)
|
20
|
-
|
59
|
+
# sort hostname
|
60
|
+
i = 0
|
61
|
+
nodes = nodes.sort_by{|key, val| [key, i += 1]}
|
62
|
+
|
21
63
|
# sort role
|
22
|
-
|
64
|
+
i = 0
|
65
|
+
nodes = nodes.sort_by{|key, val| [val['role'], i += 1]}
|
23
66
|
|
24
67
|
# sort partition
|
25
|
-
|
26
|
-
|
68
|
+
i = 0
|
69
|
+
nodes = nodes.sort_by{|key, val| [val['partition'], i += 1]}
|
70
|
+
nodes
|
27
71
|
end
|
28
72
|
# }}}
|
29
73
|
# {{{ str_date
|
@@ -55,53 +99,11 @@ class Stats < Core
|
|
55
99
|
"#{date}d"
|
56
100
|
end
|
57
101
|
# }}}
|
58
|
-
# {{{ opt_parse
|
59
|
-
def option_parse
|
60
|
-
super
|
61
|
-
begin
|
62
|
-
@option.parse!(ARGV)
|
63
|
-
rescue OptionParser::ParseError => err
|
64
|
-
puts err.message
|
65
|
-
puts @option.to_s
|
66
|
-
exit 1
|
67
|
-
end
|
68
|
-
end
|
69
|
-
# }}}
|
70
102
|
# {{{ execute
|
71
103
|
def execute
|
72
|
-
format = "%20.20s:%5.5s" # hostname:port
|
73
|
-
format += " %6s" # state
|
74
|
-
format += " %6s" # role
|
75
|
-
format += " %9s" # partition
|
76
|
-
format += " %7s" # balance
|
77
|
-
format += " %8.8s" # items
|
78
|
-
format += " %4s" # connection
|
79
|
-
format += " %6.6s" # behind
|
80
|
-
format += " %3.3s" # hit
|
81
|
-
format += " %4.4s" # size
|
82
|
-
format += " %6.6s" # uptime
|
83
|
-
format += " %7s" # version
|
84
|
-
format += "\n"
|
85
|
-
|
86
|
-
label = format % [
|
87
|
-
"hostname",
|
88
|
-
"port",
|
89
|
-
"state",
|
90
|
-
"role",
|
91
|
-
"partition",
|
92
|
-
"balance",
|
93
|
-
"items",
|
94
|
-
"conn",
|
95
|
-
"behind",
|
96
|
-
"hit",
|
97
|
-
"size",
|
98
|
-
"uptime",
|
99
|
-
"version",
|
100
|
-
]
|
101
104
|
str = ""
|
102
|
-
nodes = self.get_stats_nodes
|
105
|
+
nodes = self.get_stats_nodes.sort_node(nodes)
|
103
106
|
threads = self.get_stats_threads
|
104
|
-
nodes = self.sort_node(nodes)
|
105
107
|
nodes.each do |hostname_port,data|
|
106
108
|
ipaddr, port = hostname_port.split(":", 2)
|
107
109
|
if @dns.search(ipaddr).answer[0].methods.include?("ptr")
|
@@ -115,7 +117,7 @@ class Stats < Core
|
|
115
117
|
uptime = self.str_date(stats['uptime'])
|
116
118
|
hit_rate = stats['cmd_get'] == "0" ? "-" : (stats['get_hits'].to_f / stats['cmd_get'].to_f * 100.0).round
|
117
119
|
size = stats['bytes'] == "0" ? "-" : (stats['bytes'].to_i / 1024 / 1024 / 1024)
|
118
|
-
str += format % [
|
120
|
+
str += @format % [
|
119
121
|
hostname,
|
120
122
|
port,
|
121
123
|
data['state'],
|
@@ -128,10 +130,10 @@ class Stats < Core
|
|
128
130
|
hit_rate,
|
129
131
|
size,
|
130
132
|
uptime,
|
131
|
-
stats["version"]
|
133
|
+
stats["version"],
|
132
134
|
]
|
133
135
|
end
|
134
|
-
puts label + str
|
136
|
+
puts @label + str
|
135
137
|
end
|
136
138
|
# }}}
|
137
139
|
end
|
data/lib/flare/tools/core.rb
CHANGED
@@ -14,19 +14,34 @@ module FlareTools
|
|
14
14
|
@index_server_port = 12120
|
15
15
|
@run_flag = true
|
16
16
|
@timeout = 10
|
17
|
-
@option = OptionParser.new
|
18
17
|
@dns = Net::DNS::Resolver.new
|
18
|
+
@option = OptionParser.new
|
19
|
+
self.option_on
|
20
|
+
self.option_parse
|
21
|
+
self.option_param_check
|
19
22
|
end
|
20
23
|
# }}}
|
21
|
-
# {{{
|
22
|
-
def
|
24
|
+
# {{{ option_on
|
25
|
+
def option_on
|
23
26
|
@option.on('-h', '--help', "this message show") {puts @option.help; exit 1}
|
24
27
|
@option.on('-d', '--debug', "debug mode on") {$DEBUG = true}
|
25
28
|
@option.on("-w", '--warn', "turn warnings on for this script") {$-w = true}
|
26
|
-
@option.on( '--index-server=[HOSTNAME]', "index server hostname(default:#{@index_server_hostname})") {|v| @index_server_hostname = v}
|
27
|
-
@option.on( '--index-server-port=[PORT]', "index server port(default:#{@index_server_port})") {|v| @index_server_port = v.to_i}
|
28
29
|
end
|
29
30
|
# }}}
|
31
|
+
# {{{ option_parse
|
32
|
+
def option_parse
|
33
|
+
begin
|
34
|
+
@option.parse!(ARGV)
|
35
|
+
rescue OptionParser::ParseError => err
|
36
|
+
puts err.message
|
37
|
+
puts @option.to_s
|
38
|
+
exit 1
|
39
|
+
end
|
40
|
+
end
|
41
|
+
# }}}
|
42
|
+
# {{{ option_param_check
|
43
|
+
def option_param_check ; end
|
44
|
+
# }}}
|
30
45
|
# {{{ info
|
31
46
|
def info(msg)
|
32
47
|
puts "[INFO] #{msg}"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flare-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- kgws
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-25 00:00:00 +09:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|