sensu-plugins-mysql 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5922468dc21649e24a29345516eb02ff4f9002aee5415d1aa6248a5cd387bbd9
4
- data.tar.gz: c934f6e0c33d107072e897ad3a1ae1e8e316cdfd029df64100114f6f2aae849c
3
+ metadata.gz: 00bad3fc713f6812222e0256b8495ec87d6cf0c64668d7caad5d64f58841a5ce
4
+ data.tar.gz: 69e155cf7bc0370fe2f21a425cd727fce4c444de31c9a8731d69501588a3cbb2
5
5
  SHA512:
6
- metadata.gz: 20418c01d373e088978a0162297164776e1a2e4eeed071a9fa45218906ddaa2fa00980215c7fd4362b01b9f164fb24afbf29762d69e063c0d5fdce40a1da5e57
7
- data.tar.gz: 7202eeb5502b433c9aced5191a8cb9ebb1287cff3fc977535276042acf97f77665fabed0a4738b9be5a077d29a67cb4f44d6e165a9e243c9c9f19cb320659247
6
+ metadata.gz: 1a391131fbca828fcab9759aec2a593e964cc09a486bb614fb90e9f06e2893abb24cf63df68dd14559c9cd09d277df3e9bf05433d370d5e10860f385aa1f7a03
7
+ data.tar.gz: b0a6e03148a3038376e501d1c11283ae1cff8f1e3bc756eb91e8439553b313f35b781dd184b1e21ecec49ad30362b27528cac1ba3c24dde6b626844ff482d03b
@@ -5,6 +5,10 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [3.1.0] - 2018-12-15
9
+ ### Added
10
+ - metrics-mysql-multiple-select-countcript (@nagyt234)
11
+
8
12
 
9
13
  ## [3.0.0] - 2018-12-04
10
14
  ### Security
@@ -153,6 +157,7 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
153
157
  - initial release
154
158
 
