flare-tools 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -16,7 +16,6 @@ $hoe = Hoe.spec 'flare-tools' do
16
16
  self.summary = "Management Tools for Flare"
17
17
  self.description = "Flare is a collection of tools for management."
18
18
  self.extra_deps = [
19
- ['net-dns','>= 0.6.1']
20
19
  ]
21
20
  end
22
21
 
@@ -8,13 +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'
12
11
  require 'optparse'
13
12
  require 'socket'
14
13
  require 'timeout'
15
- require 'net/dns/resolver'
14
+ require 'resolv'
16
15
  require 'tools/core'
16
+ require 'tools/logger'
17
17
 
18
18
  module FlareTools
19
- VERSION = '0.1.2'
19
+ VERSION = '0.1.3'
20
20
  end
@@ -26,7 +26,6 @@ class Stats < Core
26
26
  @format += " %7s" # version
27
27
  @format += "\n"
28
28
  # }}}
29
-
30
29
  # {{{ @label
31
30
  @label = @format % [
32
31
  "hostname",
@@ -56,18 +55,8 @@ class Stats < Core
56
55
  # }}}
57
56
  # {{{ sort_node
58
57
  def sort_node(nodes)
59
- # sort hostname
60
- i = 0
61
- nodes = nodes.sort_by{|key, val| [key, i += 1]}
62
-
63
- # sort role
64
- i = 0
65
- nodes = nodes.sort_by{|key, val| [val['role'], i += 1]}
66
-
67
- # sort partition
68
- i = 0
69
- nodes = nodes.sort_by{|key, val| [val['partition'], i += 1]}
70
- nodes
58
+ # sort partition role hostname
59
+ nodes.sort_by{|key, val| [val['partition'], val['role'], key]}
71
60
  end
72
61
  # }}}
73
62
  # {{{ str_date
@@ -107,9 +96,9 @@ class Stats < Core
107
96
  threads = self.get_stats_threads
108
97
  nodes.each do |hostname_port,data|
109
98
  ipaddr, port = hostname_port.split(":", 2)
110
- if @dns.search(ipaddr).answer[0].methods.include?("ptr")
111
- hostname = @dns.search(ipaddr).answer[0].ptr
112
- else
99
+ begin
100
+ hostname = Resolv.getname(ipaddr).to_s
101
+ rescue Resolv::ResolvError
113
102
  hostname = ipaddr
114
103
  end
115
104
  stats = self.get_stats(ipaddr, data['port'])
@@ -14,7 +14,7 @@ module FlareTools
14
14
  @index_server_port = 12120
15
15
  @run_flag = true
16
16
  @timeout = 10
17
- @dns = Net::DNS::Resolver.new
17
+ @logger = Logger.new
18
18
  @option = OptionParser.new
19
19
  self.option_on
20
20
  self.option_parse
@@ -42,24 +42,38 @@ module FlareTools
42
42
  # {{{ option_param_check
43
43
  def option_param_check ; end
44
44
  # }}}
45
- # {{{ info
46
- def info(msg)
47
- puts "[INFO] #{msg}"
48
- end
49
- # }}}
50
- # {{{ error
51
- def error(msg)
52
- puts "\033[31m[ERROR]\033[m #{msg}"
53
- end
54
- # }}}
55
- # {{{ debug
56
- def debug(msg)
57
- puts "[DEBUG] #{msg}" if $DEBUG
45
+ # {{{ str_date
46
+ def str_date(date)
47
+ date = date.to_i
48
+ res = ""
49
+ # sec
50
+ if date >= 60
51
+ date = date / 60
52
+ else
53
+ return "#{date}s"
54
+ end
55
+
56
+ # min
57
+ if date >= 60
58
+ date = date / 60
59
+ else
60
+ return date + "m"
61
+ end
62
+
63
+ # hour
64
+ if date >= 24
65
+ date = date / 24
66
+ else
67
+ return date + "h"
68
+ end
69
+
70
+ # day
71
+ "#{date}d"
58
72
  end
59
73
  # }}}
60
74
  # {{{ command
61
75
  def command(host, port, cmd, flag=false, t=10)
62
- self.debug "Enter the command server. server=[#{host}:#{port}] command=[#{cmd.strip}]"
76
+ @logger.debug "Enter the command server. server=[#{host}:#{port}] command=[#{cmd.strip}]"
63
77
  return true if @run_flag === false && flag === false
64
78
  cmd += "\n" unless /\n$/ =~ cmd
65
79
  str = ""
@@ -80,10 +94,10 @@ module FlareTools
80
94
  end
81
95
  str
82
96
  rescue Errno::ECONNREFUSED
83
- self.error "Connection refused. server=[#{host}:#{port}] command=[#{cmd.strip}]"
97
+ @logger.error "Connection refused. server=[#{host}:#{port}] command=[#{cmd.strip}]"
84
98
  exit 1
85
99
  rescue TimeoutError
86
- self.error "Connection timeout. server=[#{host}:#{port}] command=[#{cmd.strip}]"
100
+ @logger.error "Connection timeout. server=[#{host}:#{port}] command=[#{cmd.strip}]"
87
101
  exit 1
88
102
  end
89
103
  # }}}
@@ -117,6 +131,16 @@ module FlareTools
117
131
  self.command(@index_server_hostname, @index_server_port, cmd, false, t)
118
132
  end
119
133
  # }}}
134
+ # {{{ flush_all
135
+ def flush_all(hostname, port, t=10)
136
+ self.command(hostname, port, "flush_all", true, t)
137
+ end
138
+ # }}}
139
+ # {{{ dump
140
+ def dump(partition, partition_size, wait=0, t=10)
141
+ self.command(@index_server_hostname, @index_server_port, cmd, false, t)
142
+ end
143
+ # }}}
120
144
  # {{{ stats_parse
121
145
  def stats_parse(str)
122
146
  res = {}
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: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - kgws
@@ -15,29 +15,13 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-25 00:00:00 +09:00
18
+ date: 2010-12-14 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: net-dns
23
- prerelease: false
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
21
  - !ruby/object:Gem::Dependency
38
22
  name: rubyforge
39
23
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ requirement: &id001 !ruby/object:Gem::Requirement
41
25
  none: false
42
26
  requirements:
43
27
  - - ">="
@@ -49,11 +33,11 @@ dependencies:
49
33
  - 4
50
34
  version: 2.0.4
51
35
  type: :development
52
- version_requirements: *id002
36
+ version_requirements: *id001
53
37
  - !ruby/object:Gem::Dependency
54
38
  name: hoe
55
39
  prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ requirement: &id002 !ruby/object:Gem::Requirement
57
41
  none: false
58
42
  requirements:
59
43
  - - ">="
@@ -65,7 +49,7 @@ dependencies:
65
49
  - 2
66
50
  version: 2.6.2
67
51
  type: :development
68
- version_requirements: *id003
52
+ version_requirements: *id002
69
53
  description: Flare is a collection of tools for management.
70
54
  email:
71
55
  - dev.kgws@gmail.com