sensu-plugins-edgelab 1.1.0 → 1.2.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
  SHA1:
3
- metadata.gz: 82239604e6dd622edcfb47f6f612dcb825700e41
4
- data.tar.gz: 65f687f3ee8a645cb07d767e34f4446f94b02b0a
3
+ metadata.gz: c358dd509c8585dd35a4c530ce057cd76135cd13
4
+ data.tar.gz: 740b7ab958246515ec3be1657261503f4da5476f
5
5
  SHA512:
6
- metadata.gz: d1f693e3d1a564698ee290cbec139fdb74e0ca46ecf1994c1fbc6e9720832eb8b9aa73e02bcd8d0c11d0cb24dda03cc9ad7cad34cae18877655e976c075bbecd
7
- data.tar.gz: 3c486951f0a28fdc5dcf59abe8f1dd777a21d71b190c49f8098aa32510351a37d26cb2ce632d640ed2e2c50d37aaeed8355f4da8b0a37026cec8a013fcfb164b
6
+ metadata.gz: f86727fb262df9c9f3554d5d80fe9558856905be6063fbe24114bc6cdc257b738cacfa3d760fbffa4ce74b43faa543927bf16db840cfd5f33017d80b66253b93
7
+ data.tar.gz: 8c8dc2d06a6443c8e041592790b02e2182555f894a2d5b8b69588d06881efb3b8ff921cc049aa06a153565a918f68fc0871d09d1132072586225d1d041c194ef
@@ -1,4 +1,5 @@
1
1
  #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
  #
3
4
  # check-apt-expired-keys
4
5
  #
@@ -1,4 +1,5 @@
1
1
  #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  #
4
5
  # check-nomad-jobs
