mmtop 0.9.5 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  # I'd like to say that I no longer understand this code.
2
2
  # Also, I'd like to say that it's unlikely to work for you, the general public. patches welcome!
3
+ require 'socket'
3
4
 
4
5
  module MMTop
5
6
  class Topology
@@ -28,7 +29,7 @@ module MMTop
28
29
  array << host
29
30
  t.select { |k, v|
30
31
  # find hosts who are our slaves
31
- v[:master] == host[:hostname]
32
+ v[:master] == host[:ip]
32
33
  }.sort_by { |k, v|
33
34
  # add those without children of their own first
34
35
  v[:is_master].to_i
@@ -64,31 +65,34 @@ module MMTop
64
65
  stack.push(master)
65
66
  end
66
67
 
67
- if last_master
68
- host[:final_master] = last_master[:hostname]
69
- else
70
- host[:final_master] = host[:hostname]
71
- end
72
68
  host[:levels] = levels
73
69
  end
74
70
 
71
+ def resolve_to_ip(hostname)
72
+ return nil if hostname.nil?
73
+ return hostname if hostname =~ /\d+\.\d+\.\d+\.\d+\./
74
+
75
+ arr = Socket::gethostbyname(hostname)
76
+ arr && arr.last.unpack("CCCC").join(".")
77
+ end
78
+
75
79
  def find_master_slave
76
- topology = @config.hosts.inject({}) { |accum, h|
77
- rows = h.query("show global variables where Variable_name='hostname'")
78
- next accum if rows.empty?
80
+ @config.hosts.each { |host|
81
+ host.ip = resolve_to_ip(host.name)
82
+ }
79
83
 
80
- hostname = rows.first[:Value]
84
+ topology = @config.hosts.inject({}) { |accum, h|
85
+ next unless h.ip
81
86
 
82
- hostname = hostname.split('.')[0]
83
87
  status = h.slave_status
84
88
 
85
89
  if status && status[:Master_User] != 'test'
86
90
  master_host = status[:Master_Host]
87
91
  end
88
92
 
89
- master_host = short_name_for_host(master_host) if master_host
93
+ master_host = resolve_to_ip(master_host)
90
94
 
91
- accum[hostname] = {:master => master_host, :hostname => hostname}
95
+ accum[h.ip] = {:master => master_host, :hostname => h.name, :ip => h.ip}
92
96
  accum
93
97
  }
94
98
 
@@ -101,17 +105,6 @@ module MMTop
101
105
  }
102
106
  topology
103
107
  end
104
-
105
- def short_name_for_host(h)
106
- if h =~ /\d+.\d+.\d+.\d+/
107
- h = ip_to_short_hostname(h)
108
- end
109
- h.split('.')[0]
110
- end
111
-
112
- def ip_to_short_hostname(ip)
113
- `grep #{ip} /etc/hosts | awk '{print $2}'`.chomp
114
- end
115
108
  end
116
109
 
117
110
  Filter.add_filter("discover_topology") do |queries, hostinfo, config|
data/lib/mmtop/host.rb CHANGED
@@ -29,7 +29,7 @@ module MMTop
29
29
  # rescue connection errors or sumpin
30
30
  end
31
31
 
32
- attr_accessor :display_name, :name, :comment, :options
32
+ attr_accessor :display_name, :name, :comment, :options, :ip
33
33
 
34
34
  def query(q)
35
35
  return [] if dead?
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mmtop
3
3
  version: !ruby/object:Gem::Version
4
- hash: 49
4
+ hash: 55
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 5
10
- version: 0.9.5
9
+ - 6
10
+ version: 0.9.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ben Osheroff
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-02-03 00:00:00 +00:00
19
- default_executable:
18
+ date: 2012-02-03 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: mysql2
@@ -70,25 +69,24 @@ extensions: []
70
69
  extra_rdoc_files: []
71
70
 
72
71
  files:
73
- - lib/mmtop/pid.rb
74
- - lib/mmtop/mmconfig.rb
75
- - lib/mmtop/filters/basic.rb
76
- - lib/mmtop/filters/reverse_lookup.rb
77
- - lib/mmtop/filters/map_topology.rb
78
- - lib/mmtop/command.rb
72
+ - lib/mmtop.rb
79
73
  - lib/mmtop/string_colorize.rb
74
+ - lib/mmtop/commands/basic.rb
75
+ - lib/mmtop/commands/filters.rb
76
+ - lib/mmtop/commands/kill.rb
77
+ - lib/mmtop/filter.rb
78
+ - lib/mmtop/pid.rb
80
79
  - lib/mmtop/process.rb
81
80
  - lib/mmtop/host.rb
82
81
  - lib/mmtop/term_input.rb
83
82
  - lib/mmtop/qps.rb
83
+ - lib/mmtop/mmconfig.rb
84
84
  - lib/mmtop/term_printer.rb
85
- - lib/mmtop/commands/filters.rb
86
- - lib/mmtop/commands/kill.rb
87
- - lib/mmtop/commands/basic.rb
88
- - lib/mmtop/filter.rb
89
- - lib/mmtop.rb
85
+ - lib/mmtop/command.rb
86
+ - lib/mmtop/filters/basic.rb
87
+ - lib/mmtop/filters/map_topology.rb
88
+ - lib/mmtop/filters/reverse_lookup.rb
90
89
  - bin/mmtop
91
- has_rdoc: true
92
90
  homepage: http://github.com/osheroff/mmtop
93
91
  licenses: []
94
92
 
@@ -118,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
116
  requirements: []
119
117
 
120
118
  rubyforge_project:
121
- rubygems_version: 1.5.3
119
+ rubygems_version: 1.8.10
122
120
  signing_key:
123
121
  specification_version: 3
124
122
  summary: A mytop-ish variant that can watch many mysql servers