Skip to content

fix hostname in output #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins

## [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
- Bump sensu-plugin dependency from ~> 1.2 to ~> 4.0
Expand Down
71 changes: 69 additions & 2 deletions bin/metrics-mysql-graphite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
require 'mysql'
require 'socket'
require 'inifile'
require 'ipaddr'
require 'ipaddress'

class MysqlGraphite < Sensu::Plugin::Metric::CLI::Graphite
option :host,
Expand Down Expand Up @@ -181,6 +183,18 @@ def metrics_hash
'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',
Expand All @@ -200,18 +214,66 @@ def metrics_hash
'configuration' => {
'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

metrics = metrics_hash

# FIXME: break this up
config[:host].split(' ').each do |mysql_host| # rubocop:disable Metrics/BlockLength
mysql_shorthostname = mysql_host.split('.')[0]
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]]
Expand All @@ -232,7 +294,12 @@ def run
results.each_hash do |row|
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']
# 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
output "#{config[:scheme]}.#{mysql_shorthostname}.#{category}.#{var_mapping[row['Variable_name']]}", row['Value']
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion bin/metrics-mysql-processes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
1 change: 1 addition & 0 deletions sensu-plugins-mysql.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ 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'

Expand Down