From 69aafcfeaf4c9d0662614f74b7dd53794f6e410e Mon Sep 17 00:00:00 2001 From: Michael Boutillier Date: Thu, 28 May 2020 00:12:59 +0200 Subject: [PATCH 1/7] fix hostname in output --- bin/metrics-mysql-graphite.rb | 2 +- bin/metrics-mysql-processes.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/metrics-mysql-graphite.rb b/bin/metrics-mysql-graphite.rb index 80d9ee1..c2374a6 100755 --- a/bin/metrics-mysql-graphite.rb +++ b/bin/metrics-mysql-graphite.rb @@ -211,7 +211,7 @@ def run # FIXME: break this up config[:host].split(' ').each do |mysql_host| # rubocop:disable Metrics/BlockLength - mysql_shorthostname = mysql_host.split('.')[0] + mysql_shorthostname = mysql_host.tr('.', '_') if config[:ini] ini = IniFile.load(config[:ini]) section = ini[config[:ini_section]] diff --git a/bin/metrics-mysql-processes.rb b/bin/metrics-mysql-processes.rb index 7439bbf..35356f8 100755 --- a/bin/metrics-mysql-processes.rb +++ b/bin/metrics-mysql-processes.rb @@ -119,7 +119,7 @@ def db_connection_creds def run config[:host].split(' ').each do |mysql_host| - mysql_shorthostname = mysql_host.split('.')[0] + mysql_shorthostname = mysql_host.tr('.', '_') db_user, db_pass = db_connection_creds begin mysql = Mysql.new(mysql_host, db_user, db_pass, nil, config[:port], config[:socket]) From 43faf7cb5f4ee1286632b7155433e96b53e29c75 Mon Sep 17 00:00:00 2001 From: Michael Boutillier Date: Thu, 28 May 2020 10:49:19 +0200 Subject: [PATCH 2/7] feat(percona) add percona metrics gathering --- CHANGELOG.md | 6 ++ bin/metrics-mysql-graphite.rb | 104 +++++++++++++++++++++++++++------- 2 files changed, 88 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bcf1b2..5682c7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ This project adheres to [Semantic Versioning](http://semver.org/). This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md) ## [Unreleased] +### Fixed +- Align output scheme for `metrics-mysql-graphite.rb` and `metrics-mysql-processes.rb` +- Make mysql_shorthostname compliant with graphite even if 127.0.0.1 is givent as hostname +- include MR #111: Collect more innodb variables #111: +- `metrics-mysql-graphite.rb`: collect more InnoDB variables. (@boutetnico) +- include metrics gathering from `https://github.com/sensu-plugins/sensu-plugins-percona` in `metrics-mysql-graphite.rb` (there is no reason to run the gathering twice and no reasons to keep two code base) ## [3.2.0] - 2020-08-26 ### Changed diff --git a/bin/metrics-mysql-graphite.rb b/bin/metrics-mysql-graphite.rb index c2374a6..7513f9f 100755 --- a/bin/metrics-mysql-graphite.rb +++ b/bin/metrics-mysql-graphite.rb @@ -177,32 +177,86 @@ def metrics_hash 'Handler_savepoint_rollback' => 'handlerSavepointRollback' }, 'innodb' => { - 'Innodb_buffer_pool_pages_total' => 'bufferTotal_pages', - 'Innodb_buffer_pool_pages_free' => 'bufferFree_pages', - 'Innodb_buffer_pool_pages_dirty' => 'bufferDirty_pages', - 'Innodb_buffer_pool_pages_data' => 'bufferUsed_pages', - 'Innodb_page_size' => 'pageSize', - 'Innodb_pages_created' => 'pagesCreated', - 'Innodb_pages_read' => 'pagesRead', - 'Innodb_pages_written' => 'pagesWritten', - 'Innodb_row_lock_current_waits' => 'currentLockWaits', - 'Innodb_row_lock_waits' => 'lockWaitTimes', - 'Innodb_row_lock_time' => 'rowLockTime', - 'Innodb_data_reads' => 'fileReads', - 'Innodb_data_writes' => 'fileWrites', - 'Innodb_data_fsyncs' => 'fileFsyncs', - 'Innodb_log_writes' => 'logWrites', - 'Innodb_rows_updated' => 'rowsUpdated', - 'Innodb_rows_read' => 'rowsRead', - 'Innodb_rows_deleted' => 'rowsDeleted', - 'Innodb_rows_inserted' => 'rowsInserted' + 'Innodb_buffer_pool_pages_total' => 'bufferTotal_pages', + 'Innodb_buffer_pool_pages_free' => 'bufferFree_pages', + 'Innodb_buffer_pool_pages_dirty' => 'bufferDirty_pages', + 'Innodb_buffer_pool_pages_data' => 'bufferUsed_pages', + 'Innodb_buffer_pool_pages_flushed' => 'bufferFlushed_pages', + 'Innodb_buffer_pool_pages_misc' => 'bufferMisc_pages', + 'Innodb_buffer_pool_bytes_data' => 'bufferUsed_bytes', + 'Innodb_buffer_pool_bytes_dirty' => 'bufferDirty_bytes', + 'Innodb_buffer_pool_read_ahead_rnd' => 'bufferReadAheadRnd', + 'Innodb_buffer_pool_read_ahead' => 'bufferReadAhead', + 'Innodb_buffer_pool_read_ahead_evicted' => 'bufferReadAheadEvicted', + 'Innodb_buffer_pool_read_requests' => 'bufferReadRequests', + 'Innodb_buffer_pool_reads' => 'bufferReads', + 'Innodb_buffer_pool_wait_free' => 'bufferWaitFree', + 'Innodb_buffer_pool_write_requests' => 'bufferWriteRequests', + 'innodb_buffer_pool_size' => 'poolSize', + 'Innodb_page_size' => 'pageSize', + 'Innodb_pages_created' => 'pagesCreated', + 'Innodb_pages_read' => 'pagesRead', + 'Innodb_pages_written' => 'pagesWritten', + 'Innodb_row_lock_current_waits' => 'currentLockWaits', + 'Innodb_row_lock_waits' => 'lockWaitTimes', + 'Innodb_row_lock_time' => 'rowLockTime', + 'Innodb_data_reads' => 'fileReads', + 'Innodb_data_writes' => 'fileWrites', + 'Innodb_data_fsyncs' => 'fileFsyncs', + 'Innodb_log_writes' => 'logWrites', + 'Innodb_rows_updated' => 'rowsUpdated', + 'Innodb_rows_read' => 'rowsRead', + 'Innodb_rows_deleted' => 'rowsDeleted', + 'Innodb_rows_inserted' => 'rowsInserted', }, 'configuration' => { - 'max_connections' => 'MaxConnections', - 'Max_prepared_stmt_count' => 'MaxPreparedStmtCount' + 'max_connections' => 'MaxConnections', + 'Max_prepared_stmt_count' => 'MaxPreparedStmtCount', + }, + 'cluster' => { + 'wsrep_last_committed' => 'last_committed', + 'wsrep_replicated' => 'replicated', + 'wsrep_replicated_bytes' => 'replicated_bytes', + 'wsrep_received' => 'received', + 'wsrep_received_bytes' => 'received_bytes', + 'wsrep_local_commits' => 'local_commits', + 'wsrep_local_cert_failures' => 'local_cert_failures', + 'wsrep_local_bf_aborts' => 'local_bf_aborts', + 'wsrep_local_replays' => 'local_replays', + 'wsrep_local_send_queue' => 'local_send_queue', + 'wsrep_local_send_queue_avg' => 'local_send_queue_avg', + 'wsrep_local_recv_queue' => 'local_recv_queue', + 'wsrep_local_recv_queue_avg' => 'local_recv_queue_avg', + 'wsrep_flow_control_paused' => 'flow_control_paused', + 'wsrep_flow_control_sent' => 'flow_control_sent', + 'wsrep_flow_control_recv' => 'flow_control_recv', + 'wsrep_cert_deps_distance' => 'cert_deps_distance', + 'wsrep_apply_oooe' => 'apply_oooe', + 'wsrep_apply_oool' => 'apply_oool', + 'wsrep_apply_window' => 'apply_window', + 'wsrep_commit_oooe' => 'commit_oooe', + 'wsrep_commit_oool' => 'commit_oool', + 'wsrep_commit_window' => 'commit_window', + 'wsrep_local_state' => 'local_state', + 'wsrep_cert_index_size' => 'cert_index_size', + 'wsrep_causal_reads' => 'causal_reads', + 'wsrep_cluster_conf_id' => 'cluster_conf_id', + 'wsrep_cluster_size' => 'cluster_size', + 'wsrep_local_index' => 'local_index', + 'wsrep_evs_repl_latency' => 'evs_repl_latency' } } end + + def fix_and_output_evs_repl_latency_data(row, mysql_shorthostname, category) + # see https://github.com/codership/galera/issues/67 for documentation on field mappings + data = row['Value'].split('/') + output "#{config[:scheme]}.#{mysql_shorthostname}.#{category}.wsrep_evs_repl_latency_min", data[0] + output "#{config[:scheme]}.#{mysql_shorthostname}.#{category}.wsrep_evs_repl_latency_avg", data[1] + output "#{config[:scheme]}.#{mysql_shorthostname}.#{category}.wsrep_evs_repl_latency_max", data[2] + output "#{config[:scheme]}.#{mysql_shorthostname}.#{category}.wsrep_evs_repl_latency_stddev", data[3] + output "#{config[:scheme]}.#{mysql_shorthostname}.#{category}.wsrep_evs_repl_latency_samplesize", data[4] + end def run # props to https://github.com/coredump/hoardd/blob/master/scripts-available/mysql.coffee @@ -230,9 +284,15 @@ def run end results.each_hash do |row| + # special handling for wsrep_evs_repl_latency as this contains forward slash delimited data + fix_and_output_evs_repl_latency_data(row) if row['Variable_name'] == 'wsrep_evs_repl_latency' metrics.each do |category, var_mapping| if var_mapping.key?(row['Variable_name']) - output "#{config[:scheme]}.#{mysql_shorthostname}.#{category}.#{var_mapping[row['Variable_name']]}", row['Value'] + if row['Variable_name'] == 'wsrep_evs_repl_latency' + fix_and_output_evs_repl_latency_data(row, mysql_shorthostname, category) + else + output "#{config[:scheme]}.#{mysql_shorthostname}.#{category}.#{var_mapping[row['Variable_name']]}", row['Value'] + end end end end From ea452fd2e5907637430ed0b3ba66b0126ce81280 Mon Sep 17 00:00:00 2001 From: Michael Boutillier Date: Sun, 6 Dec 2020 21:48:05 +0100 Subject: [PATCH 3/7] fixup! fix hostname in output --- CHANGELOG.md | 4 +++- bin/metrics-mysql-graphite.rb | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5682c7e..533c613 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,12 @@ This project adheres to [Semantic Versioning](http://semver.org/). This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md) ## [Unreleased] + ### Fixed + - Align output scheme for `metrics-mysql-graphite.rb` and `metrics-mysql-processes.rb` - Make mysql_shorthostname compliant with graphite even if 127.0.0.1 is givent as hostname -- include MR #111: Collect more innodb variables #111: +- include MR #111: Collect more innodb variables #111: - `metrics-mysql-graphite.rb`: collect more InnoDB variables. (@boutetnico) - include metrics gathering from `https://github.com/sensu-plugins/sensu-plugins-percona` in `metrics-mysql-graphite.rb` (there is no reason to run the gathering twice and no reasons to keep two code base) diff --git a/bin/metrics-mysql-graphite.rb b/bin/metrics-mysql-graphite.rb index 7513f9f..8459fdd 100755 --- a/bin/metrics-mysql-graphite.rb +++ b/bin/metrics-mysql-graphite.rb @@ -41,6 +41,7 @@ require 'mysql' require 'socket' require 'inifile' +require 'ipaddr' class MysqlGraphite < Sensu::Plugin::Metric::CLI::Graphite option :host, @@ -265,7 +266,13 @@ def run # FIXME: break this up config[:host].split(' ').each do |mysql_host| # rubocop:disable Metrics/BlockLength - mysql_shorthostname = mysql_host.tr('.', '_') + if IPAddress.valid? mysql_host + # in case we have an ip address, lets sanitize mysql_host to avoid side effect in graphite name scheme + mysql_shorthostname = mysql_host.tr('.', '_') + else + # in case we have a fqdn, lets continue to use the shortname + mysql_shorthostname = mysql_host.split('.')[0] + end if config[:ini] ini = IniFile.load(config[:ini]) section = ini[config[:ini_section]] From 089d805e151e99cc3dd9f3276f71f0b255d21f15 Mon Sep 17 00:00:00 2001 From: Michael Boutillier Date: Sun, 6 Dec 2020 22:10:44 +0100 Subject: [PATCH 4/7] fix: apply rubocop --- bin/metrics-mysql-graphite.rb | 84 +++++++++++++++++------------------ 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/bin/metrics-mysql-graphite.rb b/bin/metrics-mysql-graphite.rb index 8459fdd..4782731 100755 --- a/bin/metrics-mysql-graphite.rb +++ b/bin/metrics-mysql-graphite.rb @@ -178,41 +178,41 @@ def metrics_hash 'Handler_savepoint_rollback' => 'handlerSavepointRollback' }, 'innodb' => { - 'Innodb_buffer_pool_pages_total' => 'bufferTotal_pages', - 'Innodb_buffer_pool_pages_free' => 'bufferFree_pages', - 'Innodb_buffer_pool_pages_dirty' => 'bufferDirty_pages', - 'Innodb_buffer_pool_pages_data' => 'bufferUsed_pages', - 'Innodb_buffer_pool_pages_flushed' => 'bufferFlushed_pages', - 'Innodb_buffer_pool_pages_misc' => 'bufferMisc_pages', - 'Innodb_buffer_pool_bytes_data' => 'bufferUsed_bytes', - 'Innodb_buffer_pool_bytes_dirty' => 'bufferDirty_bytes', - 'Innodb_buffer_pool_read_ahead_rnd' => 'bufferReadAheadRnd', - 'Innodb_buffer_pool_read_ahead' => 'bufferReadAhead', + 'Innodb_buffer_pool_pages_total' => 'bufferTotal_pages', + 'Innodb_buffer_pool_pages_free' => 'bufferFree_pages', + 'Innodb_buffer_pool_pages_dirty' => 'bufferDirty_pages', + 'Innodb_buffer_pool_pages_data' => 'bufferUsed_pages', + 'Innodb_buffer_pool_pages_flushed' => 'bufferFlushed_pages', + 'Innodb_buffer_pool_pages_misc' => 'bufferMisc_pages', + 'Innodb_buffer_pool_bytes_data' => 'bufferUsed_bytes', + 'Innodb_buffer_pool_bytes_dirty' => 'bufferDirty_bytes', + 'Innodb_buffer_pool_read_ahead_rnd' => 'bufferReadAheadRnd', + 'Innodb_buffer_pool_read_ahead' => 'bufferReadAhead', 'Innodb_buffer_pool_read_ahead_evicted' => 'bufferReadAheadEvicted', - 'Innodb_buffer_pool_read_requests' => 'bufferReadRequests', - 'Innodb_buffer_pool_reads' => 'bufferReads', - 'Innodb_buffer_pool_wait_free' => 'bufferWaitFree', - 'Innodb_buffer_pool_write_requests' => 'bufferWriteRequests', - 'innodb_buffer_pool_size' => 'poolSize', - 'Innodb_page_size' => 'pageSize', - 'Innodb_pages_created' => 'pagesCreated', - 'Innodb_pages_read' => 'pagesRead', - 'Innodb_pages_written' => 'pagesWritten', - 'Innodb_row_lock_current_waits' => 'currentLockWaits', - 'Innodb_row_lock_waits' => 'lockWaitTimes', - 'Innodb_row_lock_time' => 'rowLockTime', - 'Innodb_data_reads' => 'fileReads', - 'Innodb_data_writes' => 'fileWrites', - 'Innodb_data_fsyncs' => 'fileFsyncs', - 'Innodb_log_writes' => 'logWrites', - 'Innodb_rows_updated' => 'rowsUpdated', - 'Innodb_rows_read' => 'rowsRead', - 'Innodb_rows_deleted' => 'rowsDeleted', - 'Innodb_rows_inserted' => 'rowsInserted', + 'Innodb_buffer_pool_read_requests' => 'bufferReadRequests', + 'Innodb_buffer_pool_reads' => 'bufferReads', + 'Innodb_buffer_pool_wait_free' => 'bufferWaitFree', + 'Innodb_buffer_pool_write_requests' => 'bufferWriteRequests', + 'innodb_buffer_pool_size' => 'poolSize', + 'Innodb_page_size' => 'pageSize', + 'Innodb_pages_created' => 'pagesCreated', + 'Innodb_pages_read' => 'pagesRead', + 'Innodb_pages_written' => 'pagesWritten', + 'Innodb_row_lock_current_waits' => 'currentLockWaits', + 'Innodb_row_lock_waits' => 'lockWaitTimes', + 'Innodb_row_lock_time' => 'rowLockTime', + 'Innodb_data_reads' => 'fileReads', + 'Innodb_data_writes' => 'fileWrites', + 'Innodb_data_fsyncs' => 'fileFsyncs', + 'Innodb_log_writes' => 'logWrites', + 'Innodb_rows_updated' => 'rowsUpdated', + 'Innodb_rows_read' => 'rowsRead', + 'Innodb_rows_deleted' => 'rowsDeleted', + 'Innodb_rows_inserted' => 'rowsInserted' }, 'configuration' => { - 'max_connections' => 'MaxConnections', - 'Max_prepared_stmt_count' => 'MaxPreparedStmtCount', + 'max_connections' => 'MaxConnections', + 'Max_prepared_stmt_count' => 'MaxPreparedStmtCount' }, 'cluster' => { 'wsrep_last_committed' => 'last_committed', @@ -248,7 +248,7 @@ def metrics_hash } } end - + def fix_and_output_evs_repl_latency_data(row, mysql_shorthostname, category) # see https://github.com/codership/galera/issues/67 for documentation on field mappings data = row['Value'].split('/') @@ -266,13 +266,13 @@ def run # FIXME: break this up config[:host].split(' ').each do |mysql_host| # rubocop:disable Metrics/BlockLength - if IPAddress.valid? mysql_host - # in case we have an ip address, lets sanitize mysql_host to avoid side effect in graphite name scheme - mysql_shorthostname = mysql_host.tr('.', '_') - else - # in case we have a fqdn, lets continue to use the shortname - mysql_shorthostname = mysql_host.split('.')[0] - end + mysql_shorthostname = if IPAddress.valid? mysql_host + # in case we have an ip address, lets sanitize mysql_host to avoid side effect in graphite name scheme + mysql_host.tr('.', '_') + else + # in case we have a fqdn, lets continue to use the shortname + mysql_host.split('.')[0] + end if config[:ini] ini = IniFile.load(config[:ini]) section = ini[config[:ini_section]] @@ -291,8 +291,8 @@ def run end results.each_hash do |row| - # special handling for wsrep_evs_repl_latency as this contains forward slash delimited data - fix_and_output_evs_repl_latency_data(row) if row['Variable_name'] == 'wsrep_evs_repl_latency' + # special handling for wsrep_evs_repl_latency as this contains forward slash delimited data + fix_and_output_evs_repl_latency_data(row) if row['Variable_name'] == 'wsrep_evs_repl_latency' metrics.each do |category, var_mapping| if var_mapping.key?(row['Variable_name']) if row['Variable_name'] == 'wsrep_evs_repl_latency' From 60b1f20a8a4650314c9770f2718f25fd44c51168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Stevens?= Date: Tue, 5 Jan 2021 11:23:46 +0100 Subject: [PATCH 5/7] fix(graphite): add ipaddress dependency --- bin/metrics-mysql-graphite.rb | 1 + sensu-plugins-mysql.gemspec | 1 + 2 files changed, 2 insertions(+) diff --git a/bin/metrics-mysql-graphite.rb b/bin/metrics-mysql-graphite.rb index 4782731..d19c391 100755 --- a/bin/metrics-mysql-graphite.rb +++ b/bin/metrics-mysql-graphite.rb @@ -42,6 +42,7 @@ require 'socket' require 'inifile' require 'ipaddr' +require 'ipaddress' class MysqlGraphite < Sensu::Plugin::Metric::CLI::Graphite option :host, diff --git a/sensu-plugins-mysql.gemspec b/sensu-plugins-mysql.gemspec index a34fea4..7d1a0ab 100644 --- a/sensu-plugins-mysql.gemspec +++ b/sensu-plugins-mysql.gemspec @@ -38,6 +38,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'inifile', '3.0.0' s.add_runtime_dependency 'ruby-mysql', '~> 2.9' s.add_runtime_dependency 'sensu-plugin', '~> 4.0' + s.add_runtime_dependency 'ipaddress', '~> 0.8' s.add_development_dependency 'bundler', '~> 2.1' s.add_development_dependency 'codeclimate-test-reporter', '~> 1.0' From 6148f6c8b0b8f2e78b65bbc941ba1026ad2f2a49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Stevens?= Date: Tue, 5 Jan 2021 14:11:38 +0100 Subject: [PATCH 6/7] fix(graphite): remove bad call to output latency --- bin/metrics-mysql-graphite.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bin/metrics-mysql-graphite.rb b/bin/metrics-mysql-graphite.rb index d19c391..e642ac0 100755 --- a/bin/metrics-mysql-graphite.rb +++ b/bin/metrics-mysql-graphite.rb @@ -292,10 +292,9 @@ def run end results.each_hash do |row| - # special handling for wsrep_evs_repl_latency as this contains forward slash delimited data - fix_and_output_evs_repl_latency_data(row) if row['Variable_name'] == 'wsrep_evs_repl_latency' metrics.each do |category, var_mapping| if var_mapping.key?(row['Variable_name']) + # special handling for wsrep_evs_repl_latency as this contains forward slash delimited data if row['Variable_name'] == 'wsrep_evs_repl_latency' fix_and_output_evs_repl_latency_data(row, mysql_shorthostname, category) else From 0c7ee81aa25e428f49ce32bec22a148c5fb0dfc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Stevens?= Date: Wed, 6 Jan 2021 11:16:41 +0100 Subject: [PATCH 7/7] fix(spec): reorder dependencies --- sensu-plugins-mysql.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sensu-plugins-mysql.gemspec b/sensu-plugins-mysql.gemspec index 7d1a0ab..7478498 100644 --- a/sensu-plugins-mysql.gemspec +++ b/sensu-plugins-mysql.gemspec @@ -36,9 +36,9 @@ Gem::Specification.new do |s| s.version = SensuPluginsMySql::Version::VER_STRING s.add_runtime_dependency 'inifile', '3.0.0' + s.add_runtime_dependency 'ipaddress', '~> 0.8' s.add_runtime_dependency 'ruby-mysql', '~> 2.9' s.add_runtime_dependency 'sensu-plugin', '~> 4.0' - s.add_runtime_dependency 'ipaddress', '~> 0.8' s.add_development_dependency 'bundler', '~> 2.1' s.add_development_dependency 'codeclimate-test-reporter', '~> 1.0'