flare-tools 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -10,11 +10,11 @@ Management Tools for Flare
10
10
 
11
11
  * flare-stats
12
12
  $ flare-stats --index-server=flare1.example.com
13
- hostname state role partition balance behind uptime hit version
14
- flare1.example.com:12121 active master 0 1 0 12345 100 1.0.10
15
- flare2.example.com:12121 active slave 0 1 0 12345 100 1.0.10
16
- flare3.example.com:12121 active master 1 1 0 12345 100 1.0.10
17
- flare4.example.com:12121 active slave 1 1 0 12345 100 1.0.10
13
+ hostname: port state role partition balance items conn behind hit size uptime version
14
+ flare1.example.com:12121 active master 0 1 10000 111 0 100 10 12d 1.0.10
15
+ flare2.example.com:12121 active slave 0 1 10000 111 0 100 10 12d 1.0.10
16
+ flare3.example.com:12121 active master 1 1 10001 111 0 100 10 12d 1.0.10
17
+ flare4.example.com:12121 active slave 1 1 10001 111 0 100 10 12d 1.0.10
18
18
 
19
19
  * flare-partition-setting
20
20
  $ flare-partition-setting --partition=2
data/Rakefile CHANGED
@@ -12,10 +12,12 @@ $hoe = Hoe.spec 'flare-tools' do
12
12
  self.version = FlareTools::VERSION
13
13
  self.developer 'kgws', 'dev.kgws@gmail.com'
14
14
  self.post_install_message = 'PostInstall.txt'
15
- self.rubyforge_name = 'kgws'
16
15
  self.url = 'http://github.com/kgws/flare-tools'
17
16
  self.summary = "Management Tools for Flare"
18
17
  self.description = "Flare is a collection of tools for management."
18
+ self.extra_deps = [
19
+ ['net-dns','>= 0.6.1']
20
+ ]
19
21
  end
20
22
 
21
23
  require 'newgem/tasks'
data/lib/flare/tools.rb CHANGED
@@ -8,11 +8,13 @@
8
8
  $:.unshift(File.dirname(__FILE__)) unless
9
9
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
10
10
 
11
+ require 'rubygems'
11
12
  require 'optparse'
12
13
  require 'socket'
13
14
  require 'timeout'
15
+ require 'net/dns/resolver'
14
16
  require 'tools/core'
15
17
 
16
18
  module FlareTools
17
- VERSION = '0.0.1'
19
+ VERSION = '0.1.0'
18
20
  end
@@ -3,7 +3,7 @@
3
3
  # Copyright:: Copyright (c) 2010- kgws.
4
4
  # License:: This program is licenced under the same licence as kgws.
5
5
  #
6
- # $--- flare-stats-nodes - [ by Ruby ] $
6
+ # $--- flare-stats - [ by Ruby ] $
7
7
  # vim: foldmethod=marker tabstop=2 shiftwidth=2
8
8
  require 'flare/tools'
9
9
 
@@ -15,6 +15,46 @@ class Stats < Core
15
15
  self.option_parse
16
16
  end
17
17
  # }}}
18
+ # {{{ sort_node
19
+ def sort_node(nodes)
20
+ res = {}
21
+ # sort role
22
+ res = nodes.sort_by{|key, val| val['role']}
23
+
24
+ # sort partition
25
+ res = nodes.sort_by{|key, val| val['partition']}
26
+ res
27
+ end
28
+ # }}}
29
+ # {{{ str_date
30
+ def str_date(date)
31
+ date = date.to_i
32
+ res = ""
33
+ # sec
34
+ if date >= 60
35
+ date = date / 60
36
+ else
37
+ return "#{date}s"
38
+ end
39
+
40
+ # min
41
+ if date >= 60
42
+ date = date / 60
43
+ else
44
+ return date + "m"
45
+ end
46
+
47
+ # hour
48
+ if date >= 24
49
+ date = date / 24
50
+ else
51
+ return date + "h"
52
+ end
53
+
54
+ # day
55
+ "#{date}d"
56
+ end
57
+ # }}}
18
58
  # {{{ opt_parse
19
59
  def option_parse
20
60
  super
@@ -29,16 +69,67 @@ class Stats < Core
29
69
  # }}}
30
70
  # {{{ execute
31
71
  def execute
