sensu-plugins-mongodb 0.0.1.alpha.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,125 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # metrics-mongodb.rb
4
+ #
5
+ # DESCRIPTION:
6
+ #
7
+ # OUTPUT:
8
+ # metric data
9
+ #
10
+ # PLATFORMS:
11
+ # Linux
12
+ #
13
+ # DEPENDENCIES:
14
+ # gem: sensu-plugin
15
+ # gem: mongo
16
+ #
17
+ # USAGE:
18
+ # #YELLOW
19
+ #
20
+ # NOTES:
21
+ # Basics from github.com/mantree/mongodb-graphite-metrics
22
+ #
23
+ # LICENSE:
24
+ # Copyright 2013 github.com/foomatty
25
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
26
+ # for details.
27
+ #
28
+
29
+ require 'sensu-plugin/metric/cli'
30
+ require 'mongo'
31
+ include Mongo
32
+
33
+ #
34
+ # Mongodb
35
+ #
36
+ class MongoDB < Sensu::Plugin::Metric::CLI::Graphite
37
+ option :host,
38
+ description: 'MongoDB host',
39
+ long: '--host HOST',
40
+ default: 'localhost'
41
+
42
+ option :port,
43
+ description: 'MongoDB port',
44
+ long: '--port PORT',
45
+ default: 27_017
46
+
47
+ option :user,
48
+ description: 'MongoDB user',
49
+ long: '--user USER',
50
+ default: nil
51
+
52
+ option :password,
53
+ description: 'MongoDB password',
54
+ long: '--password PASSWORD',
55
+ default: nil
56
+
57
+ option :scheme,
58
+ description: 'Metric naming scheme',
59
+ long: '--scheme SCHEME',
60
+ short: '-s SCHEME',
61
+ default: "#{Socket.gethostname}.mongodb"
62
+
63
+ def run # rubocop:disable all
64
+ host = config[:host]
65
+ port = config[:port]
66
+ db_name = 'admin'
67
+ db_user = config[:user]
68
+ db_password = config[:password]
69
+
70
+ mongo_client = MongoClient.new(host, port)
71
+ @db = mongo_client.db(db_name)
72
+ @db.authenticate(db_user, db_password) unless db_user.nil?
73
+
74
+ @is_master = { 'isMaster' => 1 }
75
+ begin
76
+ metrics = {}
77
+ _result = @db.command(@is_master)['ok'] == 1
78
+ server_status = @db.command('serverStatus' => 1)
79
+ if server_status['ok'] == 1
80
+ metrics.update(gather_replication_metrics(server_status))
81
+ timestamp = Time.now.to_i
82
+ metrics.each do |k, v|
83
+ output [config[:scheme], k].join('.'), v, timestamp
84
+ end
85
+ end
86
+ ok
87
+ rescue
88
+ exit(1)
89
+ end
90
+ end
91
+
92
+ def gather_replication_metrics(server_status) # rubocop:disable all
93
+ server_metrics = {}
94
+ server_metrics['lock.ratio'] = "#{sprintf('%.5f', server_status['globalLock']['ratio'])}" unless server_status['globalLock']['ratio'].nil? # rubocop:disable all
95
+
96
+ server_metrics['lock.queue.total'] = server_status['globalLock']['currentQueue']['total']
97
+ server_metrics['lock.queue.readers'] = server_status['globalLock']['currentQueue']['readers']
98
+ server_metrics['lock.queue.writers'] = server_status['globalLock']['currentQueue']['writers']
99
+
100
+ server_metrics['connections.current'] = server_status['connections']['current']
101
+ server_metrics['connections.available'] = server_status['connections']['available']
102
+
103
+ if server_status['indexCounters']['btree'].nil?
104
+ server_metrics['indexes.missRatio'] = "#{sprintf('%.5f', server_status['indexCounters']['missRatio'])}" # rubocop:disable all
105
+ server_metrics['indexes.hits'] = server_status['indexCounters']['hits']
106
+ server_metrics['indexes.misses'] = server_status['indexCounters']['misses']
107
+ else
108
+ server_metrics['indexes.missRatio'] = "#{sprintf('%.5f', server_status['indexCounters']['btree']['missRatio'])}" # rubocop:disable all
109
+ server_metrics['indexes.hits'] = server_status['indexCounters']['btree']['hits']
110
+ server_metrics['indexes.misses'] = server_status['indexCounters']['btree']['misses']
111
+ end
112
+
113
+ server_metrics['cursors.open'] = server_status['cursors']['totalOpen']
114
+ server_metrics['cursors.timedOut'] = server_status['cursors']['timedOut']
115
+
116
+ server_metrics['mem.residentMb'] = server_status['mem']['resident']
117
+ server_metrics['mem.virtualMb'] = server_status['mem']['virtual']
118
+ server_metrics['mem.mapped'] = server_status['mem']['mapped']
119
+ server_metrics['mem.pageFaults'] = server_status['extra_info']['page_faults']
120
+
121
+ server_metrics['asserts.warnings'] = server_status['asserts']['warning']
122
+ server_metrics['asserts.errors'] = server_status['asserts']['msg']
123
+ server_metrics
124
+ end
125
+ end
@@ -0,0 +1,15 @@
1
+
2
+ require 'sensu-plugins-mongodb/version'
3
+
4
+ # Load the defaults
5
+
6
+ #
7
+ # Default class
8
+ #
9
+ module SensuPluginsMongoDB
10
+ class << self
11
+ end
12
+
13
+ class << self
14
+ end
15
+ end
@@ -0,0 +1,28 @@
1
+ require 'json'
2
+
3
+ # encoding: utf-8
4
+ module SensuPluginsMongoDB
5
+ # This defines the version of the gem
6
+ module Version
7
+ MAJOR = 0
8
+ MINOR = 0
9
+ PATCH = 1
10
+
11
+ VER_STRING = [MAJOR, MINOR, PATCH, 'alpha.2'].compact.join('.')
12
+
13
+ NAME = 'sensu-plugins-mongodb'
14
+ BANNER = "#{NAME} v%s"
15
+
16
+ module_function
17
+
18
+ def version
19
+ format(BANNER, VER_STRING)
20
+ end
21
+
22
+ def json_version
23
+ {
24
+ 'version' => VER_STRING
25
+ }.to_json
26
+ end
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,230 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sensu-plugins-mongodb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.alpha.2
5
+ platform: ruby
6
+ authors:
7
+ - Yieldbot, Inc. and contributors
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDgDCCAmigAwIBAgIBATANBgkqhkiG9w0BAQUFADBDMRIwEAYDVQQDDAltYXR0
14
+ am9uZXMxGDAWBgoJkiaJk/IsZAEZFgh5aWVsZGJvdDETMBEGCgmSJomT8ixkARkW
15
+ A2NvbTAeFw0xNTAxMjgyMTAyNTFaFw0xNjAxMjgyMTAyNTFaMEMxEjAQBgNVBAMM
16
+ CW1hdHRqb25lczEYMBYGCgmSJomT8ixkARkWCHlpZWxkYm90MRM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:00.000000000 Z
34
+ dependencies:
35
+ - !ruby/object:Gem::Dependency
36
+ name: sensu-plugin
37
+ requirement: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '='
40
+ - !ruby/object:Gem::Version
41
+ version: 1.1.0
42
+ type: :runtime
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '='
47
+ - !ruby/object:Gem::Version
48
+ version: 1.1.0
49
+ - !ruby/object:Gem::Dependency
50
+ name: mongo
51
+ requirement: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '='
54
+ - !ruby/object:Gem::Version
55
+ version: 2.0.2
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '='
61
+ - !ruby/object:Gem::Version
62
+ version: 2.0.2
63
+ - !ruby/object:Gem::Dependency
64
+ name: codeclimate-test-reporter
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '0.4'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '0.4'
77
+ - !ruby/object:Gem::Dependency
78
+ name: rubocop
79
+ requirement: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '='
82
+ - !ruby/object:Gem::Version
83
+ version: 0.17.0
84
+ type: :development
85
+ prerelease: false
86
+ version_requirements: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '='
89
+ - !ruby/object:Gem::Version
90
+ version: 0.17.0
91
+ - !ruby/object:Gem::Dependency
92
+ name: rspec
93
+ requirement: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '3.1'
98
+ type: :development
99
+ prerelease: false
100
+ version_requirements: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '3.1'
105
+ - !ruby/object:Gem::Dependency
106
+ name: bundler
107
+ requirement: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '1.7'
112
+ type: :development
113
+ prerelease: false
114
+ version_requirements: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '1.7'
119
+ - !ruby/object:Gem::Dependency
120
+ name: rake
121
+ requirement: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '10.0'
126
+ type: :development
127
+ prerelease: false
128
+ version_requirements: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: '10.0'
133
+ - !ruby/object:Gem::Dependency
134
+ name: github-markup
135
+ requirement: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '1.3'
140
+ type: :development
141
+ prerelease: false
142
+ version_requirements: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - "~>"
145
+ - !ruby/object:Gem::Version
146
+ version: '1.3'
147
+ - !ruby/object:Gem::Dependency
148
+ name: redcarpet
149
+ requirement: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - "~>"
152
+ - !ruby/object:Gem::Version
153
+ version: '3.2'
154
+ type: :development
155
+ prerelease: false
156
+ version_requirements: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - "~>"
159
+ - !ruby/object:Gem::Version
160
+ version: '3.2'
161
+ - !ruby/object:Gem::Dependency
162
+ name: yard
163
+ requirement: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - "~>"
166
+ - !ruby/object:Gem::Version
167
+ version: '0.8'
168
+ type: :development
169
+ prerelease: false
170
+ version_requirements: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - "~>"
173
+ - !ruby/object:Gem::Version
174
+ version: '0.8'
175
+ - !ruby/object:Gem::Dependency
176
+ name: pry
177
+ requirement: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - "~>"
180
+ - !ruby/object:Gem::Version
181
+ version: '0.10'
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - "~>"
187
+ - !ruby/object:Gem::Version
188
+ version: '0.10'
189
+ description: Sensu plugins for mongodb
190
+ email: "<sensu-users@googlegroups.com>"
191
+ executables: []
192
+ extensions: []
193
+ extra_rdoc_files: []
194
+ files:
195
+ - CHANGELOG.md
196
+ - LICENSE
197
+ - README.md
198
+ - bin/check-mongodb.py
199
+ - bin/metrics-mongodb.rb
200
+ - lib/sensu-plugins-mongodb.rb
201
+ - lib/sensu-plugins-mongodb/version.rb
202
+ homepage: https://github.com/sensu-plugins/sensu-plugins-mongodb
203
+ licenses:
204
+ - MIT
205
+ metadata:
206
+ maintainer: ''
207
+ development_status: active
208
+ production_status: unstable - testing recommended
209
+ post_install_message:
210
+ rdoc_options: []
211
+ require_paths:
212
+ - lib
213
+ required_ruby_version: !ruby/object:Gem::Requirement
214
+ requirements:
215
+ - - ">="
216
+ - !ruby/object:Gem::Version
217
+ version: 1.9.3
218
+ required_rubygems_version: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">"
221
+ - !ruby/object:Gem::Version
222
+ version: 1.3.1
223
+ requirements: []
224
+ rubyforge_project:
225
+ rubygems_version: 2.2.2
226
+ signing_key:
227
+ specification_version: 4
228
+ summary: Sensu plugins for mongodb
229
+ test_files: []
230
+ has_rdoc:
metadata.gz.sig ADDED
Binary file