bipbip 0.5.14 → 0.5.15

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: 297ab31c33a70036e4877f4b5b44d47acdbc9a32
4
- data.tar.gz: f48f374bb3cd80e87ab5ece81c99ced7b7c2211a
3
+ metadata.gz: ddfc3ddd44eded3569a8967a2ee2afbab46d874a
4
+ data.tar.gz: 97bc00b753c876da95ab4f1c0ebe4516a3409c4d
5
5
  SHA512:
6
- metadata.gz: 4acccd584041353c38d5e234836474d9fcc44b218b2582fc06ee0d5b6ade33d0f78cf11a14a67e1470988ad4fcbdd18b211f3f0f561a12bf04a0300b8e8560b0
7
- data.tar.gz: e971c88b6ab120a8f20be1d44759f71b1fab52c4f039a14bc315891e24a82b674fa42f5ae339a1a2b52bd823e6ac0e5d1c741d1bad0cda1258a81e7895c84030
6
+ metadata.gz: 35561804f688ee6fb08154151c28b00c28e14b8885a0751c46909bcac5da4e5cfa9c7c79be1b9079dff8e214088cf92aed4e3b3db28cac37d65ebffd25c7a593
7
+ data.tar.gz: c25eb8bb521915d0a4afb6394b4bb75fe554d8b067263f95e322b62862111a8527d15ee8630a50c77d00fb05167c0f9fa9eec3ef808aa701ae4bd349c27245e8
@@ -20,7 +20,8 @@ module Bipbip
20
20
  {:name => 'mem_pagefaults', :type => 'counter', :unit => 'faults'},
21
21
  {:name => 'globalLock_currentQueue', :type => 'gauge'},
22
22
  {:name => 'replication_lag', :type => 'gauge', :unit => 'Seconds'},
23
- {:name => 'slow_queries', :type => 'gauge', :unit => 'Queries'},
23
+ {:name => 'slow_queries_count', :type => 'gauge', :unit => 'Queries'},
24
+ {:name => 'slow_queries_time_avg', :type => 'gauge', :unit => 'Seconds'},
24
25
  ]
25
26
  end
26
27
 
@@ -28,6 +29,7 @@ module Bipbip
28
29
  @mongodb_client = nil
29
30
 
30
31
  status = fetch_server_status
32
+ slow_queries_status = fetch_slow_queries_status
31
33
 
32
34
  data = {}
33
35
 
@@ -62,7 +64,8 @@ module Bipbip
62
64
  data['replication_lag'] = replication_lag
63
65
  end
64
66
 
65
- data['slow_queries'] = calculate_slow_queries
67
+ data['slow_queries_count'] = slow_queries_status['total_count']
68
+ data['slow_queries_time_avg'] = slow_queries_status['total_count'] > 0 ? (slow_queries_status['total_time'].to_f/slow_queries_status['total_count'].to_f) : 0
66
69
 
67
70
  data
68
71
  end
@@ -103,20 +106,31 @@ module Bipbip
103
106
  old
104
107
  end
105
108
 
106
- def calculate_slow_queries
109
+ def fetch_slow_queries_status
107
110
  timestamp_last_check = slow_query_last_check
111
+ time_period = Time.now - timestamp_last_check
108
112
 
109
- slow_queries = fetch_slow_queries_count(slow_query_threshold, timestamp_last_check)
113
+ database_names_ignore = ['admin', 'system']
114
+ database_list = (mongodb_client.database_names - database_names_ignore).map { |name| mongodb_database(name) }
110
115
 
111
- (slow_queries/(Time.now - timestamp_last_check)).to_i
112
- end
116
+ stats = database_list.reduce({'total_count' => 0, 'total_time' => 0}) do |memo, database|
113
117
 
114
- def fetch_slow_queries_count(millis_min, ts_min)
115
- query = {'millis' => {'$gte' => millis_min}, 'ts' => {'$gte' => ts_min}}
116
- database_names_ignore = ['admin', 'system']
118
+ results = database.collection('system.profile').aggregate(
119
+ [
120
+ {'$match' => {'millis' => {'$gte' => slow_query_threshold}, 'ts' => {'$gt' => timestamp_last_check}}},
121
+ {'$group' => {'_id' => 'null', 'total_count' => {'$sum' => 1}, 'total_time' => {'$sum' => '$millis'}}}
122
+ ])
117
123
 
118
- database_list = (mongodb_client.database_names - database_names_ignore).map { |name| mongodb_database(name) }
119
- database_list.reduce(0) { |memo, database| memo + database.collection('system.profile').count({:query => query}) }
124
+ unless results.empty?
125
+ result = results.pop
126
+ memo['total_count'] += result['total_count']
127
+ memo['total_time'] += result['total_time'].to_f/1000
128
+ end
129
+
130
+ memo
131
+ end
132
+
133
+ stats.each { |metric, value| stats[metric] = value/time_period }
120
134
  end
121
135
 
122
136
  def replication_lag
@@ -1,3 +1,3 @@
1
1
  module Bipbip
2
- VERSION = '0.5.14'
2
+ VERSION = '0.5.15'
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.14
4
+ version: 0.5.15
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-21 00:00:00.000000000 Z
13
+ date: 2015-01-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: copperegg