sensu-plugins-mysql 2.3.0 → 2.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b5e5653712ab73a7fb12a37a97c8472ffab497df
4
- data.tar.gz: 556cff86d0e9ceb1a7a2954527f858a2e5b7be1b
2
+ SHA256:
3
+ metadata.gz: 0f3c4c5c8032b4d4772fa261612cdfa3e253354fc4ecf3f91df6bd5de5ae3092
4
+ data.tar.gz: 80cc13b7479af0f2131327e376d1bf60c9fbca0bc80b2bea85d015068fe4e1a6
5
5
  SHA512:
6
- metadata.gz: 0166be616c39d39a56314c683e3f91fe09aad4cdad696a34a5115fb14fcc2f77ff389e149f5733d523e36c290719189f1ab3279f57f919bc6b900e20209e2c39
7
- data.tar.gz: 900c46efc192ba7c71b9ac3d975dd924e6ffc9beec6e75f366178e0498a6e6041219de8db613a8cdfe09d2e8381fb8c237c3ae717badde9a8d5ef5414d2205b7
6
+ metadata.gz: f4928ac744df5cfa609f918e1f3c6ebcce3c1a67d4d4cbbc55311c384341b90801bb58a97a1da8d2dce1627df3703fa6352f22e5116c35913b8786f58633b2bc
7
+ data.tar.gz: 338847d6b300427fb42ca5ee97db87fa9512520743457de3746e43405050a9327d2aadc6631285516eea0fa0b98bf2298a1099c66fa86902f64855bfb775245b
data/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [2.4.0] - 2018-06-4
9
+ ### Added
10
+ - Add check-mysql-select-count.rb script (@negachov)
11
+
8
12
  ## [2.3.0] - 2018-03-17
9
13
  ### Added
10
14
  - check-mysql-msr-replication-status.rb: new script that helps with monitoring mysql multi-source replication (@ndelic0)
@@ -121,7 +125,8 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
121
125
  ### Added
122
126
  - initial release
123
127
 
