mongodb-graphite-agent 0.0.3 → 0.0.4
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/.gitignore +2 -1
- data/Gemfile +2 -2
- data/bin/mongodb-graphite-agent.rb +27 -7
- data/lib/mongodb/graphite/agent/graphite_writer.rb +33 -0
- data/lib/mongodb/graphite/agent/op_counters_sample.rb +25 -25
- data/lib/mongodb/graphite/agent/utils.rb +1 -1
- data/lib/mongodb/graphite/agent/version.rb +1 -1
- data/lib/mongodb/graphite/agent.rb +13 -11
- data/mongodb-graphite-agent.gemspec +1 -0
- data/mongodb-graphite-agent.iml +28 -27
- metadata +25 -2
data/.gitignore
CHANGED
data/Gemfile
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
3
|
gemspec
|
@@ -1,7 +1,27 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.expand_path("#{File.dirname(__FILE__)}/../lib")
|
4
|
+
|
5
|
+
require 'trollop'
|
6
|
+
require 'mongodb/graphite/agent'
|
7
|
+
require 'mongodb/graphite/agent/graphite_writer'
|
8
|
+
|
9
|
+
opts = Trollop::options do
|
10
|
+
opt :mongodb_username, "MongoDB username", :type => :string
|
11
|
+
opt :mongodb_host, "MongoDB host", :type => :string, :default => "localhost"
|
12
|
+
opt :mongodb_post, "MongoDB host", :type => :int, :default => 27017
|
13
|
+
opt :mongodb_password, "MongoDB password", :type => :string
|
14
|
+
opt :graphite_host, "Graphite host", :type => :string
|
15
|
+
opt :graphite_port, "Graphite port", :type => :string
|
16
|
+
opt :dry_run, "Dry run", :type => :boolean, :default => false
|
17
|
+
opt :verbose, "Verbose", :type => :boolean, :default => false
|
18
|
+
end
|
19
|
+
|
20
|
+
if opts[:dry_run]
|
21
|
+
puts "\n\nWARNING!!! This is a dry run\n\n\n"
|
22
|
+
sleep 1
|
23
|
+
end
|
24
|
+
|
25
|
+
#@writer = Mongodb::Graphite::Agent::GraphiteWriter.new("localhost", 12)
|
26
|
+
#@writer.write ({ "antani" => 5, "boh" => 1 })
|
27
|
+
Mongodb::Graphite::Agent.run(opts)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
class Hash
|
4
|
+
def hash_map
|
5
|
+
self.inject({}) do |newhash, (k,v)|
|
6
|
+
newhash[k] = yield(k, v)
|
7
|
+
newhash
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module Mongodb
|
13
|
+
module Graphite
|
14
|
+
module Agent
|
15
|
+
class GraphiteWriter
|
16
|
+
def initialize(host, port, verbose)
|
17
|
+
@graphite = ::Graphite.new({:host => host, :port => port})
|
18
|
+
@verbose = verbose
|
19
|
+
end
|
20
|
+
|
21
|
+
def write(metric_hash)
|
22
|
+
puts "Sending data to graphite" if @verbose
|
23
|
+
ap metric_hash if @verbose
|
24
|
+
@metric_hash_with_hostname = metric_hash.map { |k, v| { "#{Socket.gethostname}.#{k}" => v } }.reduce Hash.new(), :merge
|
25
|
+
@graphite.send_metrics @metric_hash_with_hostname
|
26
|
+
#ap metric_hash.hash_map { |k, v| { "#{Socket.gethostname}.#{k}" => v }}
|
27
|
+
|
28
|
+
#@graphite.send_metrics({"#{Socket.gethostname}.#{metric}" => value})
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -1,26 +1,26 @@
|
|
1
|
-
require 'date'
|
2
|
-
|
3
|
-
module Mongodb
|
4
|
-
module Graphite
|
5
|
-
module Agent
|
6
|
-
|
7
|
-
class OpCountersSample
|
8
|
-
attr_reader :values, :sample_time
|
9
|
-
|
10
|
-
def initialize(values, sample_time = DateTime.now.to_s)
|
11
|
-
@values = values
|
12
|
-
@sample_time = sample_time
|
13
|
-
end
|
14
|
-
|
15
|
-
def marshal_dump
|
16
|
-
[@sample_time, @values]
|
17
|
-
end
|
18
|
-
|
19
|
-
def marshal_load array
|
20
|
-
@sample_time, @values = array
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module Mongodb
|
4
|
+
module Graphite
|
5
|
+
module Agent
|
6
|
+
|
7
|
+
class OpCountersSample
|
8
|
+
attr_reader :values, :sample_time
|
9
|
+
|
10
|
+
def initialize(values, sample_time = DateTime.now.to_s)
|
11
|
+
@values = values
|
12
|
+
@sample_time = sample_time
|
13
|
+
end
|
14
|
+
|
15
|
+
def marshal_dump
|
16
|
+
[@sample_time, @values]
|
17
|
+
end
|
18
|
+
|
19
|
+
def marshal_load array
|
20
|
+
@sample_time, @values = array
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
26
|
end
|
@@ -12,13 +12,15 @@ require 'mongodb/graphite/agent/op_counters_sample'
|
|
12
12
|
module Mongodb
|
13
13
|
module Graphite
|
14
14
|
module Agent
|
15
|
-
def self.run
|
16
|
-
@connection = Mongo::MongoClient.new(
|
15
|
+
def self.run(opts)
|
16
|
+
@connection = Mongo::MongoClient.new(opts.mongodb_host, opts.mongodb_port, :slave_ok => true)
|
17
|
+
unless(opts[:mongodb_username].blank? && opts[:mongodb_password].blank?)
|
18
|
+
@connection["admin"].authenticate(opts.mongodb_username, opts.mongodb_password)
|
19
|
+
end
|
17
20
|
|
18
21
|
@hash = @connection["local"].command('serverStatus' => 1)
|
19
22
|
|
20
|
-
|
21
|
-
@g = ::Graphite.new({:host => "localhost", :port => 2003})
|
23
|
+
@graphite_writer = GraphiteWriter.new(opts[:graphite_host], opts[:graphite_port], opts[:verbose])
|
22
24
|
|
23
25
|
#puts @hash["connections"]["current"]
|
24
26
|
#puts @hash["connections"]["available"]
|
@@ -37,9 +39,6 @@ module Mongodb
|
|
37
39
|
@asd = Utils.to_hash(@hash) #all metrics
|
38
40
|
|
39
41
|
|
40
|
-
#ap(@asd)
|
41
|
-
|
42
|
-
|
43
42
|
@current_sample = OpCountersSample.new Hash[@hash["opcounters"]]
|
44
43
|
@previous_sample = @current_sample.dup
|
45
44
|
|
@@ -51,23 +50,26 @@ module Mongodb
|
|
51
50
|
end
|
52
51
|
end
|
53
52
|
|
54
|
-
puts "Delta: "
|
55
53
|
@delta = TimeDifference.between(Time.parse(@current_sample.sample_time), Time.parse(@previous_sample.sample_time))
|
56
|
-
puts @delta.in_seconds
|
54
|
+
puts "Last sample was taken #{@delta.in_seconds.round(0)} seconds ago" if opts[:verbose]
|
57
55
|
|
58
56
|
@previous_sample.values.keys.sort.each do |k|
|
59
57
|
previous_sample_value = @previous_sample.values[k]
|
60
58
|
current_sample_value = @current_sample.values[k]
|
61
59
|
value_per_seconds = ((current_sample_value - previous_sample_value) / @delta.in_seconds).round(2)
|
62
|
-
puts "#{k}: #{previous_sample_value} / #{current_sample_value}: #{value_per_seconds}/s"
|
60
|
+
puts "#{k}: #{previous_sample_value} / #{current_sample_value}: #{value_per_seconds}/s" if opts[:verbose]
|
63
61
|
end
|
64
62
|
|
65
63
|
File.open('lastsample', 'w') do |file|
|
66
64
|
Marshal.dump(@current_sample, file)
|
67
65
|
end
|
68
66
|
|
69
|
-
|
67
|
+
@graphite_writer.write( @asd.select {|k| k.match('^connection|^network\.|^cursors|^mem\.mapped|^indexCounters|^repl.oplog') } )
|
68
|
+
#@graphite_writer.write("connections.current" => @hash["connections"]["current"]) unless(opts[:dry_run])
|
70
69
|
end
|
71
70
|
end
|
72
71
|
end
|
73
72
|
end
|
73
|
+
class GraphiteWriter
|
74
|
+
|
75
|
+
end
|
data/mongodb-graphite-agent.iml
CHANGED
@@ -1,27 +1,28 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<module type="RUBY_MODULE" version="4">
|
3
|
-
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
4
|
-
<exclude-output />
|
5
|
-
<content url="file://$MODULE_DIR$">
|
6
|
-
<sourceFolder url="file://$MODULE_DIR$/lib" isTestSource="false" />
|
7
|
-
</content>
|
8
|
-
<orderEntry type="inheritedJdk" />
|
9
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
10
|
-
<orderEntry type="library" scope="PROVIDED" name="activesupport (v4.0.0, ruby-1.9.3-
|
11
|
-
<orderEntry type="library" scope="PROVIDED" name="atomic (v1.1.10, ruby-1.9.3-
|
12
|
-
<orderEntry type="library" scope="PROVIDED" name="awesome_print (v1.1.0, ruby-1.9.3-
|
13
|
-
<orderEntry type="library" scope="PROVIDED" name="bson (v1.9.0, ruby-1.9.3-
|
14
|
-
<orderEntry type="library" scope="PROVIDED" name="bson_ext (v1.9.0, ruby-1.9.3-
|
15
|
-
<orderEntry type="library" scope="PROVIDED" name="bundler (v1.3.5, ruby-1.9.3-
|
16
|
-
<orderEntry type="library" scope="PROVIDED" name="i18n (v0.6.4, ruby-1.9.3-
|
17
|
-
<orderEntry type="library" scope="PROVIDED" name="minitest (v4.7.5, ruby-1.9.3-
|
18
|
-
<orderEntry type="library" scope="PROVIDED" name="mongo (v1.9.0, ruby-1.9.3-
|
19
|
-
<orderEntry type="library" scope="PROVIDED" name="multi_json (v1.7.7, ruby-1.9.3-
|
20
|
-
<orderEntry type="library" scope="PROVIDED" name="rake (
|
21
|
-
<orderEntry type="library" scope="PROVIDED" name="simple-graphite (v2.1.0, ruby-1.9.3-
|
22
|
-
<orderEntry type="library" scope="PROVIDED" name="thread_safe (v0.1.0, ruby-1.9.3-
|
23
|
-
<orderEntry type="library" scope="PROVIDED" name="time_difference (v0.2.0, ruby-1.9.3-
|
24
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
25
|
-
|
26
|
-
</
|
27
|
-
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
4
|
+
<exclude-output />
|
5
|
+
<content url="file://$MODULE_DIR$">
|
6
|
+
<sourceFolder url="file://$MODULE_DIR$/lib" isTestSource="false" />
|
7
|
+
</content>
|
8
|
+
<orderEntry type="inheritedJdk" />
|
9
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
10
|
+
<orderEntry type="library" scope="PROVIDED" name="activesupport (v4.0.0, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
11
|
+
<orderEntry type="library" scope="PROVIDED" name="atomic (v1.1.10, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
12
|
+
<orderEntry type="library" scope="PROVIDED" name="awesome_print (v1.1.0, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
13
|
+
<orderEntry type="library" scope="PROVIDED" name="bson (v1.9.0, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
14
|
+
<orderEntry type="library" scope="PROVIDED" name="bson_ext (v1.9.0, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
15
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v1.3.5, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
16
|
+
<orderEntry type="library" scope="PROVIDED" name="i18n (v0.6.4, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
17
|
+
<orderEntry type="library" scope="PROVIDED" name="minitest (v4.7.5, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
18
|
+
<orderEntry type="library" scope="PROVIDED" name="mongo (v1.9.0, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
19
|
+
<orderEntry type="library" scope="PROVIDED" name="multi_json (v1.7.7, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
20
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v10.1.0, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
21
|
+
<orderEntry type="library" scope="PROVIDED" name="simple-graphite (v2.1.0, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
22
|
+
<orderEntry type="library" scope="PROVIDED" name="thread_safe (v0.1.0, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
23
|
+
<orderEntry type="library" scope="PROVIDED" name="time_difference (v0.2.0, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
24
|
+
<orderEntry type="library" scope="PROVIDED" name="trollop (v2.0, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
25
|
+
<orderEntry type="library" scope="PROVIDED" name="tzinfo (v0.3.37, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
26
|
+
</component>
|
27
|
+
</module>
|
28
|
+
|
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.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -139,6 +139,22 @@ dependencies:
|
|
139
139
|
- - ! '>='
|
140
140
|
- !ruby/object:Gem::Version
|
141
141
|
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: trollop
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
type: :runtime
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
142
158
|
description: ''
|
143
159
|
email:
|
144
160
|
- michele.cantelli@jobrapido.com
|
@@ -154,6 +170,7 @@ files:
|
|
154
170
|
- Rakefile
|
155
171
|
- bin/mongodb-graphite-agent.rb
|
156
172
|
- lib/mongodb/graphite/agent.rb
|
173
|
+
- lib/mongodb/graphite/agent/graphite_writer.rb
|
157
174
|
- lib/mongodb/graphite/agent/op_counters_sample.rb
|
158
175
|
- lib/mongodb/graphite/agent/utils.rb
|
159
176
|
- lib/mongodb/graphite/agent/version.rb
|
@@ -172,15 +189,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
172
189
|
- - ! '>='
|
173
190
|
- !ruby/object:Gem::Version
|
174
191
|
version: '0'
|
192
|
+
segments:
|
193
|
+
- 0
|
194
|
+
hash: 461905061788265084
|
175
195
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
176
196
|
none: false
|
177
197
|
requirements:
|
178
198
|
- - ! '>='
|
179
199
|
- !ruby/object:Gem::Version
|
180
200
|
version: '0'
|
201
|
+
segments:
|
202
|
+
- 0
|
203
|
+
hash: 461905061788265084
|
181
204
|
requirements: []
|
182
205
|
rubyforge_project:
|
183
|
-
rubygems_version: 1.8.
|
206
|
+
rubygems_version: 1.8.25
|
184
207
|
signing_key:
|
185
208
|
specification_version: 3
|
186
209
|
summary: ''
|