Class: MMTop::Host
- Inherits:
-
Object
- Object
- MMTop::Host
- Defined in:
- lib/mmtop/host.rb
Instance Attribute Summary collapse
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#display_name ⇒ Object
Returns the value of attribute display_name.
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #dead? ⇒ Boolean
- #hide_if_empty? ⇒ Boolean
- #hostinfo ⇒ Object
-
#initialize(hostname, user, password, options) ⇒ Host
constructor
A new instance of Host.
- #initialize_mysql2_cx(m2opts) ⇒ Object
- #mark_dead! ⇒ Object
- #processlist ⇒ Object
- #query(q) ⇒ Object
- #slave_status ⇒ Object
- #stats ⇒ Object
- #wedge_monitor? ⇒ Boolean
Constructor Details
#initialize(hostname, user, password, options) ⇒ Host
Returns a new instance of Host.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/mmtop/host.rb', line 5 def initialize(hostname, user, password, ) m2opts = {} m2opts[:host] = hostname m2opts[:username] = user m2opts[:password] = password m2opts[:socket] = ['socket'] if ['socket'] m2opts[:port] = ['port'] if ['port'] m2opts[:reconnect] = true @options = @name = hostname @display_name = @name @comment = ['comment'] @last_queries = nil @port = ['port'] || 3306 @hide_if_empty = ['hide_if_empty'] initialize_mysql2_cx(m2opts) end |
Instance Attribute Details
#comment ⇒ Object
Returns the value of attribute comment.
38 39 40 |
# File 'lib/mmtop/host.rb', line 38 def comment @comment end |
#display_name ⇒ Object
Returns the value of attribute display_name.
38 39 40 |
# File 'lib/mmtop/host.rb', line 38 def display_name @display_name end |
#ip ⇒ Object
Returns the value of attribute ip.
38 39 40 |
# File 'lib/mmtop/host.rb', line 38 def ip @ip end |
#name ⇒ Object
Returns the value of attribute name.
38 39 40 |
# File 'lib/mmtop/host.rb', line 38 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
38 39 40 |
# File 'lib/mmtop/host.rb', line 38 def @options end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
39 40 41 |
# File 'lib/mmtop/host.rb', line 39 def port @port end |
Instance Method Details
#dead? ⇒ Boolean
72 73 74 |
# File 'lib/mmtop/host.rb', line 72 def dead? @dead end |
#hide_if_empty? ⇒ Boolean
41 42 43 |
# File 'lib/mmtop/host.rb', line 41 def hide_if_empty? !!@hide_if_empty end |
#hostinfo ⇒ Object
107 108 109 |
# File 'lib/mmtop/host.rb', line 107 def hostinfo HostInfo.new(self, processlist, slave_status, stats) end |
#initialize_mysql2_cx(m2opts) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mmtop/host.rb', line 24 def initialize_mysql2_cx(m2opts) begin @mysql = Mysql2::Client.new(m2opts) rescue Mysql2::Error => e if e.error_number == 2003 mark_dead! else $stdout.puts("Got Error Number #{e.error_number} (#{e.inspect}) trying to connect to #{@name}") mark_dead! sleep(1) end end end |
#mark_dead! ⇒ Object
68 69 70 |
# File 'lib/mmtop/host.rb', line 68 def mark_dead! @dead = true end |
#processlist ⇒ Object
101 102 103 104 105 |
# File 'lib/mmtop/host.rb', line 101 def processlist processlist = query("show full processlist") processlist.map { |r| Process.new(r, self) } end |
#query(q) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/mmtop/host.rb', line 45 def query(q) return [] if dead? res = [] begin ret = @mysql.query(q) rescue Mysql2::Error => e if [2007, 2013, 2003].include?(e.error_number) mark_dead! return [] else puts "Got error number " + e.error_number.to_s + " querying #{@name}" raise e end end return nil unless ret ret.each(:symbolize_keys => true) do |r| res << r end res end |
#slave_status ⇒ Object
76 77 78 79 80 81 |
# File 'lib/mmtop/host.rb', line 76 def slave_status return nil if @options['expect_slave'] == false res = query("show slave status")[0] return nil if res && res[:Master_User] == 'test' res end |
#stats ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/mmtop/host.rb', line 87 def stats stats = {} row = query("show global status like 'Questions'") return {} if row.empty? queries = row.first[:Value].to_i @qps ||= MMTop::QPS.new @qps.add_sample(queries, Time.now) stats[:qps] = @qps.calc.to_i stats end |
#wedge_monitor? ⇒ Boolean
83 84 85 |
# File 'lib/mmtop/host.rb', line 83 def wedge_monitor? @options['wedge_monitor'] end |