mongodb-graphite-agent 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea/*
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+ gem 'mongo'
3
+ gem 'simple-graphite'
4
+ gem 'bson'
5
+ gem 'bson_ext'
6
+ gem 'awesome_print'
7
+ gem 'time_difference'
data/LICENSE.txt ADDED
@@ -0,0 +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.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Mongodb::Graphite::Agent
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'mongodb-graphite-agent'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install mongodb-graphite-agent
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift File.absolute_path("#{File.dirname(__FILE__)}/../lib")
3
+ puts $LOAD_PATH
4
+ require "mongodb/graphite/agent"
5
+
6
+ Mongodb::Graphite::Agent.run()
7
+ #Agent.run()
@@ -0,0 +1,73 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'mongo'
4
+ require 'simple-graphite'
5
+ require 'bson'
6
+ require 'socket'
7
+ require 'awesome_print'
8
+ require 'time_difference'
9
+ require 'mongodb/graphite/agent/utils'
10
+ require 'mongodb/graphite/agent/op_counters_sample'
11
+
12
+ module Mongodb
13
+ module Graphite
14
+ module Agent
15
+ def self.run
16
+ @connection = Mongo::MongoClient.new("localhost", 27017, :slave_ok => true)
17
+
18
+ @hash = @connection["local"].command('serverStatus' => 1)
19
+
20
+
21
+ @g = ::Graphite.new({:host => "localhost", :port => 2003})
22
+
23
+ #puts @hash["connections"]["current"]
24
+ #puts @hash["connections"]["available"]
25
+ #
26
+ #puts @hash["backgroundFlushing"]["average_ms"]
27
+ #
28
+ #puts @hash["network"]["numRequests"]
29
+ #puts @hash["network"]["bytesIn"]
30
+ #puts @hash["network"]["bytesOut"]
31
+ #
32
+ #
33
+ #puts @hash["cursors"]["totalOpen"]
34
+ #
35
+ #puts @hash["indexCounters"]["missRatio"]
36
+
37
+ @asd = Utils.to_hash(@hash) #all metrics
38
+
39
+
40
+ #ap(@asd)
41
+
42
+
43
+ @current_sample = OpCountersSample.new Hash[@hash["opcounters"]]
44
+ @previous_sample = @current_sample.dup
45
+
46
+ if File.exist? 'lastsample'
47
+ File.open('lastsample', 'r') do |file|
48
+ @previous_sample = Marshal.load(file)
49
+ #puts "Loaded object"
50
+ #ap(@previous_sample)
51
+ end
52
+ end
53
+
54
+ puts "Delta: "
55
+ @delta = TimeDifference.between(Time.parse(@current_sample.sample_time), Time.parse(@previous_sample.sample_time))
56
+ puts @delta.in_seconds
57
+
58
+ @previous_sample.values.keys.sort.each do |k|
59
+ previous_sample_value = @previous_sample.values[k]
60
+ current_sample_value = @current_sample.values[k]
61
+ 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"
63
+ end
64
+
65
+ File.open('lastsample', 'w') do |file|
66
+ Marshal.dump(@current_sample, file)
67
+ end
68
+
69
+ #@g.send_metrics({"#{Socket.gethostname}.connections.current" => @hash["connections"]["current"]})
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +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
26
+ end
@@ -0,0 +1,29 @@
1
+ module Mongodb
2
+ module Graphite
3
+ module Agent
4
+
5
+ module Utils
6
+ def self.merge_all
7
+ self.inject({}) { |h1, h2|
8
+ h1.merge! h2
9
+ }
10
+ end
11
+
12
+ def self.json_descent(pre, json)
13
+ json.map do |k, v|
14
+ key = pre + [k]
15
+ if v.is_a? BSON::OrderedHash
16
+ json_descent(key, v)
17
+ else
18
+ {key.join('.') => v}
19
+ end
20
+ end
21
+ end
22
+
23
+ def self.to_hash(s)
24
+ json_descent([], s).flatten
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,7 @@
1
+ module Mongodb
2
+ module Graphite
3
+ module Agent
4
+ VERSION = "0.0.2"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mongodb/graphite/agent/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mongodb-graphite-agent"
8
+ spec.version = Mongodb::Graphite::Agent::VERSION
9
+ spec.authors = ["Michele Cantelli"]
10
+ spec.email = ["michele.cantelli@jobrapido.com"]
11
+ spec.description = ""
12
+ spec.summary = ""
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,26 @@
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-p429) [gem]" level="application" />
11
+ <orderEntry type="library" scope="PROVIDED" name="atomic (v1.1.10, ruby-1.9.3-p429) [gem]" level="application" />
12
+ <orderEntry type="library" scope="PROVIDED" name="awesome_print (v1.1.0, ruby-1.9.3-p429) [gem]" level="application" />
13
+ <orderEntry type="library" scope="PROVIDED" name="bson (v1.9.0, ruby-1.9.3-p429) [gem]" level="application" />
14
+ <orderEntry type="library" scope="PROVIDED" name="bson_ext (v1.9.0, ruby-1.9.3-p429) [gem]" level="application" />
15
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v1.3.5, ruby-1.9.3-p429) [gem]" level="application" />
16
+ <orderEntry type="library" scope="PROVIDED" name="i18n (v0.6.4, ruby-1.9.3-p429) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="minitest (v4.7.5, ruby-1.9.3-p429) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="mongo (v1.9.0, ruby-1.9.3-p429) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="multi_json (v1.7.7, ruby-1.9.3-p429) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="simple-graphite (v2.1.0, ruby-1.9.3-p429) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="thread_safe (v0.1.0, ruby-1.9.3-p429) [gem]" level="application" />
22
+ <orderEntry type="library" scope="PROVIDED" name="time_difference (v0.2.0, ruby-1.9.3-p429) [gem]" level="application" />
23
+ <orderEntry type="library" scope="PROVIDED" name="tzinfo (v0.3.37, ruby-1.9.3-p429) [gem]" level="application" />
24
+ </component>
25
+ </module>
26
+
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongodb-graphite-agent
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michele Cantelli
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: ''
47
+ email:
48
+ - michele.cantelli@jobrapido.com
49
+ executables:
50
+ - mongodb-graphite-agent.rb
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - bin/mongodb-graphite-agent.rb
60
+ - lib/mongodb/graphite/agent.rb
61
+ - lib/mongodb/graphite/agent/op_counters_sample.rb
62
+ - lib/mongodb/graphite/agent/utils.rb
63
+ - lib/mongodb/graphite/agent/version.rb
64
+ - mongodb-graphite-agent.gemspec
65
+ - mongodb-graphite-agent.iml
66
+ homepage: ''
67
+ licenses:
68
+ - MIT
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 1.8.24
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: ''
91
+ test_files: []