Class: MMTop::Process

Inherits:
Object
  • Object
show all
Defined in:
lib/mmtop/process.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#clientObject

Returns the value of attribute client.



16
17
18
# File 'lib/mmtop/process.rb', line 16

def client
  @client
end

#dbObject Also known as: database

Returns the value of attribute db.



16
17
18
# File 'lib/mmtop/process.rb', line 16

def db
  @db
end

#hostObject

Returns the value of attribute host.



16
17
18
# File 'lib/mmtop/process.rb', line 16

def host
  @host
end

#queryObject

Returns the value of attribute query.



16
17
18
# File 'lib/mmtop/process.rb', line 16

def query
  @query
end

#statusObject

Returns the value of attribute status.



16
17
18
# File 'lib/mmtop/process.rb', line 16

def status
  @status
end

#timeObject

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

#explainObject



49
50
51
52
# File 'lib/mmtop/process.rb', line 49

def explain
  @host.query("use #{db}")
  @host.query("explain #{sql}")
end

#idObject



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

#serverObject



37
38
39
# File 'lib/mmtop/process.rb', line 37

def server
  @host.name
end

#sqlObject



45
46
47
# File 'lib/mmtop/process.rb', line 45

def sql
  @query
end

#src_portObject



41
42
43
# File 'lib/mmtop/process.rb', line 41

def src_port
  @client_port
end