124
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.3.0...HEAD
128
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.4.0...HEAD
129
+ [2.4.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.3.0...2.4.0
125
130
  [2.3.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.2.1...2.3.0
126
131
  [2.2.1]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.2.0..2.2.1
127
132
  [2.2.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.1.1...2.2.0
data/README.md CHANGED
@@ -17,6 +17,7 @@
17
17
  * bin/check-mysql-innodb-lock.rb
18
18
  * bin/check-mysql-threads.rb
19
19
  * bin/check-mysql-query-result-count.rb
20
+ * bin/check-mysql-select-count.rb
20
21
  * bin/check-mysql-msr-replication-status.rb
21
22
  * bin/metrics-mysql-graphite.rb
22
23
  * bin/metrics-mysql-processes.rb
@@ -87,6 +88,11 @@ $ /opt/sensu/embedded/bin/check-mysql-replication-status.rb --host=<SLAVE> --ini
87
88
  /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'
88
89
  ```
89
90
 
91
+ **check-mysql-select-count** example
92
+ ```bash
93
+ /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'
94
+ ```
95
+
90
96
  **metrics-mysql-query-result-count** example
91
97
  ```bash
92
98
  /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'
@@ -103,6 +109,7 @@ In keeping with the principle of least privilege you should create a new user wi
103
109
  | check-mysql-disk.rb | `SELECT` |
104
110
  | check-mysql-innodb-lock.rb | `PROCESS` |
105
111
  | check-mysql-query-result-count.rb | depends on query |
112
+ | check-mysql-select-count.rb | `SELECT` |
106
113
  | check-mysql-replication-status.rb | `SUPER` OR `REPLICATION_CLIENT` (the latter is preferable)|
107
114
  | check-mysql-msr-replication-status.rb | `SELECT` |
108
115
  | check-mysql-status.rb | `SELECT` |
@@ -0,0 +1,115 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # MySQL Select Count Check
4
+ #
5
+ # Checks the length of a result set from a MySQL query.
6
+ #
7
+ # Copyright 2017 Andrew Thal <athal7@me.com> to check-mysql-query-result-count.rb
8
+ # Modified by Mutsutoshi Yoshimoto <negachov@gmail.com> 2018 to select count(*) version
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 MysqlSelectCountCheck < Sensu::Plugin::Check::CLI
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
+ required: true
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 :warn,
63
+ short: '-w COUNT',
64
+ long: '--warning COUNT',
65
+ description: 'Warning when query value exceeds threshold',
66
+ proc: proc(&:to_i),
67
+ required: true
68
+
69
+ option :crit,
70
+ short: '-c COUNT',
71
+ long: '--critical COUNT',
72
+ description: 'Critical when query value exceeds threshold',
73
+ proc: proc(&:to_i),
74
+ required: true
75
+
76
+ option :query,
77
+ short: '-q SELECT_COUNT_QUERY',
78
+ long: '--query SELECT_COUNT_QUERY',
79
+ description: 'Query to execute',
80
+ required: true
81
+
82
+ def run
83
+ if config[:ini]
84
+ ini = IniFile.load(config[:ini])
85
+ section = ini[config[:ini_section]]
86
+ db_user = section['user']
87
+ db_pass = section['password']
88
+ else
89
+ db_user = config[:username]
90
+ db_pass = config[:password]
91
+ end
92
+ raise "invalid query : #{config[:query]}" unless config[:query] =~ /^select\s+count\(\s*\*\s*\)/i
93
+
94
+ db = Mysql.real_connect(config[:host], db_user, db_pass, config[:database], config[:port], config[:socket])
95
+
96
+ count = db.query(config[:query]).fetch_row[0].to_i
97
+ if count >= config[:crit]
98
+ critical "Count is above the CRITICAL limit: #{count} count / #{config[:crit]} limit"
99
+ elsif count >= config[:warn]
100
+ warning "Count is above the WARNING limit: #{count} count / #{config[:warn]} limit"
101
+ else
102
+ ok "Count is below thresholds : #{count} count"
103
+ end
104
+
105
+ rescue Mysql::Error => e
106
+ errstr = "Error code: #{e.errno} Error message: #{e.error}"
107
+ critical "#{errstr} SQLSTATE: #{e.sqlstate}" if e.respond_to?('sqlstate')
108
+
109
+ rescue StandardError => e
110
+ critical "unhandled exception: #{e}"
111
+
112
+ ensure
113
+ db.close if db
114
+ end
115
+ end
@@ -1,7 +1,7 @@
1
1
  module SensuPluginsMySql
2
2
  module Version
3
3
  MAJOR = 2
4
- MINOR = 3
4
+ MINOR = 4
5
5
  PATCH = 0
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
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: 2.3.0
4
+ version: 2.4.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: 2018-03-17 00:00:00.000000000 Z
11
+ date: 2018-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inifile
@@ -186,20 +186,21 @@ description: |-
186
186
  sending metrics to a MySQL database.
187
187
  email: "<sensu-users@googlegroups.com>"
188
188
  executables:
189
- - metrics-mysql-query-result-count.rb
189
+ - check-mysql-alive.rb
190
+ - check-mysql-connections.rb
190
191
  - check-mysql-disk.rb
191
- - metrics-mysql.rb
192
192
  - check-mysql-innodb-lock.rb
193
- - check-mysql-alive.rb
193
+ - check-mysql-msr-replication-status.rb
194
194
  - check-mysql-query-result-count.rb
195
- - metrics-mysql-graphite.rb
196
195
  - check-mysql-replication-status.rb
196
+ - check-mysql-status.rb
197
197
  - check-mysql-threads.rb
198
- - check-mysql-msr-replication-status.rb
198
+ - metrics-mysql-graphite.rb
199
199
  - metrics-mysql-processes.rb
200
+ - metrics-mysql-query-result-count.rb
200
201
  - metrics-mysql-raw.rb
201
- - check-mysql-connections.rb
202
- - check-mysql-status.rb
202
+ - metrics-mysql.rb
203
+ - check-mysql-select-count.rb
203
204
  extensions: []
204
205
  extra_rdoc_files: []
205
206
  files:
@@ -213,6 +214,7 @@ files:
213
214
  - bin/check-mysql-msr-replication-status.rb
214
215
  - bin/check-mysql-query-result-count.rb
215
216
  - bin/check-mysql-replication-status.rb
217
+ - bin/check-mysql-select-count.rb
216
218
  - bin/check-mysql-status.rb
217
219
  - bin/check-mysql-threads.rb
218
220
  - bin/metrics-mysql-graphite.rb
@@ -249,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
249
251
  version: '0'
250
252
  requirements: []
251
253
  rubyforge_project:
252
- rubygems_version: 2.5.2.1
254
+ rubygems_version: 2.7.7
253
255
  signing_key:
254
256
  specification_version: 4
255
257
  summary: Sensu plugins for MySql