sensu-plugins-mongodb 1.2.2 → 1.3.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: adbff6eb2e9cf5561f9934b9d1adb3113271c7fe
4
- data.tar.gz: 9a5736e402cfb088cb0b07bb03a72d810c3d0bac
3
+ metadata.gz: 66b2d5a053085a584cd966e891d11bbff8500999
4
+ data.tar.gz: 19ae5997b3440b58fe9b60f96b31faa50e9ba503
5
5
  SHA512:
6
- metadata.gz: f57055be8c51424806f80ba63bc784f0d2d5865cc182e22c8ab64767842cd59793cf798f2a53c80e715469b7e96e1330460eed2897619560287483e1f9058977
7
- data.tar.gz: 3cf34b90f91e2996c35bc975d2c3767c51c777da775896e168ffa72c9a8ff21ae4f5ad71dba7248d144e0be82d1326bb638dd700b1d3d6dafc8cec1e2ccfc1d9
6
+ metadata.gz: 34e01de3b9d4aa25022540fa4f6774d9e5a1a442323a7247f3c65de126512193210ed144268cf0c6d9c865ec1cd5e3a8176e9c2ae4f5c556120c61441489ee38
7
+ data.tar.gz: 945d1d2cfe04f5f842b1109560a28af11ef0411fbadde16d8aa67833f2cfac242d97a19414c14b83af1c4aaff19cf889cd9468ed1fce27f715cdda4b1c3270cd
data/CHANGELOG.md CHANGED
@@ -4,6 +4,12 @@ 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
+
8
+ ## [1.3.0]
9
+ ### Added
10
+ - Support for database size metrics (@naemono)
11
+ - Tests covering returning database size metrics (@naemono)
12
+
7
13
  ## [1.2.2]
8
14
  ### Fixed
9
15
  - `check-mongodb.py`: will now correctly crit on connection issues (@majormoses)
@@ -95,7 +101,8 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
95
101
  ### Added
96
102
  - initial release
97
103
 
98
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-mongodb/compare/1.2.1...HEAD
104
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-mongodb/compare/1.3.0...HEAD
105
+ [1.3.0]: https://github.com/sensu-plugins/sensu-plugins-mongodb/compare/1.2.1...1.3.0
99
106
  [1.2.1]: https://github.com/sensu-plugins/sensu-plugins-mongodb/compare/1.2.0...1.2.1
100
107
  [1.2.0]: https://github.com/sensu-plugins/sensu-plugins-mongodb/compare/1.1.0...1.2.0
101
108
  [1.1.0]: https://github.com/sensu-plugins/sensu-plugins-mongodb/compare/1.0.0...1.1.0
@@ -12,6 +12,7 @@ module SensuPluginsMongoDB
12
12
  @config = config
13
13
  @connected = false
14
14
  @db = nil
15
+ @mongo_client = nil
15
16
  end
16
17
 
17
18
  # Connects to a mongo database.
@@ -22,38 +23,16 @@ module SensuPluginsMongoDB
22
23
  raise 'Already connected to a database'
23
24
  end
24
25
 
25
- @connected = true
26
- host = @config[:host]
27
- port = @config[:port]
28
26
  db_user = @config[:user]
29
27
  db_password = @config[:password]
30
- ssl = @config[:ssl]
31
- ssl_cert = @config[:ssl_cert]
32
- ssl_key = @config[:ssl_key]
33
- ssl_ca_cert = @config[:ssl_ca_cert]
34
- ssl_verify = @config[:ssl_verify]
35
28
 
36
29
  if Gem.loaded_specs['mongo'].version < Gem::Version.new('2.0.0')
37
- mongo_client = MongoClient.new(host, port)
38
- @db = mongo_client.db(db_name)
30
+ @mongo_client = get_mongo_client(db_name)
31
+ @db = @mongo_client.db(db_name)
39
32
  @db.authenticate(db_user, db_password) unless db_user.nil?
40
33
  else
