sensu-plugins-mysql 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +7 -1
- data/bin/check-mysql-query-result-count.rb +102 -0
- data/lib/sensu-plugins-mysql/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 09befac0a6d69ea724280ceed0de5e745675a15b
|
4
|
+
data.tar.gz: 1361386396355226ae7d80fc47353a7144de726b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 256cb9c8249af6be2343b98d2bb1e9aba3fcaec0c7eb11748dd7610061a16c85a3f0bf8efd63de185e36ccdc292955ff7e0d2b0d48540d9206e99d5b0d4547a5
|
7
|
+
data.tar.gz: efe0cc759521f9e3883bc2b99119987fa8b1a83c029704f49e01315bd4380cbaae4586a48c3e9be41d65717e4454f975d4417734021f6c5adedb33dda8f370b9
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,9 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
|
|
5
5
|
|
6
6
|
## [Unreleased]
|
7
7
|
|
8
|
+
## [1.2.0] - 2017-03-23
|
9
|
+
- Add check-mysql-query-result-count.rb script (@athal7)
|
10
|
+
|
8
11
|
## [1.1.0] - 2017-01-15
|
9
12
|
### Added
|
10
13
|
- Added minimum thresholds to the check-mysql-threads.rb script
|
@@ -51,7 +54,8 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
|
|
51
54
|
### Added
|
52
55
|
- initial release
|
53
56
|
|
54
|
-
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/1.
|
57
|
+
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/1.2.0...HEAD
|
58
|
+
[1.2.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/1.1.0...1.2.0
|
55
59
|
[1.1.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/1.0.0...1.1.0
|
56
60
|
[1.0.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/0.0.4...1.0.0
|
57
61
|
[0.0.4]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/0.0.3...0.0.4
|
data/README.md
CHANGED
@@ -16,6 +16,7 @@
|
|
16
16
|
* bin/check-mysql-disk.rb
|
17
17
|
* bin/check-mysql-innodb-lock.rb
|
18
18
|
* bin/check-mysql-threads.rb
|
19
|
+
* bin/check-mysql-query-result-count.rb
|
19
20
|
* bin/metrics-mysql-graphite.rb
|
20
21
|
* bin/metrics-mysql-processes.rb
|
21
22
|
* bin/metrics-mysql-raw.rb
|
@@ -45,6 +46,11 @@
|
|
45
46
|
/opt/sensu/embedded/bin$ /opt/sensu/embedded/bin/ruby check-mysql-connections.rb --host=localhost --port=3306 --user=collectd --pass=tflypass --socket=/data/mysql.sock
|
46
47
|
```
|
47
48
|
|
49
|
+
**check-mysql-query-result-count** example
|
50
|
+
```bash
|
51
|
+
/opt/sensu/embedded/bin$ /opt/sensu/embedded/bin/ruby check-mysql-query-result-count.rb --host=localhost --port=3306 --user=collectd --pass=tflypass --socket=/data/mysql.sock --warning 1 --critical 10 --query 'SELECT DISTINCT(t.id) FROM table t where t.failed = true'
|
52
|
+
```
|
53
|
+
|
48
54
|
## Installation
|
49
55
|
|
50
56
|
[Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
|
@@ -53,7 +59,7 @@
|
|
53
59
|
The ruby executables are install in path similar to `/opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-plugins-mysql-0.0.4/bin`
|
54
60
|
|
55
61
|
## Troubleshooting
|
56
|
-
When used in `chef`, if the dependencies are missing, an error may abort the chef-client run:
|
62
|
+
When used in `chef`, if the dependencies are missing, an error may abort the chef-client run:
|
57
63
|
```bash
|
58
64
|
*** extconf.rb failed ***
|
59
65
|
Could not create Makefile due to some reason, probably lack of
|
@@ -0,0 +1,102 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# MySQL Query Result Count Check
|
4
|
+
#
|
5
|
+
# Checks the length of a result set from a MySQL query.
|
6
|
+
#
|
7
|
+
# Copyright 2017 Andrew Thal <athal7@me.com>
|
8
|
+
#
|
9
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
10
|
+
# for details.
|
11
|
+
|
12
|
+
require 'sensu-plugin/check/cli'
|
13
|
+
require 'mysql'
|
14
|
+
require 'inifile'
|
15
|
+
|
16
|
+
class MysqlQueryCountCheck < Sensu::Plugin::Check::CLI
|
17
|
+
option :host,
|
18
|
+
short: '-h HOST',
|
19
|
+
long: '--host HOST',
|
20
|
+
description: 'MySQL Host to connect to',
|
21
|
+
required: true
|
22
|
+
|
23
|
+
option :port,
|
24
|
+
short: '-P PORT',
|
25
|
+
long: '--port PORT',
|
26
|
+
description: 'MySQL Port to connect to',
|
27
|
+
proc: proc(&:to_i),
|
28
|
+
default: 3306
|
29
|
+
|
30
|
+
option :username,
|
31
|
+
short: '-u USERNAME',
|
32
|
+
long: '--user USERNAME',
|
33
|
+
description: 'MySQL Username'
|
34
|
+
|
35
|
+
option :password,
|
36
|
+
short: '-p PASSWORD',
|
37
|
+
long: '--pass PASSWORD',
|
38
|
+
description: 'MySQL password',
|
39
|
+
default: ''
|
40
|
+
|
41
|
+
option :ini,
|
42
|
+
short: '-i',
|
43
|
+
long: '--ini VALUE',
|
44
|
+
description: 'My.cnf ini file'
|
45
|
+
|
46
|
+
option :socket,
|
47
|
+
short: '-S SOCKET',
|
48
|
+
long: '--socket SOCKET',
|
49
|
+
description: 'MySQL Unix socket to connect to'
|
50
|
+
|
51
|
+
option :warn,
|
52
|
+
short: '-w COUNT',
|
53
|
+
long: '--warning COUNT',
|
54
|
+
description: 'COUNT warning threshold for number of items returned by the query',
|
55
|
+
proc: proc(&:to_i),
|
56
|
+
required: true
|
57
|
+
|
58
|
+
option :crit,
|
59
|
+
short: '-c COUNT',
|
60
|
+
long: '--critical COUNT',
|
61
|
+
description: 'COUNT critical threshold for number of items returned by the query',
|
62
|
+
proc: proc(&:to_i),
|
63
|
+
required: true
|
64
|
+
|
65
|
+
option :query,
|
66
|
+
short: '-q QUERY',
|
67
|
+
long: '--query QUERY',
|
68
|
+
description: 'Query to execute',
|
69
|
+
required: true
|
70
|
+
|
71
|
+
def run
|
72
|
+
if config[:ini]
|
73
|
+
ini = IniFile.load(config[:ini])
|
74
|
+
section = ini['client']
|
75
|
+
db_user = section['user']
|
76
|
+
db_pass = section['password']
|
77
|
+
else
|
78
|
+
db_user = config[:user]
|
79
|
+
db_pass = config[:password]
|
80
|
+
end
|
81
|
+
db = Mysql.real_connect(config[:hostname], db_user, db_pass, config[:database], config[:port].to_i, config[:socket])
|
82
|
+
length = db.query(config[:query]).count
|
83
|
+
|
84
|
+
if length >= config[:crit]
|
85
|
+
critical "Result count is above the CRITICAL limit: #{length} length / #{config[:crit]} limit"
|
86
|
+
elsif length >= config[:warn]
|
87
|
+
warning "Result count is above the WARNING limit: #{length} length / #{config[:warn]} limit"
|
88
|
+
else
|
89
|
+
ok 'Result count length is below thresholds'
|
90
|
+
end
|
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 => e
|
97
|
+
critical e
|
98
|
+
|
99
|
+
ensure
|
100
|
+
db.close if db
|
101
|
+
end
|
102
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugins-mysql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sensu-Plugins and contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: inifile
|
@@ -190,6 +190,7 @@ executables:
|
|
190
190
|
- check-mysql-connections.rb
|
191
191
|
- check-mysql-disk.rb
|
192
192
|
- check-mysql-innodb-lock.rb
|
193
|
+
- check-mysql-query-result-count.rb
|
193
194
|
- check-mysql-replication-status.rb
|
194
195
|
- check-mysql-status.rb
|
195
196
|
- check-mysql-threads.rb
|
@@ -207,6 +208,7 @@ files:
|
|
207
208
|
- bin/check-mysql-connections.rb
|
208
209
|
- bin/check-mysql-disk.rb
|
209
210
|
- bin/check-mysql-innodb-lock.rb
|
211
|
+
- bin/check-mysql-query-result-count.rb
|
210
212
|
- bin/check-mysql-replication-status.rb
|
211
213
|
- bin/check-mysql-status.rb
|
212
214
|
- bin/check-mysql-threads.rb
|