bipbip 0.5.10 → 0.5.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cf1d48bb34bcf5158a9389079923fff2fe8eb55f
4
- data.tar.gz: d02e8c7f9b4edc8379995501390e366507e1a73e
3
+ metadata.gz: 33b1ceccac2deba94e787721658d11a82de9913a
4
+ data.tar.gz: 9b4aa869c258b1f00340b0dab419e17a74478031
5
5
  SHA512:
6
- metadata.gz: c108d106ff9a506aefbf4b39bcf0d0e90082360f5954b41dc835527c8e0e0bedd934dc3da1acd7dc05f1a42b44dd2de285e15444c01f82f2b884d3b2b688d4ef
7
- data.tar.gz: 20978afd5260bd4cd32b3ef33c7496ef2411e5b54a90c440e8e0b6e420dea52c238ab5c7baf09638af14fd57b8d9e03dc97850193ce2bea920a8274b0d2034ff
6
+ metadata.gz: e7f5cf7eb5052a331a3d3ac91f9abcd9e914dec37be8d97d81946e5ba79f8bd5f7ccee91c12b9d61575e355ba41d9fb34a973309f4243dd14a6c387edb5a6fcc
7
+ data.tar.gz: 3b52aa3e298b3a31d51c5783a46a5201c1825682f1aeca9dd4ae888c7d1164bcf6f05a5c39b42abb80c06aae8302a5193f43c594d840a3ea2c3e383df856f9f4
@@ -24,73 +24,100 @@ module Bipbip
24
24
  end
25
25
 
26
26
  def monitor
27
- mongoStats = server_status
27
+ @mongodb_client = nil
28
+
29
+ status = fetch_server_status
28
30
 
29
31
  data = {}
30
32
 
31
- if mongoStats['indexCounters']
32
- data['btree_misses'] = mongoStats['indexCounters']['misses'].to_i
33
+ if status['indexCounters']
34
+ data['btree_misses'] = status['indexCounters']['misses'].to_i
33
35
  end
34
- if mongoStats['backgroundFlushing']
35
- data['flushing_last_ms'] = mongoStats['backgroundFlushing']['last_ms'].to_i
36
+ if status['backgroundFlushing']
37
+ data['flushing_last_ms'] = status['backgroundFlushing']['last_ms'].to_i
36
38
  end
37
- if mongoStats['opcounters']
38
- data['op_inserts'] = mongoStats['opcounters']['insert'].to_i
39
- data['op_queries'] = mongoStats['opcounters']['query'].to_i
40
- data['op_updates'] = mongoStats['opcounters']['update'].to_i
41
- data['op_deletes'] = mongoStats['opcounters']['delete'].to_i
42
- data['op_getmores'] = mongoStats['opcounters']['getmore'].to_i
43
- data['op_commands'] = mongoStats['opcounters']['command'].to_i
39
+ if status['opcounters']
40
+ data['op_inserts'] = status['opcounters']['insert'].to_i
41
+ data['op_queries'] = status['opcounters']['query'].to_i
42
+ data['op_updates'] = status['opcounters']['update'].to_i
43
+ data['op_deletes'] = status['opcounters']['delete'].to_i
44
+ data['op_getmores'] = status['opcounters']['getmore'].to_i
45
+ data['op_commands'] = status['opcounters']['command'].to_i
44
46
  end
45
- if mongoStats['connections']
46
- data['connections_current'] = mongoStats['connections']['current'].to_i
47
+ if status['connections']
48
+ data['connections_current'] = status['connections']['current'].to_i
47
49
  end
48
- if mongoStats['mem']
49
- data['mem_resident'] = mongoStats['mem']['resident'].to_i
50
- data['mem_mapped'] = mongoStats['mem']['mapped'].to_i
50
+ if status['mem']
51
+ data['mem_resident'] = status['mem']['resident'].to_i
52
+ data['mem_mapped'] = status['mem']['mapped'].to_i
51
53
  end
52
- if mongoStats['extra_info']
53
- data['mem_pagefaults'] = mongoStats['extra_info']['page_faults'].to_i
54
+ if status['extra_info']
55
+ data['mem_pagefaults'] = status['extra_info']['page_faults'].to_i
54
56
  end
