Skip to content
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

Update metrics-mysql-graphite.rb #126

Open
wants to merge 1 commit 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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]
- metrics-mysql-graphite.rb change mysql gem to mysql2 to fix runs against MySQL8.

## [3.1.1] - 2019-03-04
### Fixed
Expand Down
16 changes: 11 additions & 5 deletions bin/metrics-mysql-graphite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#

require 'sensu-plugin/metric/cli'
require 'mysql'
require 'mysql2'
require 'socket'
require 'inifile'

Expand Down Expand Up @@ -220,14 +220,20 @@ def run
db_pass = config[:password]
end
begin
mysql = Mysql.new(mysql_host, db_user, db_pass, nil, config[:port], config[:socket])
mysql = Mysql2::Client.new(
host: mysql_host,
username: db_user,
password: db_pass,
port: config[:port],
socket: config[:socket]
)

results = mysql.query('SHOW GLOBAL STATUS')
rescue StandardError => e
puts e.message
end

results.each_hash do |row|
results.each 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']
Expand All @@ -239,7 +245,7 @@ def run
slave_results = mysql.query('SHOW SLAVE STATUS')
# should return a single element array containing one hash
# #YELLOW
slave_results.fetch_hash.each_pair do |key, value|
slave_results.first.each do |key, value|
if metrics['general'].include?(key)
# Replication lag being null is bad, very bad, so negativate it here
value = -1 if key == 'Seconds_Behind_Master' && value.nil?
Expand All @@ -254,7 +260,7 @@ def run
variables_results = mysql.query('SHOW GLOBAL VARIABLES')

category = 'configuration'
variables_results.each_hash do |row|
variables_results.each do |row|
metrics[category].each do |metric, desc|
if metric.casecmp(row['Variable_name']).zero?
output "#{config[:scheme]}.#{mysql_shorthostname}.#{category}.#{desc}", row['Value']
Expand Down
1 change: 1 addition & 0 deletions sensu-plugins-mysql.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Gem::Specification.new do |s| # rubocop:disable Metrics/BlockLength

s.add_runtime_dependency 'inifile', '3.0.0'
s.add_runtime_dependency 'ruby-mysql', '~> 2.9'
s.add_runtime_dependency 'mysql2', '0.5.3'
s.add_runtime_dependency 'sensu-plugin', '~> 1.2'

s.add_development_dependency 'bundler', '~> 1.7'
Expand Down