bipbip 0.5.10 → 0.5.11
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 +4 -4
- data/lib/bipbip/plugin/mongodb.rb +63 -36
- data/lib/bipbip/version.rb +1 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33b1ceccac2deba94e787721658d11a82de9913a
|
4
|
+
data.tar.gz: 9b4aa869c258b1f00340b0dab419e17a74478031
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
27
|
+
@mongodb_client = nil
|
28
|
+
|
29
|
+
status = fetch_server_status
|
28
30
|
|
29
31
|
data = {}
|
30
32
|
|
31
|
-
if
|
32
|
-
data['btree_misses'] =
|
33
|
+
if status['indexCounters']
|
34
|
+
data['btree_misses'] = status['indexCounters']['misses'].to_i
|
33
35
|
end
|
34
|
-
if
|
35
|
-
data['flushing_last_ms'] =
|
36
|
+
if status['backgroundFlushing']
|
37
|
+
data['flushing_last_ms'] = status['backgroundFlushing']['last_ms'].to_i
|
36
38
|
end
|
37
|
-
if
|
38
|
-
data['op_inserts'] =
|
39
|
-
data['op_queries'] =
|
40
|
-
data['op_updates'] =
|
41
|
-
data['op_deletes'] =
|
42
|
-
data['op_getmores'] =
|
43
|
-
data['op_commands'] =
|
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
|
46
|
-
data['connections_current'] =
|
47
|
+
if status['connections']
|
48
|
+
data['connections_current'] = status['connections']['current'].to_i
|
47
49
|
end
|
48
|
-
if
|
49
|
-
data['mem_resident'] =
|
50
|
-
data['mem_mapped'] =
|
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
|
53
|
-
data['mem_pagefaults'] =
|
54
|
+
if status['extra_info']
|
55
|
+
data['mem_pagefaults'] = status['extra_info']['page_faults'].to_i
|
54
56
|
end
|
55
|
-
if
|
56
|
-
data['globalLock_currentQueue'] =
|
57
|
+
if status['globalLock'] && status['globalLock']['currentQueue']
|
58
|
+
data['globalLock_currentQueue'] = status['globalLock']['currentQueue']['total'].to_i
|
57
59
|
end
|
58
|
-
if
|
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
|
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
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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
|
80
|
-
|
95
|
+
def fetch_replica_status
|
96
|
+
mongodb_database('admin').command('replSetGetStatus' => 1)
|
81
97
|
end
|
82
98
|
|
83
|
-
def
|
84
|
-
|
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
|
-
|
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 `#{
|
93
|
-
raise "Cannot find itself as secondary member in replica `#{
|
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
|
data/lib/bipbip/version.rb
CHANGED
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.
|
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-
|
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:
|