55
- if mongoStats['globalLock'] && mongoStats['globalLock']['currentQueue']
56
- data['globalLock_currentQueue'] = mongoStats['globalLock']['currentQueue']['total'].to_i
57
+ if status['globalLock'] && status['globalLock']['currentQueue']
58
+ data['globalLock_currentQueue'] = status['globalLock']['currentQueue']['total'].to_i
57
59
  end
58
- if mongoStats['repl'] && mongoStats['repl']['secondary'] == true
60
+ if status['repl'] && status['repl']['secondary'] == true
59
61
  data['replication_lag'] = replication_lag
60
62
  end
63
+
64
+ data['slow_queries_count'] = fetch_slow_queries_count
65
+
61
66
  data
62
67
  end
63
68
 
64
69
  private
65
70
 
66
- def admin_database
71
+ def slow_query_threshold
72
+ config['slow_query_threshold'] || 0
73
+ end
74
+
75
+ # @return [Mongo::MongoClient]
76
+ def mongodb_client
67
77
  options = {
68
78
  'hostname' => 'localhost',
69
79
  'port' => 27017,
70
- 'username' => nil,
71
- 'password' => nil
72
80
  }.merge(config)
73
- connection = Mongo::MongoClient.new(options['hostname'], options['port'], {:op_timeout => 2, :slave_ok => true})
74
- mongo = connection.db('admin')
75
- mongo.authenticate(options['username'], options['password']) unless options['password'].nil?
76
- mongo
81
+ @mongodb_client ||= Mongo::MongoClient.new(options['hostname'], options['port'], {:op_timeout => 2, :slave_ok => true})
82
+ end
83
+
84
+ # @return [Mongo::DB]
85
+ def mongodb_database(db_name)
86
+ db = mongodb_client.db(db_name)
87
+ db.authenticate(config['username'], config['password']) unless config['password'].nil?
88
+ db
89
+ end
90
+
91
+ def fetch_server_status
92
+ mongodb_database('admin').command('serverStatus' => 1)
77
93
  end
78
94
 
79
- def server_status
80
- admin_database.command('serverStatus' => 1)
95
+ def fetch_replica_status
96
+ mongodb_database('admin').command('replSetGetStatus' => 1)
81
97
  end
82
98
 
83
- def replica_status
84
- admin_database.command('replSetGetStatus' => 1)
99
+ def slow_query_last_check
100
+ old = (@slow_query_last_check || Time.now)
101
+ @slow_query_last_check = Time.now
102
+ old
103
+ end
104
+
105
+ def fetch_slow_queries_count
106
+ query = {'millis' => {'$gte' => slow_query_threshold}, 'ts' => {'$gte' => slow_query_last_check}}
107
+ database_names_ignore = ['admin', 'system']
108
+
109
+ database_list = (mongodb_client.database_names - database_names_ignore).map { |name| mongodb_database(name) }
110
+ database_list.reduce(0) { |memo, database| memo + database.collection('system.profile').count({:query => query}) }
85
111
  end
86
112
 
87
113
  def replication_lag
88
- member_list = replica_status['members']
114
+ status = fetch_replica_status
115
+ member_list = status['members']
89
116
  primary = member_list.select { |member| member['stateStr'] == 'PRIMARY' }.first
90
117
  secondary = member_list.select { |member| member['stateStr'] == 'SECONDARY' and member['self'] == true }.first
91
118
 
92
- raise "No primary member in replica `#{replica_status['set']}`" if primary.nil?
93
- raise "Cannot find itself as secondary member in replica `#{replica_status['set']}`" if secondary.nil?
119
+ raise "No primary member in replica `#{status['set']}`" if primary.nil?
120
+ raise "Cannot find itself as secondary member in replica `#{status['set']}`" if secondary.nil?
94
121
 
95
122
  (secondary['optime'].seconds - primary['optime'].seconds)
96
123
  end
@@ -1,3 +1,3 @@
1
1
  module Bipbip
2
- VERSION = '0.5.10'
2
+ VERSION = '0.5.11'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bipbip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.10
4
+ version: 0.5.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cargo Media
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-01-15 00:00:00.000000000 Z
13
+ date: 2015-01-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: copperegg
@@ -272,4 +272,3 @@ signing_key:
272
272
  specification_version: 4
273
273
  summary: Gather services data and store in CopperEgg
274
274
  test_files: []
275
- has_rdoc: