Class: SlashPort::Component::Mysql
- Inherits:
-
SlashPort::Component
- Object
- SlashPort::Component
- SlashPort::Component::Mysql
- Defined in:
- app/models/components/mysql.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#password ⇒ Object
Returns the value of attribute password.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
-
#ConfigGetVariables ⇒ Object
end MysqlStats.
-
#initialize ⇒ Mysql
constructor
A new instance of Mysql.
-
#MasterStatus ⇒ Object
end MysqlOK.
- #MysqlOK ⇒ Object
-
#MysqlStats ⇒ Object
end MasterStatus.
-
#SlaveStatus ⇒ Object
end MasterStatus.
Methods inherited from SlashPort::Component
#_want, attribute, attributes, #attributes, class_initialize, components, config, #configs, configs, disable, enable, #get_attributes, get_attributes, #get_configs, get_configs, #get_things, get_things, inherited, is_enabled?, label, #path
Constructor Details
#initialize ⇒ Mysql
Returns a new instance of Mysql.
26 27 28 29 30 31 32 33 34 |
# File 'app/models/components/mysql.rb', line 26 def initialize super begin @db = Sequel.connect("mysql://slashport@localhost") rescue Sequel::AdapterNotFound => e puts "Disabling #{self.class.label} component: missing mysql Sequel adapter: #{e.inspect}" self.class.disable end end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
6 7 8 |
# File 'app/models/components/mysql.rb', line 6 def host @host end |
#password ⇒ Object
Returns the value of attribute password.
8 9 10 |
# File 'app/models/components/mysql.rb', line 8 def password @password end |
#user ⇒ Object
Returns the value of attribute user.
7 8 9 |
# File 'app/models/components/mysql.rb', line 7 def user @user end |
Instance Method Details
#ConfigGetVariables ⇒ Object
end MysqlStats
97 98 99 100 101 102 103 104 |
# File 'app/models/components/mysql.rb', line 97 def ConfigGetVariables result = @db["show variables"] data = Hash.new result.map do |row| data[row[:Variable_name]] = row[:Value] end return data end |
#MasterStatus ⇒ Object
end MysqlOK
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/models/components/mysql.rb', line 48 def MasterStatus data = [] tuple = SlashPort::Tuple.new begin result = @db["show master status"].map[0] result.each do |key, val| tuple.data[key.to_s.downcase] = val end data << tuple rescue Sequel::DatabaseConnectionError, Sequel::DatabaseError return nil end return data end |
#MysqlOK ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/components/mysql.rb', line 36 def MysqlOK tuple = SlashPort::Tuple.new begin # dummy query just to test our connection @db["show variables like 'x'"].map tuple.data["healthy"] = 1 rescue Sequel::DatabaseConnectionError, Sequel::DatabaseError tuple.data["healthy"] = 0 end return tuple end |
#MysqlStats ⇒ Object
end MasterStatus
82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/models/components/mysql.rb', line 82 def MysqlStats tuple = SlashPort::Tuple.new begin result = @db["show global status"] result.map do |row| value = row[:Value] # use actual value if Float fails. tuple.data[row[:Variable_name].downcase] = (Float(value) rescue value) end rescue Sequel::DatabaseConnectionError, Sequel::DatabaseError return nil end return tuple end |
#SlaveStatus ⇒ Object
end MasterStatus
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/models/components/mysql.rb', line 63 def SlaveStatus tuple = SlashPort::Tuple.new begin result = @db["show slave status"].map[0] ret = Hash.new if result == nil # this host is not a slave tuple.data["is_slave"] = false else result.each do |key, val| tuple.data[key.to_s.downcase] = val end end rescue Sequel::DatabaseConnectionError, Sequel::DatabaseError return nil end return tuple end |