@@ -0,0 +1,60 @@
1
+ #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'docker-api'
5
+ require 'diplomat'
6
+ require 'sensu-plugin/check/cli'
7
+
8
+ class CheckDockerSwarmCluster < Sensu::Plugin::Check::CLI
9
+ option :consul_url,
10
+ short: '-c CONSUL_URL',
11
+ long: '--consul CONSUL_URL',
12
+ default: 'http://localhost:8500'
13
+
14
+ option :cert_path,
15
+ short: '-t CERT_PATH',
16
+ long: '--cert-path CERT_PATH',
17
+ default: '~/.docker'
18
+
19
+ option :tls_enabled,
20
+ short: '-t',
21
+ long: '--tls-enabled',
22
+ default: false
23
+
24
+ def run
25
+ Diplomat.configure do |consul|
26
+ consul.url = config[:consul_url]
27
+ end
28
+
29
+ begin
30
+ leader = Diplomat::Kv.get('docker/swarm/leader')
31
+ rescue => e
32
+ critical "Unable to query Consul on #{config[:consul_url]} for Swarm leader: #{e.inspect}"
33
+ end
34
+
35
+ if config[:tls_enabled]
36
+ scheme = 'https'
37
+ cert_path = File.expand_path(config[:cert_path])
38
+ Docker.options = {
39
+ client_cert: File.join(cert_path, 'cert.pem'),
40
+ client_key: File.join(cert_path, 'key.pem'),
41
+ ssl_ca_file: File.join(cert_path, 'ca.pem'),
42
+ scheme: scheme
43
+ }
44
+ else
45
+ scheme = 'http'
46
+ Docker.options = {
47
+ scheme: scheme
48
+ }
49
+ end
50
+
51
+ Docker.url = "#{scheme}://#{leader}"
52
+
53
+ begin
54
+ count = Docker::Container.all(running: true).size.to_i
55
+ ok "Swarm running with #{count} containers (leader: #{leader})"
56
+ rescue => e
57
+ critical "Swarm error: #{e.inspect} (leader: #{leader})"
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,133 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # metrics-mysql-processes
5
+ #
6
+ # DESCRIPTION:
7
+ # Gets metrics out of of MySQL's "SHOW PROCESSLIST" query.
8
+ #
9
+ # Output number of connections per-users, number of connections
10
+ # per-databases, number of the different commands running.
11
+ #
12
+ # OUTPUT:
13
+ # metric-data
14
+ #
15
+ # PLATFORMS:
16
+ # Linux, Windows, BSD, Solaris, etc
17
+ #
18
+ # DEPENDENCIES:
19
+ # gem: sensu-plugin
20
+ # gem: mysql
21
+ #
22
+ # USAGE:
23
+ # This was implemented to load mysql credentials without parsing the username/password.
24
+ # The ini file should be readable by the sensu user/group.
25
+ # Ref: http://eric.lubow.org/2009/ruby/parsing-ini-files-with-ruby/
26
+ #
27
+ # EXAMPLE
28
+ # mysql-alive.rb -h db01 --ini '/etc/sensu/my.cnf'
29
+ #
30
+ # MY.CNF INI FORMAT
31
+ # [client]
32
+ # user=sensu
33
+ # password="abcd1234"
34
+ #
35
+ # NOTES:
36
+ #
37
+ # LICENSE:
38
+ # Jonathan Ballet <jballet@edgelab.ch>
39
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
40
+ # for details.
41
+
42
+ require 'sensu-plugin/metric/cli'
43
+ require 'mysql'
44
+ require 'socket'
45
+ require 'inifile'
46
+
47
+ class MetricsMySQLProcesses < Sensu::Plugin::Metric::CLI::Graphite
48
+ option :host,
49
+ short: '-h HOST',
50
+ long: '--host HOST',
51
+ description: 'MySQL Host to connect to',
52
+ required: true
53
+
54
+ option :port,
55
+ short: '-P PORT',
56
+ long: '--port PORT',
57
+ description: 'MySQL Port to connect to',
58
+ proc: proc(&:to_i),
59
+ default: 3306
60
+
61
+ option :username,
62
+ short: '-u USERNAME',
63
+ long: '--user USERNAME',
64
+ description: 'MySQL Username'
65
+
66
+ option :password,
67
+ short: '-p PASSWORD',
68
+ long: '--pass PASSWORD',
69
+ description: 'MySQL password',
70
+ default: ''
71
+
72
+ option :ini,
73
+ short: '-i',
74
+ long: '--ini VALUE',
75
+ description: 'My.cnf ini file'
76
+
77
+ option :scheme,
78
+ description: 'Metric naming scheme, text to prepend to metric',
79
+ short: '-s SCHEME',
80
+ long: '--scheme SCHEME',
81
+ default: "#{Socket.gethostname}.mysql"
82
+
83
+ option :socket,
84
+ short: '-S SOCKET',
85
+ long: '--socket SOCKET',
86
+ description: 'MySQL Unix socket to connect to'
87
+
88
+ def run
89
+ config[:host].split(' ').each do |mysql_host|
90
+ mysql_shorthostname = mysql_host.split('.')[0]
91
+ if config[:ini]
92
+ ini = IniFile.load(config[:ini])
93
+ section = ini['client']
94
+ db_user = section['user']
95
+ db_pass = section['password']
96
+ else
97
+ db_user = config[:username]
98
+ db_pass = config[:password]
99
+ end
100
+ begin
101
+ mysql = Mysql.new(mysql_host, db_user, db_pass, nil, config[:port], config[:socket])
102
+
103
+ results = mysql.query('SHOW PROCESSLIST')
104
+ rescue => e
105
+ unknown "Unable to query MySQL: #{e.message}"
106
+ end
107
+
108
+ metrics = {
109
+ 'user' => {},
110
+ 'database' => {},
111
+ 'command' => {}
112
+ }
113
+
114
+ metrics.each_value { |value| value.default = 0 }
115
+
116
+ results.each_hash do |row|
117
+ metrics['user'][row['User']] += 1
118
+ if row['db'] # If no database has been selected by the process, it is set to nil.
119
+ metrics['database'][row['db']] += 1
120
+ end
121
+ metrics['command'][row['Command']] += 1
122
+ end
123
+
124
+ metrics.each do |key, value|
125
+ value.each do |instance, count|
126
+ output "#{config[:scheme]}.#{mysql_shorthostname}.#{key}.#{instance}", count
127
+ end
128
+ end
129
+ end
130
+
131
+ ok
132
+ end
133
+ end
@@ -0,0 +1,102 @@
1
+ #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'docker-api'
5
+ require 'diplomat'
6
+ require 'sensu-plugin/metric/cli'
7
+
8
+ class DockerContainerMetrics < Sensu::Plugin::Metric::CLI::Graphite
9
+ option :scheme,
10
+ description: 'Metric naming scheme, text to prepend to metric',
11
+ short: '-s SCHEME',
12
+ long: '--scheme SCHEME',
13
+ default: 'swarm'
14
+
15
+ option :consul_url,
16
+ short: '-c CONSUL_URL',
17
+ long: '--consul CONSUL_URL',
18
+ default: 'http://localhost:8500'
19
+
20
+ option :cert_path,
21
+ short: '-t CERT_PATH',
22
+ long: '--cert-path CERT_PATH',
23
+ default: '~/.docker'
24
+
25
+ option :tls_enabled,
26
+ short: '-t',
27
+ long: '--tls-enabled',
28
+ default: false
29
+
30
+ def run
31
+ swarm_metrics
32
+ ok
33
+ end
34
+
35
+ def swarm_metrics
36
+ Diplomat.configure do |consul|
37
+ consul.url = config[:consul_url]
38
+ end
39
+
40
+ begin
41
+ leader = Diplomat::Kv.get('docker/swarm/leader')
42
+ rescue => e
43
+ critical "Unable to query Consul on #{config[:consul_url]} for Swarm leader: #{e.inspect}"
44
+ end
45
+
46
+ if config[:tls_enabled]
47
+ scheme = 'https'
48
+ cert_path = File.expand_path(config[:cert_path])
49
+ Docker.options = {
50
+ client_cert: File.join(cert_path, 'cert.pem'),
51
+ client_key: File.join(cert_path, 'key.pem'),
52
+ ssl_ca_file: File.join(cert_path, 'ca.pem'),
53
+ scheme: scheme
54
+ }
55
+ else
56
+ scheme = 'http'
57
+ Docker.options = {
58
+ scheme: scheme
59
+ }
60
+ end
61
+
62
+ Docker.url = "#{scheme}://#{leader}"
63
+
64
+ timestamp = Time.now.to_i
65
+
66
+ infos = Docker.info
67
+
68
+ prefix = config[:scheme]
69
+
70
+ output "#{prefix}.containers.running", infos['ContainersRunning'], timestamp
71
+ output "#{prefix}.containers.paused", infos['ContainersPaused'], timestamp
72
+ output "#{prefix}.containers.stopped", infos['ContainersStopped'], timestamp
73
+
74
+ output "#{prefix}.images", infos['Images'], timestamp
75
+
76
+ output "#{prefix}.size.cpus", infos['NCPU'], timestamp
77
+ output "#{prefix}.size.memory", infos['MemTotal'], timestamp
78
+
79
+ nodes = {
80
+ 'healthy': 0,
81
+ 'pending': 0,
82
+ 'unhealthy': 0
83
+ }
84
+ infos['DriverStatus'].each do |info|
85
+ key, value = info
86
+
87
+ if key.end_with?(' Status')
88
+ status = value.downcase
89
+
90
+ # Just in case there are other statuses...
91
+ unless nodes.key?(status)
92
+ nodes[status] = 0
93
+ end
94
+ nodes[status] += 1
95
+ end
96
+ end
97
+
98
+ nodes.each do |status, count|
99
+ output "#{prefix}.nodes.status.#{status}", count, timestamp
100
+ end
101
+ end
102
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-edgelab
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edgelab
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-11 00:00:00.000000000 Z
11
+ date: 2017-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-plugin
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: inifile
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 3.0.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rest-client
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +52,20 @@ dependencies:
38
52
  - - '='
39
53
  - !ruby/object:Gem::Version
40
54
  version: 1.8.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: ruby-mysql
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.9'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.9'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: bundler
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -83,13 +111,19 @@ dependencies:
83
111
  description: Sensu plugins developed by Edgelab
84
112
  email:
85
113
  executables:
114
+ - metrics-swarm-cluster.rb
86
115
  - check-apt-expired-keys.rb
87
116
  - check-nomad-jobs.rb
117
+ - check-swarm-cluster.rb
118
+ - metrics-mysql-processes.rb
88
119
  extensions: []
89
120
  extra_rdoc_files: []
90
121
  files:
91
122
  - bin/check-apt-expired-keys.rb
92
123
  - bin/check-nomad-jobs.rb
124
+ - bin/check-swarm-cluster.rb
125
+ - bin/metrics-mysql-processes.rb
126
+ - bin/metrics-swarm-cluster.rb
93
127
  homepage:
94
128
  licenses: []
95
129
  metadata: {}