155
159
  [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/3.0.0...HEAD
160
+ [3.1.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/3.0.0...3.1.0
156
161
  [3.0.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.7.0...3.0.0
157
162
  [2.7.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.6.0...2.7.0
158
163
  [2.6.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.5.1...2.6.0
data/README.md CHANGED
@@ -20,6 +20,7 @@
20
20
  * bin/check-mysql-select-count.rb
21
21
  * bin/check-mysql-msr-replication-status.rb
22
22
  * bin/metrics-mysql-graphite.rb
23
+ * bin/metrics-mysql-multiple-select-count.rb
23
24
  * bin/metrics-mysql-processes.rb
24
25
  * bin/metrics-mysql-raw.rb
25
26
  * bin/metrics-mysql.rb
@@ -104,6 +105,10 @@ $ /opt/sensu/embedded/bin/check-mysql-replication-status.rb --host=<SLAVE> --ini
104
105
  /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
  ```
106
107
 
108
+ **metrics-mysql-multiple-select-count** example
109
+ ```bash
110
+ /opt/sensu/embedded/bin$ /opt/sensu/embedded/bin/metrics-mysql-multiple-select-count.rb --host=localhost --port=3306 --user=collectd --pass=tflypass --socket=/data/mysql.sock --query '{"t1_count":"SELECT COUNT(*) FROM table t1", "t2_count":"SELECT COUNT(*) FROM table t2"}'
111
+ ```
107
112
  ### Security
108
113
 
109
114
  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.
@@ -124,6 +129,7 @@ In keeping with the principle of least privilege you should create a new user wi
124
129
  | metrics-mysql-processes.rb | `SELECT` |
125
130
  | metrics-mysql-query-result-count.rb | depends on query |
126
131
  | metrics-mysql-select-count.rb   | depends on query                                         |
132
+ | metrics-mysql-multiple-select-count   | depends on query                                         |
127
133
  | metrics-mysql-raw.rb | `SELECT` |
128
134
  | metrics-mysql.rb | `INSERT` into `sensumetrics.sensu_historic_metrics` |
129
135
 
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # MySQL Select Count Metrics
4
+ #
5
+ # Creates a graphite-formatted metrics for the first values of a result set from MySQL queries
6
+ # defined as a JSON parameter.
7
+ #
8
+ # Copyright 2017 Andrew Thal <athal7@me.com>
9
+ # Copyright 2018 Tibor Nagy <nagyt@hu.inter.net>
10
+ #
11
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
12
+ # for details.
13
+
14
+ require 'sensu-plugin/metric/cli'
15
+ require 'mysql'
16
+ require 'inifile'
17
+ require 'json'
18
+
19
+ class MysqlQueryCountMetric < Sensu::Plugin::Metric::CLI::Graphite
20
+ option :host,
21
+ short: '-h HOST',
22
+ long: '--host HOST',
23
+ description: 'MySQL Host to connect to',
24
+ required: true
25
+
26
+ option :port,
27
+ short: '-P PORT',
28
+ long: '--port PORT',
29
+ description: 'MySQL Port to connect to',
30
+ proc: proc(&:to_i),
31
+ default: 3306
32
+
33
+ option :username,
34
+ short: '-u USERNAME',
35
+ long: '--user USERNAME',
36
+ description: 'MySQL Username'
37
+
38
+ option :password,
39
+ short: '-p PASSWORD',
40
+ long: '--pass PASSWORD',
41
+ description: 'MySQL password'
42
+
43
+ option :database,
44
+ short: '-d DATABASE',
45
+ long: '--database DATABASE',
46
+ description: 'MySQL database',
47
+ default: ''
48
+
49
+ option :ini,
50
+ short: '-i',
51
+ long: '--ini VALUE',
52
+ description: 'My.cnf ini file'
53
+
54
+ option :ini_section,
55
+ description: 'Section in my.cnf ini file',
56
+ long: '--ini-section VALUE',
57
+ default: 'client'
58
+
59
+ option :socket,
60
+ short: '-S SOCKET',
61
+ long: '--socket SOCKET',
62
+ description: 'MySQL Unix socket to connect to'
63
+
64
+ option :name,
65
+ short: '-n NAME',
66
+ long: '--name NAME',
67
+ description: 'Metric name for a configured handler',
68
+ default: 'mysql.query_count'
69
+
70
+ option :query,
71
+ short: '-q SELECT_COUNT_QUERIES',
72
+ long: '--query SELECT_COUNT_QUERIES',
73
+ description: 'Queries to execute in JSON',
74
+ required: true
75
+
76
+ def run
77
+ if config[:ini]
78
+ ini = IniFile.load(config[:ini])
79
+ section = ini[config[:ini_section]]
80
+ db_user = section['user']
81
+ db_pass = section['password']
82
+ else
83
+ db_user = config[:username]
84
+ db_pass = config[:password]
85
+ end
86
+
87
+ begin
88
+ query_hash = ::JSON.parse config[:query]
89
+ rescue ::JSON::ParserError => e
90
+ critical "JSON.parse error: #{e}"
91
+ end
92
+
93
+ # traverse all SQL
94
+ query_hash.each do |key, sql|
95
+ raise "invalid query : #{sql}" unless sql =~ /^select\s+count\(\s*\*\s*\)/i
96
+
97
+ db = Mysql.real_connect(config[:host], db_user, db_pass, config[:database], config[:port], config[:socket])
98
+ count = db.query(sql).fetch_row[0].to_i
99
+
100
+ output "#{config[:name]}.#{key}", count
101
+ end
102
+
103
+ ok
104
+ rescue Mysql::Error => e
105
+ errstr = "Error code: #{e.errno} Error message: #{e.error}"
106
+ critical "#{errstr} SQLSTATE: #{e.sqlstate}" if e.respond_to?('sqlstate')
107
+ rescue StandardError => e
108
+ critical "unhandled exception: #{e}"
109
+ end
110
+ end
@@ -1,7 +1,7 @@
1
1
  module SensuPluginsMySql
2
2
  module Version
3
3
  MAJOR = 3
4
- MINOR = 0
4
+ MINOR = 1
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: 3.0.0
4
+ version: 3.1.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-12-05 00:00:00.000000000 Z
11
+ date: 2018-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inifile
@@ -197,6 +197,7 @@ executables:
197
197
  - check-mysql-msr-replication-status.rb
198
198
  - metrics-mysql-processes.rb
199
199
  - check-mysql-status.rb
200
+ - metrics-mysql-multiple-select-count.rb
200
201
  - check-mysql-query-result-count.rb
201
202
  - check-mysql-threads.rb
202
203
  - check-mysql-alive.rb
@@ -219,6 +220,7 @@ files:
219
220
  - bin/check-mysql-status.rb
220
221
  - bin/check-mysql-threads.rb
221
222
  - bin/metrics-mysql-graphite.rb
223
+ - bin/metrics-mysql-multiple-select-count.rb
222
224
  - bin/metrics-mysql-processes.rb
223
225
  - bin/metrics-mysql-query-result-count.rb
224
226
  - bin/metrics-mysql-raw.rb