Class: MMTop::Process
- Inherits:
-
Object
- Object
- MMTop::Process
- Defined in:
- lib/mmtop/process.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#db ⇒ Object
(also: #database)
Returns the value of attribute db.
-
#host ⇒ Object
Returns the value of attribute host.
-
#query ⇒ Object
Returns the value of attribute query.
-
#status ⇒ Object
Returns the value of attribute status.
-
#time ⇒ Object
Returns the value of attribute time.
Instance Method Summary collapse
- #clean_sql! ⇒ Object
- #explain ⇒ Object
- #id ⇒ Object
-
#initialize(result, host) ⇒ Process
constructor
A new instance of Process.
- #kill! ⇒ Object
- #server ⇒ Object
- #sql ⇒ Object
- #src_port ⇒ Object
Constructor Details
#initialize(result, host) ⇒ Process
Returns a new instance of Process.
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/mmtop/process.rb', line 3 def initialize(result, host) @real_id = result[:Id] @query = result[:Info] @status = result[:State] @time = result[:Time] @client, @client_port = result[:Host] && result[:Host].split(":") @client ||= "(slave)" @client_port ||= "" @db = result[:db] @host = host clean_sql! end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
16 17 18 |
# File 'lib/mmtop/process.rb', line 16 def client @client end |
#db ⇒ Object Also known as: database
Returns the value of attribute db.
16 17 18 |
# File 'lib/mmtop/process.rb', line 16 def db @db end |
#host ⇒ Object
Returns the value of attribute host.
16 17 18 |
# File 'lib/mmtop/process.rb', line 16 def host @host end |
#query ⇒ Object
Returns the value of attribute query.
16 17 18 |
# File 'lib/mmtop/process.rb', line 16 def query @query end |
#status ⇒ Object
Returns the value of attribute status.
16 17 18 |
# File 'lib/mmtop/process.rb', line 16 def status @status end |
#time ⇒ Object
Returns the value of attribute time.
16 17 18 |
# File 'lib/mmtop/process.rb', line 16 def time @time end |
Instance Method Details
#clean_sql! ⇒ Object
31 32 33 34 35 |
# File 'lib/mmtop/process.rb', line 31 def clean_sql! if @query && !@query.valid_encoding? @query = @query.chars.select { |c| c.valid_encoding? }.join end end |
#explain ⇒ Object
49 50 51 52 |
# File 'lib/mmtop/process.rb', line 49 def explain @host.query("use #{db}") @host.query("explain #{sql}") end |
#id ⇒ Object
19 20 21 |
# File 'lib/mmtop/process.rb', line 19 def id @id ||= MMTop::PID.get(@host, @real_id) end |
#kill! ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/mmtop/process.rb', line 23 def kill! begin @host.query("KILL #{@real_id}") rescue Mysql2::Error => e puts e end end |
#server ⇒ Object
37 38 39 |
# File 'lib/mmtop/process.rb', line 37 def server @host.name end |
#sql ⇒ Object
45 46 47 |
# File 'lib/mmtop/process.rb', line 45 def sql @query end |
#src_port ⇒ Object
41 42 43 |
# File 'lib/mmtop/process.rb', line 41 def src_port @client_port end |