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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0574e1b596d0d9f104670b489dc9c0fb4c245202572d912f94a9e8f9b140c326
|
4
|
+
data.tar.gz: fbcb7258c7ad529bc7612b2d095ca8e64f87d71e095ea92e1a4618b9105c1647
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 804afcd1f806e4bbb0256301ebe64f46f8252d0c58bdd080785d0adacc9357b5beab64b7cde515118f99c71a4e7101c63613328d170353dee8150205212cdb31
|
7
|
+
data.tar.gz: 206bf05399577f37942c18950aed105b29bec8d6b058005109f41e5ea5baef34488cf1d0c094959e1ba538f437379e7e09be27b1e438a15eeb4514b5f26693dd
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
# Change Log
|
2
|
+
This project adheres to [Semantic Versioning](http://semver.org/).
|
3
|
+
|
4
|
+
This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md)
|
5
|
+
|
6
|
+
## [Unreleased]
|
7
|
+
### Added
|
8
|
+
- metrics-mysql-select-count.rb script (@nagyt234)
|
9
|
+
|
10
|
+
## [2.5.1] - 2018-06-21
|
11
|
+
### Fixed
|
12
|
+
- check-mysql-alive.rb: allow specifying a value for `-i` (@scones)
|
13
|
+
|
14
|
+
## [2.5.0] - 2018-06-12
|
15
|
+
### Added
|
16
|
+
- metrics-mysql-raw.rb: added `Qcache_free_memory` collection (@alchandia)
|
17
|
+
|
18
|
+
## [2.4.0] - 2018-06-4
|
19
|
+
### Added
|
20
|
+
- Add check-mysql-select-count.rb script (@negachov)
|
21
|
+
|
22
|
+
## [2.3.0] - 2018-03-17
|
23
|
+
### Added
|
24
|
+
- check-mysql-msr-replication-status.rb: new script that helps with monitoring mysql multi-source replication (@ndelic0)
|
25
|
+
|
26
|
+
### Changed
|
27
|
+
- appeased cops (@majormoses)
|
28
|
+
|
29
|
+
## [2.1.1] - 2018-02-07
|
30
|
+
### Fixed
|
31
|
+
- check-mysql-status.rb: if --socket flag is specified, it overrides config (@tinle)
|
32
|
+
|
33
|
+
## [2.2.0] - 2017-11-19
|
34
|
+
### Changed
|
35
|
+
- check-mysql-alive.rb: Add support for custom section in inifile. (@oba11)
|
36
|
+
- check-mysql-connections.rb: Add support for custom section in inifile. (@oba11)
|
37
|
+
- check-mysql-disk.rb: Add support for custom section in inifile. (@oba11)
|
38
|
+
- check-mysql-innodb-lock.rb: Add support for custom section in inifile. (@oba11)
|
39
|
+
- check-mysql-query-result-count.rb: Add support for custom section in inifile. (@oba11)
|
40
|
+
- check-mysql-replication-status.rb: Add support for custom section in inifile. (@oba11)
|
41
|
+
- check-mysql-status.rb: Add support for custom section in inifile. (@oba11)
|
42
|
+
- check-mysql-threads.rb: Add support for custom section in inifile. (@oba11)
|
43
|
+
- metrics-mysql-graphite.rb: Add support for custom section in inifile. (@oba11)
|
44
|
+
- metrics-mysql-processes.rb: Add support for custom section in inifile. (@oba11)
|
45
|
+
- metrics-mysql-query-result-count.rb: Add support for custom section in inifile. (@oba11)
|
46
|
+
- metrics-mysql-raw.rb: Add support for custom section in inifile. (@oba11)
|
47
|
+
- README.md: update useage to have an example using the custom ini section (@majormoses)
|
48
|
+
- update changelog guidelines location (@majormoses)
|
49
|
+
|
50
|
+
### Fixed
|
51
|
+
- misc spelling and whitespace (@majormoses)
|
52
|
+
|
53
|
+
## [2.1.2] - 2017-10-04
|
54
|
+
### Changed
|
55
|
+
- In `README` clarify why they should not use privileged users for monitoring with sensu. (@majormoses)
|
56
|
+
- In `README` add more usage examples. (@rwillmer)
|
57
|
+
|
58
|
+
### Fixed
|
59
|
+
- check-mysql-disk.rb: fixed short option `-s` to `-S` for `--socket` as it conflicted with `--size` (@2autunni)
|
60
|
+
|
61
|
+
## [2.1.1] - 2017-06-25
|
62
|
+
### Added
|
63
|
+
- Added minimum viable permissions in `README` for all the checks, metrics, and handlers. (@majormoses)
|
64
|
+
|
65
|
+
### Fixed
|
66
|
+
- check-mysql-disk.rb: make required options required. (@majormoses)
|
67
|
+
|
68
|
+
### Changed
|
69
|
+
- check-mysql-disk.rb: misc changes on where option output is cast. (@majormoses)
|
70
|
+
|
71
|
+
## [2.1.0] - 2017-06-10
|
72
|
+
### Added
|
73
|
+
- metrics-mysql-query-result-count.rb: Creates a graphite-formatted metric for the length of a result set from a MySQL query. (@athal7)
|
74
|
+
|
75
|
+
## [2.0.0] - 2017-06-05
|
76
|
+
### Breaking Change
|
77
|
+
- check-mysql-status.rb: renamed short arg of `--check` due to conflicts (@majormoses)
|
78
|
+
|
79
|
+
### Changed
|
80
|
+
- check-mysql-status.rb: made the options easier to read by splitting them across multiple lines (@majormoses)
|
81
|
+
|
82
|
+
### Added
|
83
|
+
- Add testing on Ruby 2.4 (@eheydrick)
|
84
|
+
|
85
|
+
## [1.2.1] - 2017-05-03
|
86
|
+
### Fixed
|
87
|
+
- Fix configuration for check-mysql-query-result-count.rb script (@athal7)
|
88
|
+
|
89
|
+
## [1.2.0] - 2017-03-23
|
90
|
+
- Add check-mysql-query-result-count.rb script (@athal7)
|
91
|
+
|
92
|
+
## [1.1.0] - 2017-01-15
|
93
|
+
### Added
|
94
|
+
- Added minimum thresholds to the check-mysql-threads.rb script
|
95
|
+
- Added metrics plugin with mysql gem requirement
|
96
|
+
- Added metrics plugin metrics-mysql-processes from `SHOW PROCESSLIST`
|
97
|
+
- Added fallback plugin check-mysql-status.rb with no mysql gem requirement - status and replication
|
98
|
+
- Added multi source replication parameter on check-mysql-replication-status.rb
|
99
|
+
|
100
|
+
### Fixed
|
101
|
+
- metrics-mysql-graphite.rb: Properly close mysql connection
|
102
|
+
|
103
|
+
## [1.0.0] - 2016-08-15
|
104
|
+
### Added
|
105
|
+
- added check-mysql-threads.rb script
|
106
|
+
- changed metrics-mysql-graphite.rb to use mysql / ruby-mysql gem
|
107
|
+
|
108
|
+
### Changed
|
109
|
+
- Removed compatibility with Ruby 1.9
|
110
|
+
- Updated sensu-plugin dependency from `= 1.2.0` to `~> 1.2`
|
111
|
+
- removed --help option as it comes from opt parser
|
112
|
+
|
113
|
+
### Removed
|
114
|
+
- check-cloudwatch-mysql-sensu.rb - sensu-plugins-aws check-cloudwatch-metric.rb should be used
|
115
|
+
|
116
|
+
## [0.0.4] - 2015-08-04
|
117
|
+
### Changed
|
118
|
+
- updated sensu-plugin gem to 1.2.0
|
119
|
+
|
120
|
+
## [0.0.3] - 2015-07-14
|
121
|
+
### Changed
|
122
|
+
- updated sensu-plugin gem to 1.2.0
|
123
|
+
|
124
|
+
### Added
|
125
|
+
- ability to read configuration data from an ini file
|
126
|
+
|
127
|
+
## [0.0.2] - 2015-06-03
|
128
|
+
### Fixed
|
129
|
+
- added binstubs
|
130
|
+
|
131
|
+
### Changed
|
132
|
+
- removed cruft from /lib
|
133
|
+
|
134
|
+
## 0.0.1 - 2015-05-29
|
135
|
+
### Added
|
136
|
+
- initial release
|
137
|
+
|
138
|
+
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.5.1...HEAD
|
139
|
+
[2.5.1]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.5.0...2.5.1
|
140
|
+
[2.5.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.4.0...2.5.0
|
141
|
+
[2.4.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.3.0...2.4.0
|
142
|
+
[2.3.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.2.1...2.3.0
|
143
|
+
[2.2.1]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.2.0..2.2.1
|
144
|
+
[2.2.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.1.1...2.2.0
|
145
|
+
[2.1.2]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.1.1...2.1.2
|
146
|
+
[2.1.1]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.1.0...2.1.1
|
147
|
+
[2.1.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.0.0...2.1.0
|
148
|
+
[2.0.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/1.2.1...2.0.0
|
149
|
+
[1.2.1]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/1.2.0...1.2.1
|
150
|
+
[1.2.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/1.1.0...1.2.0
|
151
|
+
[1.1.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/1.0.0...1.1.0
|
152
|
+
[1.0.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/0.0.4...1.0.0
|
153
|
+
[0.0.4]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/0.0.3...0.0.4
|
154
|
+
[0.0.3]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/0.0.2...0.0.3
|
155
|
+
[0.0.2]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/0.0.1...0.0.2
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Sensu-Plugins
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
## Sensu-Plugins-mysql
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/sensu-plugins/sensu-plugins-mysql.svg?branch=master)](https://travis-ci.org/sensu-plugins/sensu-plugins-mysql)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/sensu-plugins-mysql.svg)](http://badge.fury.io/rb/sensu-plugins-mysql)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/sensu-plugins/sensu-plugins-mysql/badges/gpa.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-mysql)
|
6
|
+
[![Test Coverage](https://codeclimate.com/github/sensu-plugins/sensu-plugins-mysql/badges/coverage.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-mysql)
|
7
|
+
[![Dependency Status](https://gemnasium.com/sensu-plugins/sensu-plugins-mysql.svg)](https://gemnasium.com/sensu-plugins/sensu-plugins-mysql)
|
8
|
+
|
9
|
+
## Functionality
|
10
|
+
|
11
|
+
## Files
|
12
|
+
* bin/check-cloudwatch-mysql-sensu.rb
|
13
|
+
* bin/check-mysql-alive.rb
|
14
|
+
* bin/check-mysql-status.rb
|
15
|
+
* bin/check-mysql-connections.rb
|
16
|
+
* bin/check-mysql-disk.rb
|
17
|
+
* bin/check-mysql-innodb-lock.rb
|
18
|
+
* bin/check-mysql-threads.rb
|
19
|
+
* bin/check-mysql-query-result-count.rb
|
20
|
+
* bin/check-mysql-select-count.rb
|
21
|
+
* bin/check-mysql-msr-replication-status.rb
|
22
|
+
* bin/metrics-mysql-graphite.rb
|
23
|
+
* bin/metrics-mysql-processes.rb
|
24
|
+
* bin/metrics-mysql-raw.rb
|
25
|
+
* bin/metrics-mysql.rb
|
26
|
+
* bin/metrics-mysql-query-result-count.rb
|
27
|
+
* bin/metrics-mysql-select-count.rb
|
28
|
+
* bin/mysql-metrics.sql
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
**metrics-mysql**
|
32
|
+
```
|
33
|
+
{
|
34
|
+
"mysql":{
|
35
|
+
"hostname": "localhost",
|
36
|
+
"username": "sensu_user",
|
37
|
+
"password": "sensu_user_pass"
|
38
|
+
}
|
39
|
+
}
|
40
|
+
```
|
41
|
+
|
42
|
+
**metrics-mysql-graphite** example:
|
43
|
+
```bash
|
44
|
+
/opt/sensu/embedded/bin$ /opt/sensu/embedded/bin/ruby metrics-mysql-graphite.rb --host=localhost --port=3306 --user=collectd --pass=tflypass --socket=/data/mysql.sock
|
45
|
+
```
|
46
|
+
|
47
|
+
**check-mysql-connections** example
|
48
|
+
```bash
|
49
|
+
/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
|
50
|
+
```
|
51
|
+
|
52
|
+
**check-mysql-connections** example with ini file to hide credentials
|
53
|
+
```bash
|
54
|
+
$ /opt/sensu/embedded/bin/check-mysql-connections.rb --host=<DBHOST> --ini=/etc/sensu/my.ini
|
55
|
+
```
|
56
|
+
|
57
|
+
**check-mysql-alive** example
|
58
|
+
```bash
|
59
|
+
$ /opt/sensu/embedded/bin/check-mysql-alive.rb --host=<DBHOST> --ini=/etc/sensu/my.ini --ini-section=customsection
|
60
|
+
```
|
61
|
+
|
62
|
+
**check-mysql-disk** example (note: you must supply max disk size)
|
63
|
+
```bash
|
64
|
+
$ /opt/sensu/embedded/bin/check-mysql-disk.rb --host=<DBHOST> --ini=/etc/sensu/my.ini --size <MAX_DB_SIZE>
|
65
|
+
```
|
66
|
+
|
67
|
+
**check-mysql-innodb-lock** example
|
68
|
+
```bash
|
69
|
+
$ /opt/sensu/embedded/bin/check-mysql-innodb-lock.rb --host=<DBHOST> --ini=/etc/sensu/my.ini
|
70
|
+
```
|
71
|
+
|
72
|
+
**check-mysql-threads** example
|
73
|
+
```bash
|
74
|
+
$ /opt/sensu/embedded/bin/check-mysql-threads.rb --host=<DBHOST> --ini=/etc/sensu/my.ini --warnlow 0
|
75
|
+
```
|
76
|
+
|
77
|
+
**check-mysql-replication-status** example
|
78
|
+
```bash
|
79
|
+
$ /opt/sensu/embedded/bin/check-mysql-replication-status.rb --host=<SLAVE> --ini=/etc/sensu/my.ini
|
80
|
+
```
|
81
|
+
|
82
|
+
**check-mysql-msr-replication-status** example
|
83
|
+
```bash
|
84
|
+
$ /opt/sensu/embedded/bin/check-mysql-replication-status.rb --host=<SLAVE> --ini=/etc/sensu/my.ini
|
85
|
+
```
|
86
|
+
|
87
|
+
**check-mysql-query-result-count** example
|
88
|
+
```bash
|
89
|
+
/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'
|
90
|
+
```
|
91
|
+
|
92
|
+
**check-mysql-select-count** example
|
93
|
+
```bash
|
94
|
+
/opt/sensu/embedded/bin$ /opt/sensu/embedded/bin/ruby check-mysql-select-count.rb --host=localhost --port=3306 --user=collectd --pass=tflypass --socket=/data/mysql.sock --warning 30000 --critical 50000 --query 'SELECT count(*) FROM table t'
|
95
|
+
```
|
96
|
+
|
97
|
+
**metrics-mysql-query-result-count** example
|
98
|
+
```bash
|
99
|
+
/opt/sensu/embedded/bin$ /opt/sensu/embedded/bin/ruby metrics-mysql-query-result-count.rb --host=localhost --port=3306 --user=collectd --pass=tflypass --socket=/data/mysql.sock --query 'SELECT DISTINCT(t.id) FROM table t where t.failed = true'
|
100
|
+
```
|
101
|
+
|
102
|
+
**metrics-mysql-select-count** example
|
103
|
+
```bash
|
104
|
+
/opt/sensu/embedded/bin$ /opt/sensu/embedded/bin/ruby metrics-mysql-select-count.rb --host=localhost --port=3306 --user=collectd --pass=tflypass --socket=/data/mysql.sock --query 'SELECT COUNT(*) FROM table t'
|
105
|
+
```
|
106
|
+
|
107
|
+
### Security
|
108
|
+
|
109
|
+
In keeping with the principle of least privilege you should create a new user with the minimum required permissions. See the table below for minimum permissions for each check.
|
110
|
+
|
111
|
+
| Check | Permissions |
|
112
|
+
|:---------------------------------------|:----------------------------------------------------------|
|
113
|
+
| check-mysql-alive.rb | `SELECT` |
|
114
|
+
| check-mysql-connections.rb | `SELECT` |
|
115
|
+
| check-mysql-disk.rb | `SELECT` |
|
116
|
+
| check-mysql-innodb-lock.rb | `PROCESS` |
|
117
|
+
| check-mysql-query-result-count.rb | depends on query |
|
118
|
+
| check-mysql-select-count.rb | `SELECT` |
|
119
|
+
| check-mysql-replication-status.rb | `SUPER` OR `REPLICATION_CLIENT` (the latter is preferable)|
|
120
|
+
| check-mysql-msr-replication-status.rb | `SELECT` |
|
121
|
+
| check-mysql-status.rb | `SELECT` |
|
122
|
+
| check-mysql-threads.rb | `SELECT` |
|
123
|
+
| metrics-mysql-graphite.rb | `SELECT` |
|
124
|
+
| metrics-mysql-processes.rb | `SELECT` |
|
125
|
+
| metrics-mysql-query-result-count.rb | depends on query |
|
126
|
+
| metrics-mysql-select-count.rb | depends on query |
|
127
|
+
| metrics-mysql-raw.rb | `SELECT` |
|
128
|
+
| metrics-mysql.rb | `INSERT` into `sensumetrics.sensu_historic_metrics` |
|
129
|
+
|
130
|
+
I would recommend using different users when you need to have more than RO access (`REPLICATION_CLIENT` or using the metrics handler) to limit the potential ramifications of that user being compromised.
|
131
|
+
|
132
|
+
## Installation
|
133
|
+
|
134
|
+
[Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
|
135
|
+
|
136
|
+
## Notes
|
137
|
+
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`
|
138
|
+
|
139
|
+
## Troubleshooting
|
140
|
+
When used in `chef`, if the dependencies are missing, an error may abort the chef-client run:
|
141
|
+
```bash
|
142
|
+
*** extconf.rb failed ***
|
143
|
+
Could not create Makefile due to some reason, probably lack of
|
144
|
+
necessary libraries and/or headers. Check the mkmf.log file for more
|
145
|
+
details. You may need configuration options.
|
146
|
+
```
|
147
|
+
This may be fixed by installing the mysql client library before the plugin:
|
148
|
+
```ruby
|
149
|
+
# http://serverfault.com/questions/415392/install-mysql-gem-for-use-in-chef-client
|
150
|
+
package "libmysqlclient-dev" do
|
151
|
+
action :install
|
152
|
+
end
|
153
|
+
|
154
|
+
sensu_gem 'sensu-plugins-mysql' do version '0.0.4' end
|
155
|
+
|
156
|
+
```
|
@@ -0,0 +1,102 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# MySQL Alive Plugin
|
4
|
+
# ===
|
5
|
+
#
|
6
|
+
# This plugin attempts to login to mysql with provided credentials.
|
7
|
+
#
|
8
|
+
# Copyright 2011 Joe Crim <josephcrim@gmail.com>
|
9
|
+
# Updated by Lewis Preson 2012 to accept a database parameter
|
10
|
+
# Updated by Oluwaseun Obajobi 2014 to accept ini argument
|
11
|
+
#
|
12
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
13
|
+
# for details.
|
14
|
+
#
|
15
|
+
# USING INI ARGUMENT
|
16
|
+
# This was implemented to load mysql credentials without parsing the username/password.
|
17
|
+
# The ini file should be readable by the sensu user/group.
|
18
|
+
# Ref: http://eric.lubow.org/2009/ruby/parsing-ini-files-with-ruby/
|
19
|
+
#
|
20
|
+
# EXAMPLE
|
21
|
+
# mysql-alive.rb -h db01 --ini '/etc/sensu/my.cnf'
|
22
|
+
# mysql-alive.rb -h db01 --ini '/etc/sensu/my.cnf' --ini-section customsection
|
23
|
+
#
|
24
|
+
# MY.CNF INI FORMAT
|
25
|
+
# [client]
|
26
|
+
# user=sensu
|
27
|
+
# password="abcd1234"
|
28
|
+
#
|
29
|
+
# [customsection]
|
30
|
+
# user=user
|
31
|
+
# password="password"
|
32
|
+
#
|
33
|
+
|
34
|
+
require 'sensu-plugin/check/cli'
|
35
|
+
require 'mysql'
|
36
|
+
require 'inifile'
|
37
|
+
|
38
|
+
class CheckMySQL < Sensu::Plugin::Check::CLI
|
39
|
+
option :user,
|
40
|
+
description: 'MySQL User',
|
41
|
+
short: '-u USER',
|
42
|
+
long: '--user USER'
|
43
|
+
|
44
|
+
option :password,
|
45
|
+
description: 'MySQL Password',
|
46
|
+
short: '-p PASS',
|
47
|
+
long: '--password PASS'
|
48
|
+
|
49
|
+
option :ini,
|
50
|
+
description: 'My.cnf ini file',
|
51
|
+
short: '-i VALUE',
|
52
|
+
long: '--ini VALUE'
|
53
|
+
|
54
|
+
option :ini_section,
|
55
|
+
description: 'Section in my.cnf ini file',
|
56
|
+
long: '--ini-section VALUE',
|
57
|
+
default: 'client'
|
58
|
+
|
59
|
+
option :hostname,
|
60
|
+
description: 'Hostname to login to',
|
61
|
+
short: '-h HOST',
|
62
|
+
long: '--hostname HOST'
|
63
|
+
|
64
|
+
option :database,
|
65
|
+
description: 'Database schema to connect to',
|
66
|
+
short: '-d DATABASE',
|
67
|
+
long: '--database DATABASE',
|
68
|
+
default: 'test'
|
69
|
+
|
70
|
+
option :port,
|
71
|
+
description: 'Port to connect to',
|
72
|
+
short: '-P PORT',
|
73
|
+
long: '--port PORT',
|
74
|
+
default: '3306'
|
75
|
+
|
76
|
+
option :socket,
|
77
|
+
description: 'Socket to use',
|
78
|
+
short: '-s SOCKET',
|
79
|
+
long: '--socket SOCKET'
|
80
|
+
|
81
|
+
def run
|
82
|
+
if config[:ini]
|
83
|
+
ini = IniFile.load(config[:ini])
|
84
|
+
section = ini[config[:ini_section]]
|
85
|
+
db_user = section['user']
|
86
|
+
db_pass = section['password']
|
87
|
+
else
|
88
|
+
db_user = config[:user]
|
89
|
+
db_pass = config[:password]
|
90
|
+
end
|
91
|
+
|
92
|
+
begin
|
93
|
+
db = Mysql.real_connect(config[:hostname], db_user, db_pass, config[:database], config[:port].to_i, config[:socket])
|
94
|
+
info = db.get_server_info
|
95
|
+
ok "Server version: #{info}"
|
96
|
+
rescue Mysql::Error => e
|
97
|
+
critical "Error message: #{e.error}"
|
98
|
+
ensure
|
99
|
+
db.close if db
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# MySQL Health Plugin
|
4
|
+
# ===
|
5
|
+
#
|
6
|
+
# This plugin counts the maximum connections your MySQL has reached and warns you according to specified limits
|
7
|
+
#
|
8
|
+
# Copyright 2012 Panagiotis Papadomitsos <pj@ezgr.net>
|
9
|
+
#
|
10
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
11
|
+
# for details.
|
12
|
+
|
13
|
+
require 'sensu-plugin/check/cli'
|
14
|
+
require 'mysql'
|
15
|
+
require 'inifile'
|
16
|
+
|
17
|
+
class CheckMySQLHealth < Sensu::Plugin::Check::CLI
|
18
|
+
option :user,
|
19
|
+
description: 'MySQL User',
|
20
|
+
short: '-u USER',
|
21
|
+
long: '--user USER',
|
22
|
+
default: 'root'
|
23
|
+
|
24
|
+
option :password,
|
25
|
+
description: 'MySQL Password',
|
26
|
+
short: '-p PASS',
|
27
|
+
long: '--password PASS'
|
28
|
+
|
29
|
+
option :ini,
|
30
|
+
description: 'My.cnf ini file',
|
31
|
+
short: '-i',
|
32
|
+
long: '--ini VALUE'
|
33
|
+
|
34
|
+
option :ini_section,
|
35
|
+
description: 'Section in my.cnf ini file',
|
36
|
+
long: '--ini-section VALUE',
|
37
|
+
default: 'client'
|
38
|
+
|
39
|
+
option :hostname,
|
40
|
+
description: 'Hostname to login to',
|
41
|
+
short: '-h HOST',
|
42
|
+
long: '--hostname HOST',
|
43
|
+
default: 'localhost'
|
44
|
+
|
45
|
+
option :port,
|
46
|
+
description: 'Port to connect to',
|
47
|
+
short: '-P PORT',
|
48
|
+
long: '--port PORT',
|
49
|
+
default: '3306'
|
50
|
+
|
51
|
+
option :socket,
|
52
|
+
description: 'Socket to use',
|
53
|
+
short: '-s SOCKET',
|
54
|
+
long: '--socket SOCKET'
|
55
|
+
|
56
|
+
option :maxwarn,
|
57
|
+
description: "Number of connections upon which we'll issue a warning",
|
58
|
+
short: '-w NUMBER',
|
59
|
+
long: '--warnnum NUMBER',
|
60
|
+
default: 100
|
61
|
+
|
62
|
+
option :maxcrit,
|
63
|
+
description: "Number of connections upon which we'll issue an alert",
|
64
|
+
short: '-c NUMBER',
|
65
|
+
long: '--critnum NUMBER',
|
66
|
+
default: 128
|
67
|
+
|
68
|
+
option :usepc,
|
69
|
+
description: 'Use percentage of defined max connections instead of absolute number',
|
70
|
+
short: '-a',
|
71
|
+
long: '--percentage',
|
72
|
+
default: false
|
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[:user]
|
82
|
+
db_pass = config[:password]
|
83
|
+
end
|
84
|
+
db = Mysql.real_connect(config[:hostname], db_user, db_pass, config[:database], config[:port].to_i, config[:socket])
|
85
|
+
max_con = db
|
86
|
+
.query("SHOW VARIABLES LIKE 'max_connections'")
|
87
|
+
.fetch_hash
|
88
|
+
.fetch('Value')
|
89
|
+
.to_i
|
90
|
+
used_con = db
|
91
|
+
.query("SHOW GLOBAL STATUS LIKE 'Threads_connected'")
|
92
|
+
.fetch_hash
|
93
|
+
.fetch('Value')
|
94
|
+
.to_i
|
95
|
+
if config[:usepc]
|
96
|
+
pc = used_con.fdiv(max_con) * 100
|
97
|
+
critical "Max connections reached in MySQL: #{used_con} out of #{max_con}" if pc >= config[:maxcrit].to_i
|
98
|
+
warning "Max connections reached in MySQL: #{used_con} out of #{max_con}" if pc >= config[:maxwarn].to_i
|
99
|
+
ok "Max connections is under limit in MySQL: #{used_con} out of #{max_con}" # rubocop:disable Style/IdenticalConditionalBranches
|
100
|
+
else
|
101
|
+
critical "Max connections reached in MySQL: #{used_con} out of #{max_con}" if used_con >= config[:maxcrit].to_i
|
102
|
+
warning "Max connections reached in MySQL: #{used_con} out of #{max_con}" if used_con >= config[:maxwarn].to_i
|
103
|
+
ok "Max connections is under limit in MySQL: #{used_con} out of #{max_con}" # rubocop:disable Style/IdenticalConditionalBranches
|
104
|
+
end
|
105
|
+
rescue Mysql::Error => e
|
106
|
+
critical "MySQL check failed: #{e.error}"
|
107
|
+
ensure
|
108
|
+
db.close if db
|
109
|
+
end
|
110
|
+
end
|