sensu-plugins-mysql 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +6 -0
- data/bin/metrics-mysql-query-result-count.rb +95 -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: 7b7608ea6a5cded48a747cf06209077fe26e9041
|
4
|
+
data.tar.gz: 9f7cdbab6faede729fe2d3784f55a9056a7e2bad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbfcc07febf6c3fd280f2ac82765162037d977bf153e68dce1711f3607157cd6ef5ee2dbca82b39a1e6ddc5d76d9bfbde7f7c1f47f0f8b0d596863426f89c4e1
|
7
|
+
data.tar.gz: 8e794b4cce853c315b3add749195e8fc6318f6403eae8a5bdc02420cfeac31ea2083d1ad52a12790dfcd7e21fcbe86a3085c4075a89310efac503eeb80e7f756
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
4
4
|
This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
|
5
5
|
|
6
6
|
## [Unreleased]
|
7
|
+
## [2.1.0] - 2017-06-10
|
8
|
+
### Added
|
9
|
+
- metrics-mysql-query-result-count.rb: Creates a graphite-formatted metric for the length of a result set from a MySQL query. (@athal7)
|
7
10
|
|
8
11
|
## [2.0.0] - 2017-06-05
|
9
12
|
### Breaking Change
|
@@ -68,7 +71,8 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
|
|
68
71
|
### Added
|
69
72
|
- initial release
|
70
73
|
|
71
|
-
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.
|
74
|
+
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.1.0...HEAD
|
75
|
+
[2.1.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.0.0...2.1.0
|
72
76
|
[2.0.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/1.2.1...2.0.0
|
73
77
|
[1.2.1]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/1.2.0...1.2.1
|
74
78
|
[1.2.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/1.1.0...1.2.0
|
data/README.md
CHANGED
@@ -21,6 +21,7 @@
|
|
21
21
|
* bin/metrics-mysql-processes.rb
|
22
22
|
* bin/metrics-mysql-raw.rb
|
23
23
|
* bin/metrics-mysql.rb
|
24
|
+
* bin/metrics-mysql-query-result-count.rb
|
24
25
|
* bin/mysql-metrics.sql
|
25
26
|
|
26
27
|
## Usage
|
@@ -51,6 +52,11 @@
|
|
51
52
|
/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
|
```
|
53
54
|
|
55
|
+
**metrics-mysql-query-result-count** example
|
56
|
+
```bash
|
57
|
+
/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'
|
58
|
+
```
|
59
|
+
|
54
60
|
## Installation
|
55
61
|
|
56
62
|
[Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
|
@@ -0,0 +1,95 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# MySQL Query Result Count Metric
|
4
|
+
#
|
5
|
+
# Creates a graphite-formatted metric for 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/metric/cli'
|
13
|
+
require 'mysql'
|
14
|
+
require 'inifile'
|
15
|
+
|
16
|
+
class MysqlQueryCountMetric < Sensu::Plugin::Metric::CLI::Graphite
|
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 :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 :socket,
|
53
|
+
short: '-S SOCKET',
|
54
|
+
long: '--socket SOCKET',
|
55
|
+
description: 'MySQL Unix socket to connect to'
|
56
|
+
|
57
|
+
option :name,
|
58
|
+
short: '-n NAME',
|
59
|
+
long: '--name NAME',
|
60
|
+
description: 'Metric name for a configured handler',
|
61
|
+
default: 'mysql.query_count'
|
62
|
+
|
63
|
+
option :query,
|
64
|
+
short: '-q QUERY',
|
65
|
+
long: '--query QUERY',
|
66
|
+
description: 'Query to execute',
|
67
|
+
required: true
|
68
|
+
|
69
|
+
def run
|
70
|
+
if config[:ini]
|
71
|
+
ini = IniFile.load(config[:ini])
|
72
|
+
section = ini['client']
|
73
|
+
db_user = section['user']
|
74
|
+
db_pass = section['password']
|
75
|
+
else
|
76
|
+
db_user = config[:username]
|
77
|
+
db_pass = config[:password]
|
78
|
+
end
|
79
|
+
db = Mysql.real_connect(config[:host], db_user, db_pass, config[:database], config[:port].to_i, config[:socket])
|
80
|
+
length = db.query(config[:query]).count
|
81
|
+
|
82
|
+
output config[:name], length
|
83
|
+
ok
|
84
|
+
|
85
|
+
rescue Mysql::Error => e
|
86
|
+
errstr = "Error code: #{e.errno} Error message: #{e.error}"
|
87
|
+
critical "#{errstr} SQLSTATE: #{e.sqlstate}" if e.respond_to?('sqlstate')
|
88
|
+
|
89
|
+
rescue => e
|
90
|
+
critical e
|
91
|
+
|
92
|
+
ensure
|
93
|
+
db.close if db
|
94
|
+
end
|
95
|
+
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: 2.
|
4
|
+
version: 2.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: 2017-06-
|
11
|
+
date: 2017-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: inifile
|
@@ -196,6 +196,7 @@ executables:
|
|
196
196
|
- check-mysql-threads.rb
|
197
197
|
- metrics-mysql-graphite.rb
|
198
198
|
- metrics-mysql-processes.rb
|
199
|
+
- metrics-mysql-query-result-count.rb
|
199
200
|
- metrics-mysql-raw.rb
|
200
201
|
- metrics-mysql.rb
|
201
202
|
extensions: []
|
@@ -214,6 +215,7 @@ files:
|
|
214
215
|
- bin/check-mysql-threads.rb
|
215
216
|
- bin/metrics-mysql-graphite.rb
|
216
217
|
- bin/metrics-mysql-processes.rb
|
218
|
+
- bin/metrics-mysql-query-result-count.rb
|
217
219
|
- bin/metrics-mysql-raw.rb
|
218
220
|
- bin/metrics-mysql.rb
|
219
221
|
- bin/mysql-metrics.sql
|