sensu-plugins-mysql-nagyt 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +155 -0
- data/LICENSE +22 -0
- data/README.md +156 -0
- data/bin/check-mysql-alive.rb +102 -0
- data/bin/check-mysql-connections.rb +110 -0
- data/bin/check-mysql-disk.rb +140 -0
- data/bin/check-mysql-innodb-lock.rb +149 -0
- data/bin/check-mysql-msr-replication-status.rb +153 -0
- data/bin/check-mysql-query-result-count.rb +113 -0
- data/bin/check-mysql-replication-status.rb +175 -0
- data/bin/check-mysql-select-count.rb +115 -0
- data/bin/check-mysql-status.rb +209 -0
- data/bin/check-mysql-threads.rb +122 -0
- data/bin/metrics-mysql-graphite.rb +268 -0
- data/bin/metrics-mysql-multiple-select-count.rb +112 -0
- data/bin/metrics-mysql-processes.rb +142 -0
- data/bin/metrics-mysql-query-result-count.rb +100 -0
- data/bin/metrics-mysql-raw.rb +396 -0
- data/bin/metrics-mysql-select-count.rb +102 -0
- data/bin/metrics-mysql.rb +58 -0
- data/bin/mysql-metrics.sql +15 -0
- data/lib/sensu-plugins-mysql.rb +1 -0
- data/lib/sensu-plugins-mysql/version.rb +9 -0
- metadata +262 -0
@@ -0,0 +1,102 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# MySQL Select Count Metric
|
4
|
+
#
|
5
|
+
# Creates a graphite-formatted metric for the first value of a result set from a MySQL query.
|
6
|
+
#
|
7
|
+
# Copyright 2017 Andrew Thal <athal7@me.com>
|
8
|
+
# Copyright 2018 Tibor Nagy <nagyt@hu.inter.net>
|
9
|
+
#
|
10
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
11
|
+
# for details.
|
12
|
+
|
13
|
+
require 'sensu-plugin/metric/cli'
|
14
|
+
require 'mysql'
|
15
|
+
require 'inifile'
|
16
|
+
|
17
|
+
class MysqlQueryCountMetric < Sensu::Plugin::Metric::CLI::Graphite
|
18
|
+
option :host,
|
19
|
+
short: '-h HOST',
|
20
|
+
long: '--host HOST',
|
21
|
+
description: 'MySQL Host to connect to',
|
22
|
+
required: true
|
23
|
+
|
24
|
+
option :port,
|
25
|
+
short: '-P PORT',
|
26
|
+
long: '--port PORT',
|
27
|
+
description: 'MySQL Port to connect to',
|
28
|
+
proc: proc(&:to_i),
|
29
|
+
default: 3306
|
30
|
+
|
31
|
+
option :username,
|
32
|
+
short: '-u USERNAME',
|
33
|
+
long: '--user USERNAME',
|
34
|
+
description: 'MySQL Username'
|
35
|
+
|
36
|
+
option :password,
|
37
|
+
short: '-p PASSWORD',
|
38
|
+
long: '--pass PASSWORD',
|
39
|
+
description: 'MySQL password'
|
40
|
+
|
41
|
+
option :database,
|
42
|
+
short: '-d DATABASE',
|
43
|
+
long: '--database DATABASE',
|
44
|
+
description: 'MySQL database',
|
45
|
+
default: ''
|
46
|
+
|
47
|
+
option :ini,
|
48
|
+
short: '-i',
|
49
|
+
long: '--ini VALUE',
|
50
|
+
description: 'My.cnf ini file'
|
51
|
+
|
52
|
+
option :ini_section,
|
53
|
+
description: 'Section in my.cnf ini file',
|
54
|
+
long: '--ini-section VALUE',
|
55
|
+
default: 'client'
|
56
|
+
|
57
|
+
option :socket,
|
58
|
+
short: '-S SOCKET',
|
59
|
+
long: '--socket SOCKET',
|
60
|
+
description: 'MySQL Unix socket to connect to'
|
61
|
+
|
62
|
+
option :name,
|
63
|
+
short: '-n NAME',
|
64
|
+
long: '--name NAME',
|
65
|
+
description: 'Metric name for a configured handler',
|
66
|
+
default: 'mysql.query_count'
|
67
|
+
|
68
|
+
option :query,
|
69
|
+
short: '-q SELECT_COUNT_QUERY',
|
70
|
+
long: '--query SELECT_COUNT_QUERY',
|
71
|
+
description: 'Query to execute',
|
72
|
+
required: true
|
73
|
+
|
74
|
+
def run
|
75
|
+
if config[:ini]
|
76
|
+
ini = IniFile.load(config[:ini])
|
77
|
+
section = ini[config[:ini_section]]
|
78
|
+
db_user = section['user']
|
79
|
+
db_pass = section['password']
|
80
|
+
else
|
81
|
+
db_user = config[:username]
|
82
|
+
db_pass = config[:password]
|
83
|
+
end
|
84
|
+
raise "invalid query : #{config[:query]}" unless config[:query] =~ /^select\s+count\(\s*\*\s*\)/i
|
85
|
+
|
86
|
+
db = Mysql.real_connect(config[:host], db_user, db_pass, config[:database], config[:port], config[:socket])
|
87
|
+
count = db.query(config[:query]).fetch_row[0].to_i
|
88
|
+
|
89
|
+
output config[:name], count
|
90
|
+
ok
|
91
|
+
|
92
|
+
rescue Mysql::Error => e
|
93
|
+
errstr = "Error code: #{e.errno} Error message: #{e.error}"
|
94
|
+
critical "#{errstr} SQLSTATE: #{e.sqlstate}" if e.respond_to?('sqlstate')
|
95
|
+
|
96
|
+
rescue StandardError => e
|
97
|
+
critical "unhandled exception: #{e}"
|
98
|
+
|
99
|
+
ensure
|
100
|
+
db.close if db
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Copyright 2014 Paulo Miguel Almeida Rodenas (paulo.ubuntu@gmail.com)
|
4
|
+
#
|
5
|
+
# Depends on mysql gem
|
6
|
+
# gem install mysql
|
7
|
+
#
|
8
|
+
# This handler sends metrics to a MySQL database for later user such as
|
9
|
+
# historic comparisons, charts and so on
|
10
|
+
#
|
11
|
+
# =========== Initial DDL ===========
|
12
|
+
# MySQL initial can be found in mysql-metrics.sql
|
13
|
+
#
|
14
|
+
# =========== Config ===========
|
15
|
+
# MySQL 'hostname', 'username', and 'password' must be
|
16
|
+
# specified in a config file in /etc/sensu/conf.d.
|
17
|
+
# See mysql-metrics.json for an example.
|
18
|
+
#
|
19
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
20
|
+
# for details.
|
21
|
+
|
22
|
+
require 'sensu-handler'
|
23
|
+
require 'json'
|
24
|
+
require 'mysql'
|
25
|
+
|
26
|
+
class MysqlMetric < Sensu::Handler
|
27
|
+
# override filters from Sensu::Handler. not appropriate for metric handlers
|
28
|
+
def filter; end
|
29
|
+
|
30
|
+
def handle
|
31
|
+
# mysql settings
|
32
|
+
mysql_hostname = settings['mysql']['hostname']
|
33
|
+
mysql_username = settings['mysql']['username']
|
34
|
+
mysql_password = settings['mysql']['password']
|
35
|
+
|
36
|
+
# event values
|
37
|
+
client_id = @event['client']['name']
|
38
|
+
check_name = @event['check']['name']
|
39
|
+
check_issued = @event['check']['issued']
|
40
|
+
check_output = @event['check']['output']
|
41
|
+
check_status = @event['check']['status']
|
42
|
+
|
43
|
+
begin
|
44
|
+
con = Mysql.new mysql_hostname, mysql_username, mysql_password
|
45
|
+
con.query('INSERT INTO '\
|
46
|
+
'sensumetrics.sensu_historic_metrics('\
|
47
|
+
'client_id, check_name, issue_time, '\
|
48
|
+
'output, status) '\
|
49
|
+
"VALUES ('#{client_id}', '#{check_name}', "\
|
50
|
+
"#{check_issued}, '#{check_output}', #{check_status})")
|
51
|
+
rescue Mysql::Error => e
|
52
|
+
puts e.errno
|
53
|
+
puts e.error
|
54
|
+
ensure
|
55
|
+
con.close if con
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
create database sensumetrics;
|
2
|
+
use sensumetrics;
|
3
|
+
create table sensu_historic_metrics(
|
4
|
+
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
5
|
+
`client_id` VARCHAR(150) NOT NULL,
|
6
|
+
`check_name` VARCHAR(100) NOT NULL,
|
7
|
+
`issue_time` INT(8) UNSIGNED NOT NULL,
|
8
|
+
`output` TEXT,
|
9
|
+
`status` INT(2) UNSIGNED,
|
10
|
+
INDEX `client_id_idx` (`client_id`),
|
11
|
+
INDEX `check_name_idx` (`check_name`),
|
12
|
+
INDEX `issue_time_idx` (`issue_time`)
|
13
|
+
);
|
14
|
+
GRANT SELECT,INSERT on sensumetrics.sensu_historic_metrics TO sensu_user@'localhost' IDENTIFIED BY 'sensu_user_pass';
|
15
|
+
FLUSH PRIVILEGES;
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'sensu-plugins-mysql/version'
|
metadata
ADDED
@@ -0,0 +1,262 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sensu-plugins-mysql-nagyt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.6.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sensu-Plugins and contributors
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: inifile
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ruby-mysql
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.9'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sensu-plugin
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: codeclimate-test-reporter
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.4'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.7'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.7'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: github-markup
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.10'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.10'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rake
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '10.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '10.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: redcarpet
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '3.2'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '3.2'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rspec
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '3.1'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '3.1'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rubocop
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 0.40.0
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 0.40.0
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: yard
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0.8'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0.8'
|
181
|
+
description: |-
|
182
|
+
This plugin provides native MySQL instrumentation
|
183
|
+
for monitoring and metrics collection, including:
|
184
|
+
service health, database connectivity, `InnoDB`
|
185
|
+
locks, replication status, metrics collection, and
|
186
|
+
sending metrics to a MySQL database.
|
187
|
+
email: "<sensu-users@googlegroups.com>"
|
188
|
+
executables:
|
189
|
+
- check-mysql-status.rb
|
190
|
+
- check-mysql-connections.rb
|
191
|
+
- check-mysql-threads.rb
|
192
|
+
- check-mysql-select-count.rb
|
193
|
+
- metrics-mysql-select-count.rb
|
194
|
+
- check-mysql-alive.rb
|
195
|
+
- metrics-mysql-query-result-count.rb
|
196
|
+
- check-mysql-disk.rb
|
197
|
+
- check-mysql-msr-replication-status.rb
|
198
|
+
- metrics-mysql-raw.rb
|
199
|
+
- metrics-mysql-multiple-select-count.rb
|
200
|
+
- check-mysql-innodb-lock.rb
|
201
|
+
- metrics-mysql-processes.rb
|
202
|
+
- check-mysql-replication-status.rb
|
203
|
+
- metrics-mysql-graphite.rb
|
204
|
+
- check-mysql-query-result-count.rb
|
205
|
+
- metrics-mysql.rb
|
206
|
+
extensions: []
|
207
|
+
extra_rdoc_files: []
|
208
|
+
files:
|
209
|
+
- CHANGELOG.md
|
210
|
+
- LICENSE
|
211
|
+
- README.md
|
212
|
+
- bin/check-mysql-alive.rb
|
213
|
+
- bin/check-mysql-connections.rb
|
214
|
+
- bin/check-mysql-disk.rb
|
215
|
+
- bin/check-mysql-innodb-lock.rb
|
216
|
+
- bin/check-mysql-msr-replication-status.rb
|
217
|
+
- bin/check-mysql-query-result-count.rb
|
218
|
+
- bin/check-mysql-replication-status.rb
|
219
|
+
- bin/check-mysql-select-count.rb
|
220
|
+
- bin/check-mysql-status.rb
|
221
|
+
- bin/check-mysql-threads.rb
|
222
|
+
- bin/metrics-mysql-graphite.rb
|
223
|
+
- bin/metrics-mysql-multiple-select-count.rb
|
224
|
+
- bin/metrics-mysql-processes.rb
|
225
|
+
- bin/metrics-mysql-query-result-count.rb
|
226
|
+
- bin/metrics-mysql-raw.rb
|
227
|
+
- bin/metrics-mysql-select-count.rb
|
228
|
+
- bin/metrics-mysql.rb
|
229
|
+
- bin/mysql-metrics.sql
|
230
|
+
- lib/sensu-plugins-mysql.rb
|
231
|
+
- lib/sensu-plugins-mysql/version.rb
|
232
|
+
homepage: https://github.com/nagyt/sensu-plugins-mysql
|
233
|
+
licenses:
|
234
|
+
- MIT
|
235
|
+
metadata:
|
236
|
+
maintainer: sensu-plugin
|
237
|
+
development_status: active
|
238
|
+
production_status: unstable - testing recommended
|
239
|
+
release_draft: 'false'
|
240
|
+
release_prerelease: 'false'
|
241
|
+
post_install_message: You can use the embedded Ruby by setting EMBEDDED_RUBY=true
|
242
|
+
in /etc/default/sensu
|
243
|
+
rdoc_options: []
|
244
|
+
require_paths:
|
245
|
+
- lib
|
246
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
247
|
+
requirements:
|
248
|
+
- - ">="
|
249
|
+
- !ruby/object:Gem::Version
|
250
|
+
version: 2.0.0
|
251
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
252
|
+
requirements:
|
253
|
+
- - ">="
|
254
|
+
- !ruby/object:Gem::Version
|
255
|
+
version: '0'
|
256
|
+
requirements: []
|
257
|
+
rubyforge_project:
|
258
|
+
rubygems_version: 2.7.3
|
259
|
+
signing_key:
|
260
|
+
specification_version: 4
|
261
|
+
summary: Sensu plugins for MySql
|
262
|
+
test_files: []
|