Class: Bipbip::Plugin::Mysql
- Inherits:
-
Bipbip::Plugin
- Object
- Bipbip::Plugin
- Bipbip::Plugin::Mysql
- Defined in:
- lib/bipbip/plugin/mysql.rb
Instance Attribute Summary
Attributes inherited from Bipbip::Plugin
#config, #frequency, #metric_group, #name, #tags
Instance Method Summary collapse
Methods inherited from Bipbip::Plugin
factory, factory_from_plugin, #initialize, #metrics_names, #run, #source_identifier
Methods included from InterruptibleSleep
#interrupt_sleep, #interruptible_sleep
Constructor Details
This class inherits a constructor from Bipbip::Plugin
Instance Method Details
#metrics_schema ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/bipbip/plugin/mysql.rb', line 5 def metrics_schema [ { name: 'Max_used_connections', type: 'gauge', unit: 'Connections' }, { name: 'Connections', type: 'counter', unit: 'Connections' }, { name: 'Threads_connected', type: 'gauge', unit: 'Threads' }, { name: 'Slave_running', type: 'gauge', unit: 'Boolean' }, { name: 'Seconds_Behind_Master', type: 'gauge', unit: 'Seconds' }, { name: 'Created_tmp_disk_tables', type: 'counter', unit: 'Tables' }, { name: 'Queries', type: 'counter', unit: 'Queries' }, { name: 'Slow_queries', type: 'counter', unit: 'Queries' }, { name: 'Table_locks_immediate', type: 'counter', unit: 'Locks' }, { name: 'Table_locks_waited', type: 'counter', unit: 'Locks' }, { name: 'Processlist', type: 'gauge', unit: 'Processes' }, { name: 'Processlist_Locked', type: 'gauge', unit: 'Processes' }, { name: 'Com_select', type: 'counter', unit: 'Commands' }, { name: 'Com_delete', type: 'counter', unit: 'Commands' }, { name: 'Com_insert', type: 'counter', unit: 'Commands' }, { name: 'Com_update', type: 'counter', unit: 'Commands' }, { name: 'Com_replace', type: 'counter', unit: 'Commands' } ] end |
#monitor ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/bipbip/plugin/mysql.rb', line 33 def monitor mysql = Mysql2::Client.new( host: config['hostname'], port: config['port'], username: config['username'], password: config['password'] ) stats = Hash.new(0) mysql.query('SHOW GLOBAL STATUS').each do |v| stats[v['Variable_name']] = v['Value'] end mysql.query('SHOW VARIABLES').each do |v| stats[v['Variable_name']] = v['Value'] end slave_status = mysql.query('SHOW SLAVE STATUS').first if slave_status stats['Seconds_Behind_Master'] = slave_status['Seconds_Behind_Master'] end processlist = mysql.query('SHOW PROCESSLIST') stats['Processlist'] = processlist.count processlist.each do |process| state = process['State'].to_s stats['Processlist_' + state.sub(' ', '_')] += 1 unless state.empty? end mysql.close data = {} if stats.key?('Slave_SQL_Running') && stats.key?('Slave_SQL_Running') stats['Slave_running'] = ('Yes' === stats['Slave_SQL_Running'] && 'Yes' === stats['Slave_SQL_Running']) ? 'Yes' : 'No' end metrics_schema.each do |metric| name = metric[:name] unit = metric[:unit] data[name] = if 'Boolean' == unit ('ON' === stats[name] || 'Yes' === stats[name] ? 1 : 0) else stats[name].to_i end end data end |