mongodb-graphite-agent 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -1
- data/LICENSE.txt +22 -22
- data/Rakefile +6 -6
- data/lib/mongodb/graphite/agent.rb +4 -0
- data/lib/mongodb/graphite/agent/collection_size_calculator.rb +28 -0
- data/lib/mongodb/graphite/agent/version.rb +1 -1
- data/spec/collection_size_calculator_spec.rb +10 -0
- metadata +5 -2
data/.gitignore
CHANGED
data/LICENSE.txt
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
Copyright (c) 2013 Michele Cantelli
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
|
+
Copyright (c) 2013 Michele Cantelli
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
require 'rspec/core/rake_task'
|
3
|
-
|
4
|
-
RSpec::Core::RakeTask.new('spec')
|
5
|
-
|
6
|
-
# If you want to make this the default task
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
RSpec::Core::RakeTask.new('spec')
|
5
|
+
|
6
|
+
# If you want to make this the default task
|
7
7
|
task :default => :spec
|
@@ -9,6 +9,7 @@ require 'time_difference'
|
|
9
9
|
require 'mongodb/graphite/agent/utils'
|
10
10
|
require 'mongodb/graphite/agent/op_counters_sample'
|
11
11
|
require 'mongodb/graphite/agent/mongo_cient_extensions'
|
12
|
+
require 'mongodb/graphite/agent/collection_size_calculator'
|
12
13
|
|
13
14
|
module Mongodb
|
14
15
|
module Graphite
|
@@ -31,11 +32,13 @@ module Mongodb
|
|
31
32
|
}
|
32
33
|
|
33
34
|
opcounters_per_second_metric_hash = calculate_opcounters_per_second server_status_result["opcounters"]
|
35
|
+
total_collections_hash = CollectionSizeCalculator.new(connection).calculate
|
34
36
|
|
35
37
|
if @opts[:verbose]
|
36
38
|
puts "Calculating metrics..."
|
37
39
|
ap metric_hash
|
38
40
|
ap opcounters_per_second_metric_hash
|
41
|
+
ap total_collections_hash
|
39
42
|
end
|
40
43
|
|
41
44
|
|
@@ -46,6 +49,7 @@ module Mongodb
|
|
46
49
|
:metrics_prefix => @opts[:graphite_metrics_prefix]})
|
47
50
|
graphite_writer.write(metric_hash)
|
48
51
|
graphite_writer.write(opcounters_per_second_metric_hash)
|
52
|
+
graphite_writer.write(total_collections_hash)
|
49
53
|
end
|
50
54
|
end
|
51
55
|
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'awesome_print'
|
2
|
+
|
3
|
+
module Mongodb
|
4
|
+
module Graphite
|
5
|
+
module Agent
|
6
|
+
class CollectionSizeCalculator
|
7
|
+
|
8
|
+
def initialize(mongo_client)
|
9
|
+
@mongo_client = mongo_client
|
10
|
+
end
|
11
|
+
|
12
|
+
def calculate
|
13
|
+
collection_count_hash = {}
|
14
|
+
@mongo_client.database_names.each { |db_name|
|
15
|
+
@mongo_client[db_name].collection_names.each { |collection_name|
|
16
|
+
|
17
|
+
|
18
|
+
collection_count_hash["collection_sizes.#{db_name}.#{collection_name}"] = @mongo_client[db_name][collection_name].stats()["count"]
|
19
|
+
} unless db_name == 'local'
|
20
|
+
}
|
21
|
+
|
22
|
+
return collection_count_hash
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'mongodb/graphite/agent/collection_size_calculator'
|
3
|
+
require 'mongo'
|
4
|
+
|
5
|
+
describe 'Collection size calculator' do
|
6
|
+
it 'should calculate the number of documents in all db collections' do
|
7
|
+
collection_size_calculator = Mongodb::Graphite::Agent::CollectionSizeCalculator.new(Mongo::MongoClient.new())
|
8
|
+
collection_size_calculator.calculate.should have_at_least(1).items
|
9
|
+
end
|
10
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongodb-graphite-agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -187,6 +187,7 @@ files:
|
|
187
187
|
- Rakefile
|
188
188
|
- bin/mongodb-graphite-agent.rb
|
189
189
|
- lib/mongodb/graphite/agent.rb
|
190
|
+
- lib/mongodb/graphite/agent/collection_size_calculator.rb
|
190
191
|
- lib/mongodb/graphite/agent/graphite_writer.rb
|
191
192
|
- lib/mongodb/graphite/agent/mongo_cient_extensions.rb
|
192
193
|
- lib/mongodb/graphite/agent/op_counters_sample.rb
|
@@ -194,6 +195,7 @@ files:
|
|
194
195
|
- lib/mongodb/graphite/agent/version.rb
|
195
196
|
- mongodb-graphite-agent.gemspec
|
196
197
|
- spec/agent_spec.rb
|
198
|
+
- spec/collection_size_calculator_spec.rb
|
197
199
|
- spec/op_counters_sample_spec.rb
|
198
200
|
homepage: https://github.com/emmekappa/mongodb-graphite-agent
|
199
201
|
licenses:
|
@@ -222,4 +224,5 @@ specification_version: 3
|
|
222
224
|
summary: ''
|
223
225
|
test_files:
|
224
226
|
- spec/agent_spec.rb
|
227
|
+
- spec/collection_size_calculator_spec.rb
|
225
228
|
- spec/op_counters_sample_spec.rb
|