41
- address_str = "#{host}:#{port}"
42
- client_opts = {}
43
- client_opts[:database] = db_name
44
- unless db_user.nil?
45
- client_opts[:user] = db_user
46
- client_opts[:password] = db_password
47
- end
48
- if ssl
49
- client_opts[:ssl] = true
50
- client_opts[:ssl_cert] = ssl_cert
51
- client_opts[:ssl_key] = ssl_key
52
- client_opts[:ssl_ca_cert] = ssl_ca_cert
53
- client_opts[:ssl_verify] = ssl_verify
54
- end
55
- mongo_client = Mongo::Client.new([address_str], client_opts)
56
- @db = mongo_client.database
34
+ @mongo_client = get_mongo_client(db_name)
35
+ @db = @mongo_client.database
57
36
  end
58
37
  end
59
38
 
@@ -170,6 +149,25 @@ module SensuPluginsMongoDB
170
149
  end
171
150
  end
172
151
 
152
+ # Database Sizes
153
+ @mongo_client.database_names.each do |name|
154
+ @mongo_client.use(name)
155
+ db = @mongo_client.database
156
+ result = db.command(dbstats: 1).documents.first
157
+ server_metrics["databaseSizes.#{name}.collections"] = result['collections']
158
+ server_metrics["databaseSizes.#{name}.objects"] = result['objects']
159
+ server_metrics["databaseSizes.#{name}.avgObjSize"] = result['avgObjSize']
160
+ server_metrics["databaseSizes.#{name}.dataSize"] = result['dataSize']
161
+ server_metrics["databaseSizes.#{name}.storageSize"] = result['storageSize']
162
+ server_metrics["databaseSizes.#{name}.numExtents"] = result['numExtents']
163
+ server_metrics["databaseSizes.#{name}.indexes"] = result['indexes']
164
+ server_metrics["databaseSizes.#{name}.indexSize"] = result['indexSize']
165
+ server_metrics["databaseSizes.#{name}.fileSize"] = result['fileSize']
166
+ server_metrics["databaseSizes.#{name}.nsSizeMB"] = result['nsSizeMB']
167
+ end
168
+ # Reset back to previous database
169
+ @mongo_client.use(@db.name)
170
+
173
171
  # Journaling (durability)
174
172
  if server_status.key?('dur')
175
173
  dur = server_status['dur']
@@ -336,5 +334,40 @@ module SensuPluginsMongoDB
336
334
  end
337
335
  clean_metrics
338
336
  end
337
+
338
+ private
339
+
340
+ def get_mongo_client(db_name)
341
+ @connected = true
342
+ host = @config[:host]
343
+ port = @config[:port]
344
+ db_user = @config[:user]
345
+ db_password = @config[:password]
346
+ ssl = @config[:ssl]
347
+ ssl_cert = @config[:ssl_cert]
348
+ ssl_key = @config[:ssl_key]
349
+ ssl_ca_cert = @config[:ssl_ca_cert]
350
+ ssl_verify = @config[:ssl_verify]
351
+
352
+ if Gem.loaded_specs['mongo'].version < Gem::Version.new('2.0.0')
353
+ MongoClient.new(host, port)
354
+ else
355
+ address_str = "#{host}:#{port}"
356
+ client_opts = {}
357
+ client_opts[:database] = db_name
358
+ unless db_user.nil?
359
+ client_opts[:user] = db_user
360
+ client_opts[:password] = db_password
361
+ end
362
+ if ssl
363
+ client_opts[:ssl] = true
364
+ client_opts[:ssl_cert] = ssl_cert
365
+ client_opts[:ssl_key] = ssl_key
366
+ client_opts[:ssl_ca_cert] = ssl_ca_cert
367
+ client_opts[:ssl_verify] = ssl_verify
368
+ end
369
+ Mongo::Client.new([address_str], client_opts)
370
+ end
371
+ end
339
372
  end
340
373
  end
@@ -1,8 +1,8 @@
1
1
  module SensuPluginsMongoDB
2
2
  module Version
3
3
  MAJOR = 1
4
- MINOR = 2
5
- PATCH = 2
4
+ MINOR = 3
5
+ PATCH = 0
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-mongodb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.3.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-05-09 00:00:00.000000000 Z
11
+ date: 2017-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bson