32
- format = "%21s %6s %6s %9s %7s %6s %6s %3s %7s\n"
33
- label = format % ["hostname", "state", "role", "partition", "balance", "behind", "uptime", "hit", "version"]
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
+ ]
34
101
  str = ""
35
102
  nodes = self.get_stats_nodes
36
103
  threads = self.get_stats_threads
104
+ nodes = self.sort_node(nodes)
37
105
  nodes.each do |hostname_port,data|
38
- hostname, port = hostname_port.split(":", 2)
39
- stats = self.get_stats(hostname, data['port'])
40
- threads[hostname_port]['behind'] = "-" unless threads[hostname_port].key?('behind')
41
- str += format % [hostname, data['state'], data['role'], data['partition'], data['balance'], threads[hostname_port]['behind'], stats['uptime'], stats["get_hits"], stats["version"]]
106
+ ipaddr, port = hostname_port.split(":", 2)
107
+ if @dns.search(ipaddr).answer[0].methods.include?("ptr")
108
+ hostname = @dns.search(ipaddr).answer[0].ptr
109
+ else
110
+ hostname = ipaddr
111
+ end
112
+ stats = self.get_stats(ipaddr, data['port'])
113
+ partition = data['partition'] == "-1" ? "-" : data['partition']
114
+ behind = threads[hostname_port].key?('behind') ? threads[hostname_port]['behind'] : "-"
115
+ uptime = self.str_date(stats['uptime'])
116
+ hit_rate = stats['cmd_get'] == "0" ? "-" : (stats['get_hits'].to_f / stats['cmd_get'].to_f * 100.0).round
117
+ size = stats['bytes'] == "0" ? "-" : (stats['bytes'].to_i / 1024 / 1024 / 1024)
118
+ str += format % [
119
+ hostname,
120
+ port,
121
+ data['state'],
122
+ data['role'],
123
+ partition,
124
+ data['balance'],
125
+ stats['curr_items'],
126
+ stats['curr_connections'],
127
+ behind,
128
+ hit_rate,
129
+ size,
130
+ uptime,
131
+ stats["version"]
132
+ ]
42
133
  end
43
134
  puts label + str
44
135
  end
@@ -3,7 +3,7 @@
3
3
  # Copyright:: Copyright (c) 2010- kgws.
4
4
  # License:: This program is licenced under the same licence as kgws.
5
5
  #
6
- # $--- flare-stats-nodes - [ by Ruby ] $
6
+ # $--- flare-tools - [ by Ruby ] $
7
7
  # vim: foldmethod=marker tabstop=2 shiftwidth=2
8
8
 
9
9
  module FlareTools
@@ -15,6 +15,7 @@ module FlareTools
15
15
  @run_flag = true
16
16
  @timeout = 10
17
17
  @option = OptionParser.new
18
+ @dns = Net::DNS::Resolver.new
18
19
  end
19
20
  # }}}
20
21
  # {{{ option_parse
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: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 0
9
8
  - 1
10
- version: 0.0.1
9
+ - 0
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - kgws
@@ -15,13 +15,29 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-21 00:00:00 +09:00
18
+ date: 2010-11-24 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: rubyforge
22
+ name: net-dns
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 5
30
+ segments:
31
+ - 0
32
+ - 6
33
+ - 1
34
+ version: 0.6.1
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rubyforge
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
25
41
  none: false
26
42
  requirements:
27
43
  - - ">="
@@ -33,11 +49,11 @@ dependencies:
33
49
  - 4
34
50
  version: 2.0.4
35
51
  type: :development
36
- version_requirements: *id001
52
+ version_requirements: *id002
37
53
  - !ruby/object:Gem::Dependency
38
54
  name: hoe
39
55
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
56
+ requirement: &id003 !ruby/object:Gem::Requirement
41
57
  none: false
42
58
  requirements:
43
59
  - - ">="
@@ -49,7 +65,7 @@ dependencies:
49
65
  - 2
50
66
  version: 2.6.2
51
67
  type: :development
52
- version_requirements: *id002
68
+ version_requirements: *id003
53
69
  description: Flare is a collection of tools for management.
54
70
  email:
55
71
  - dev.kgws@gmail.com
@@ -106,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
122
  version: "0"
107
123
  requirements: []
108
124
 
109
- rubyforge_project: kgws
125
+ rubyforge_project: flare-tools
110
126
  rubygems_version: 1.3.7
111
127
  signing_key:
112
128
  specification_version: 3