sensu-plugins-mysql 2.6.0 → 2.7.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
2
  SHA256:
3
- metadata.gz: ba2c83d93364ab17b2ff50509b773fd06cf27874b154c812cfd205e24e01fe4a
4
- data.tar.gz: 9354135db5e40d55d8e9ff44c095a6d7bd6287b5d8b5989937deaffa59c62b65
3
+ metadata.gz: 28da8b8dda887c5405c1328498b1a2756fe5115cb0eaac7919e95c9582ce2678
4
+ data.tar.gz: 97b4ebe627681a7d71ab58ed9e7ac9cb9e6a82eb9d86811f4ec4a3c83c6ae5e5
5
5
  SHA512:
6
- metadata.gz: 15b9d19c2f41c2ff0c7397ff950c7addcacae961e0579a60db86f0238f3608885f0a55b2f3678b7dee94a6094ad5a809a4de286134c5efb90e0f33f3fea9c81c
7
- data.tar.gz: 866bf72082604e8743b58c8eba700ee66be98fba9dc36098b68103b018763b7779c0a44ff30e24968e9d655e1d755fbf06f900959cd37df58a07220bf8d7208c
6
+ metadata.gz: e040bfbb772dc2c2568e9556e48324cfcca839dbf8f1da17f4ce10c76cb55f7769f575ca2d5c679eb49171b4d3af89abdadd5783d1c1049112588d921f149537
7
+ data.tar.gz: a5fce726a73bd536ea44c1829372e5a3c8859b79818b6bba4ab57806d521dd22a1aa5dc805f714bf60558a2a476e7c870edf14d8a8802229a4549cb297786ca9
@@ -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.7.0] - 2018-11-25
9
+ ### Added
10
+ - metrics-mysql-select-count.rb script (@nagyt234)
11
+
8
12
  ## [2.6.0] - 2018-11-17
9
13
  ### Added
10
14
  - check-mysql-select-count.rb: fleshed out config hash to read from ini file if specified (@fuzzy-logic-zach)
@@ -137,7 +141,8 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
137
141
  ### Added
138
142
  - initial release
139
143
 
140
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.6.0...HEAD
144
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.7.0...HEAD
145
+ [2.7.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.6.0...2.7.0
141
146
  [2.6.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.5.1...2.6.0
142
147
  [2.5.1]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.5.0...2.5.1
143
148
  [2.5.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.4.0...2.5.0
data/README.md CHANGED
@@ -24,6 +24,7 @@
24
24
  * bin/metrics-mysql-raw.rb
25
25
  * bin/metrics-mysql.rb
26
26
  * bin/metrics-mysql-query-result-count.rb
27
+ * bin/metrics-mysql-select-count.rb
27
28
  * bin/mysql-metrics.sql
28
29
 
29
30
  ## Usage
@@ -98,6 +99,11 @@ $ /opt/sensu/embedded/bin/check-mysql-replication-status.rb --host=<SLAVE> --ini
98
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'
99
100
  ```
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
+
101
107
  ### Security
102
108
 
103
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.
@@ -117,6 +123,7 @@ In keeping with the principle of least privilege you should create a new user wi
117
123
  | metrics-mysql-graphite.rb | `SELECT` |
118
124
  | metrics-mysql-processes.rb | `SELECT` |
119
125
  | metrics-mysql-query-result-count.rb | depends on query |
126
+ | metrics-mysql-select-count.rb   | depends on query                                         |
120
127
  | metrics-mysql-raw.rb | `SELECT` |
121
128
  | metrics-mysql.rb | `INSERT` into `sensumetrics.sensu_historic_metrics` |
122
129
 
@@ -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
@@ -1,7 +1,7 @@
1
1
  module SensuPluginsMySql
2
2
  module Version
3
3
  MAJOR = 2
4
- MINOR = 6
4
+ MINOR = 7
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.6.0
4
+ version: 2.7.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-11-17 00:00:00.000000000 Z
11
+ date: 2018-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inifile
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.4'
61
+ version: '1.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.4'
68
+ version: '1.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '1.3'
89
+ version: '3.0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '1.3'
96
+ version: '3.0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: pry
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '10.0'
117
+ version: '12.3'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '10.0'
124
+ version: '12.3'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: redcarpet
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -200,6 +200,7 @@ executables:
200
200
  - check-mysql-query-result-count.rb
201
201
  - check-mysql-threads.rb
202
202
  - check-mysql-alive.rb
203
+ - metrics-mysql-select-count.rb
203
204
  - metrics-mysql-graphite.rb
204
205
  extensions: []
205
206
  extra_rdoc_files: []
@@ -221,6 +222,7 @@ files:
221
222
  - bin/metrics-mysql-processes.rb
222
223
  - bin/metrics-mysql-query-result-count.rb
223
224
  - bin/metrics-mysql-raw.rb
225
+ - bin/metrics-mysql-select-count.rb
224
226
  - bin/metrics-mysql.rb
225
227
  - bin/mysql-metrics.sql
226
228
  - lib/sensu-plugins-mysql.rb