mongodb-graphite 0.1.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.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # A sample Gemfile
2
+ source "http://rubygems.org"
3
+
4
+ # gem "rails"
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mongodb-graphite (0.1.0.alpha)
5
+ graphite (>= 0.2.0)
6
+ mongo (>= 1.5.2)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ bson (1.5.2)
12
+ eventmachine (0.12.10)
13
+ graphite (0.2.0)
14
+ eventmachine
15
+ rufus-scheduler
16
+ mongo (1.5.2)
17
+ bson (= 1.5.2)
18
+ rufus-scheduler (2.0.16)
19
+ tzinfo (>= 0.3.23)
20
+ tzinfo (0.3.31)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ mongodb-graphite!
data/README.md ADDED
@@ -0,0 +1,12 @@
1
+ Very simple gem to monitor a mongodb cluster and send data to a graphite server.
2
+
3
+ Install :
4
+
5
+ Open the mongodb_graphite file and modify the graphite server variable to your graphite server. For exemple : "mygraphite.mydomain.com:2023"
6
+
7
+ Add the mongodb_graphite to your crontab, for instance
8
+ * * * * mongodb_graphite
9
+
10
+
11
+ That's all.
12
+
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'mongo'
4
+ require 'graphite'
5
+ require 'peach'
6
+
7
+ graphite_server = ARGV[0]
8
+
9
+ g = Graphite::Logger.new(graphite_server)
10
+
11
+ to_ignore =[ "set", "repl", "time","qr|qw","ar|aw","conn"]
12
+ to_convert = ["mapped","vsize","res","netIn","netOut"]
13
+ output_average = ["mapped","vsize","res","locked","idxmiss"]
14
+ output_sum = ["netIn", "netOut","insert","query","update","delete","getmore","command","flushes","faults"]
15
+ prefix_common = "criteo.mongodb."
16
+
17
+ def convert(s)
18
+ mul = case s[-1]
19
+ when "b"
20
+ 1
21
+ when "k"
22
+ 1024
23
+ when "m"
24
+ 1024 * 1024
25
+ when "g"
26
+ 1024 * 1024 *1024
27
+ when "t"
28
+ 1024 * 1024 * 1024 *1024
29
+ else
30
+ raise "not convertible"
31
+ end
32
+ s[0..-1].to_f * mul
33
+ end
34
+
35
+
36
+
37
+
38
+
39
+ @conn = Mongo::Connection.new
40
+
41
+
42
+ @isdbgrid = {"isdbgrid" => 1}
43
+ if @conn["admin"].command(@isdbgrid)["ok"] == 1
44
+ puts "mongos"
45
+ else
46
+ puts "not mongos => you should not run this if you are not in a cluster"
47
+ end
48
+
49
+ shards = Array.new
50
+
51
+ puts @conn["config"]["shards"].find().each { |shard| shards << shard["host"] }
52
+
53
+ shards.peach { |s|
54
+ host,port = s.split(/,|\//)[1].split(':')
55
+ #puts "shard : ", host,port
56
+ connHost = Mongo::Connection.new(host, port)
57
+ slaves = Array.new
58
+ connHost["admin"].command({ "isMaster" => 1 } )["hosts"].each { |slave| slaves << slave}
59
+ slaves.peach { |slave|
60
+ host, port = slave.split(':')
61
+ timestamp = Time.now.getutc.to_i
62
+ result= `mongostat -n 60 --host #{host} --port #{port} `.split("\n")
63
+ #timestamp += Time.now.getutc.to_i
64
+ #timestamp /= 2
65
+ headers, values = result[1], result[2..-1]
66
+ headers = headers.gsub(' %','').gsub('*','').gsub('idx miss','idxmiss').split
67
+ values= values.delete_if {|line| line.start_with?('insert')}.map { |line| line.gsub('*','').split}
68
+ values = values.transpose
69
+
70
+ prefix = prefix_common + host +"."+port+"."
71
+ headers = headers.map { |key| prefix+key }
72
+ metrics = Hash[headers.zip(values)]
73
+ to_ignore.each { |key| metrics.delete(prefix + key) }
74
+ to_convert.each { |key| metrics[prefix + key] = metrics[prefix+key].map {|val| convert(val)}}
75
+ output_average.each { |key| metrics[prefix+key] = metrics[prefix+key].inject(0.0) {|sum,el| sum+(el.to_i) } / metrics[prefix+key].size }
76
+ output_sum.each { |key| metrics[prefix+key] = metrics[prefix+key].inject(0) {|sum,el| sum+(el.to_i)} }
77
+ g.log(timestamp, metrics)
78
+
79
+ }
80
+ }
81
+
82
+
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "mongodb-graphite"
6
+ s.version = '0.1.0'
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Grégoire Seux"]
9
+ s.email = ["g.seux@criteo.com"]
10
+ s.homepage = "https://github.com/kamaradclimber/mongodb-graphite"
11
+ s.summary = %q{}
12
+ s.description = %q{}
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- test/{functional,unit}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ #s.require_paths = ["lib"]
17
+
18
+ s.add_dependency "mongo", ">= 1.5.2"
19
+ s.add_dependency "graphite", ">= 0.2.0"
20
+ s.add_dependency "peach", ">= 0.4"
21
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongodb-graphite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - "Gr\xC3\xA9goire Seux"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2012-02-07 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mongo
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.5.2
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: graphite
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: peach
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0.4"
44
+ version:
45
+ description: ""
46
+ email:
47
+ - g.seux@criteo.com
48
+ executables:
49
+ - mongodb-graphite
50
+ extensions: []
51
+
52
+ extra_rdoc_files: []
53
+
54
+ files:
55
+ - Gemfile
56
+ - Gemfile.lock
57
+ - README.md
58
+ - bin/mongodb-graphite
59
+ - mongodb-graphite.gemspec
60
+ has_rdoc: false
61
+ homepage: https://github.com/kamaradclimber/mongodb-graphite
62
+ post_install_message:
63
+ rdoc_options: []
64
+
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ requirements: []
80
+
81
+ rubyforge_project:
82
+ rubygems_version: 1.3.1
83
+ signing_key:
84
+ specification_version: 2
85
+ summary: ""
86
+ test_files: []
87
+