graphite-ruby 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ # Ignore bundler config.
2
+ /.bundle
3
+
4
+ # Ignore all logfiles and tempfiles.
5
+ /log/*.log
6
+ /tmp
7
+
8
+ # OS generated files.
9
+ .DS_Store*
10
+ ehthumbs.db
11
+ Icon?
12
+ Thumbs.db
13
+
14
+ # VIM.
15
+ .*.sw[a-z]
16
+ *.un~
17
+ Session.vim
18
+
19
+ # Yard
20
+ .yardoc
21
+ _yardoc
22
+ doc/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --debug
@@ -0,0 +1,5 @@
1
+ ---
2
+ language: ruby
3
+ rvm:
4
+ - 1.9.2
5
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ graphite-ruby (1.0.0)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ columnize (0.3.6)
10
+ debugger (1.2.3)
11
+ columnize (>= 0.3.1)
12
+ debugger-linecache (~> 1.1.1)
13
+ debugger-ruby_core_source (~> 1.1.5)
14
+ debugger-linecache (1.1.2)
15
+ debugger-ruby_core_source (>= 1.1.1)
16
+ debugger-ruby_core_source (1.1.6)
17
+ diff-lcs (1.1.3)
18
+ rake (10.0.3)
19
+ rspec (2.12.0)
20
+ rspec-core (~> 2.12.0)
21
+ rspec-expectations (~> 2.12.0)
22
+ rspec-mocks (~> 2.12.0)
23
+ rspec-core (2.12.0)
24
+ rspec-expectations (2.12.0)
25
+ diff-lcs (~> 1.1.3)
26
+ rspec-mocks (2.12.0)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ debugger (~> 1.2.2)
33
+ graphite-ruby!
34
+ rake
35
+ rspec (~> 2.12.0)
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Jey Balachandran
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,28 @@
1
+ graphite-ruby [![Build Status](https://travis-ci.org/jeyb/graphite-ruby.png)](https://travis-ci.org/jeyb/graphite-ruby)
2
+ =============
3
+ Sends measurements to [Hosted Graphite](http://hostedgraphite.com/) via UDP.
4
+
5
+ Usage
6
+ -----
7
+ ```ruby
8
+ $graphite = Graphite.new(ENV["GRAPHITE_TOKEN"], "carbon.hostedgraphite.com")
9
+
10
+ $graphite.measure "stats.name", 123
11
+ $graphite.measure "stats.another_name" do
12
+ sleep 1
13
+ end
14
+ ```
15
+
16
+ Contributing to graphite-ruby
17
+ -----------------------------
18
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
19
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
20
+ * Fork the project.
21
+ * Start a feature/bugfix branch.
22
+ * Commit and push until you are happy with your contribution.
23
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
24
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
25
+
26
+ Copyright
27
+ ---------
28
+ Copyright (c) 2013 Jey Balachandran. See LICENSE for further details.
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ require "rubygems"
4
+ require "bundler/setup"
5
+ require "rake"
6
+
7
+ begin
8
+ Bundler.setup(:default, :development)
9
+ rescue Bundler::BundlerError => exception
10
+ $stderr.puts exception.message
11
+ $stderr.puts "Run `bundle install` to install missing gems"
12
+ exit exception.status_code
13
+ end
14
+
15
+ require "rspec/core"
16
+ require "rspec/core/rake_task"
17
+ RSpec::Core::RakeTask.new(:spec) do |spec|
18
+ spec.pattern = FileList["spec/**/*_spec.rb"]
19
+ end
20
+
21
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
22
+ spec.pattern = "spec/**/*_spec.rb"
23
+ end
24
+
25
+ task default: :spec
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "graphite-ruby"
8
+ gem.version = "1.0.0"
9
+ gem.authors = ["Jey Balachandran"]
10
+ gem.email = ["jey.balachandran@gmail.com"]
11
+ gem.summary = %q{Sends measurements to Graphite via UDP}
12
+ gem.description = %q{Sends measurements to Graphite via UDP}
13
+ gem.homepage = "http://github.com/jeyb/graphite-ruby"
14
+ gem.license = "MIT"
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+
19
+ gem.required_ruby_version = ">= 1.9.2"
20
+
21
+ gem.add_development_dependency "debugger", "~> 1.2.2"
22
+ gem.add_development_dependency "rake"
23
+ gem.add_development_dependency "rspec", "~> 2.12.0"
24
+ end
@@ -0,0 +1,29 @@
1
+ require "socket"
2
+
3
+ class Graphite
4
+ def initialize(token, host, port = 2003)
5
+ @token, @host, @port = token, host, port
6
+ end
7
+
8
+ def measure(stat, value = nil)
9
+ if block_given?
10
+ start = Time.now
11
+ yield
12
+ value = ((Time.now - start) * 1000).round
13
+ end
14
+
15
+ send_to_socket("#{stat} #{value}") unless value.nil?
16
+ end
17
+
18
+ private
19
+
20
+ def send_to_socket(message)
21
+ return if defined?(Rails) && !Rails.env.production?
22
+
23
+ socket.send("#{@token}.#{message}", 0, @host, @port) rescue nil
24
+ end
25
+
26
+ def socket
27
+ @socket ||= UDPSocket.new
28
+ end
29
+ end
@@ -0,0 +1,19 @@
1
+ require "spec_helper"
2
+
3
+ describe Graphite do
4
+ let(:client) { Graphite.new("12345", "example.com") }
5
+
6
+ subject { Honeypot::Client.new(configuration) }
7
+
8
+ it "measures a value" do
9
+ client.should_receive(:send_to_socket).with("stat 123")
10
+ client.measure("stat", 123)
11
+ end
12
+
13
+ it "measures a block execution time" do
14
+ client.should_receive(:send_to_socket).with(/stat 1\d{3}/)
15
+ client.measure "stat" do
16
+ sleep 1
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require "graphite"
4
+
5
+ # Requires supporting files with custom matchers and macros, etc,
6
+ # in ./support/ and its subdirectories.
7
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: graphite-ruby
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.0.0
6
+ platform: ruby
7
+ authors:
8
+ - Jey Balachandran
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ prerelease: false
16
+ type: :development
17
+ version_requirements: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 1.2.2
23
+ name: debugger
24
+ requirement: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.2.2
30
+ - !ruby/object:Gem::Dependency
31
+ prerelease: false
32
+ type: :development
33
+ version_requirements: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ name: rake
40
+ requirement: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ prerelease: false
48
+ type: :development
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.12.0
55
+ name: rspec
56
+ requirement: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.12.0
62
+ description: Sends measurements to Graphite via UDP
63
+ email:
64
+ - jey.balachandran@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .rspec
71
+ - .travis.yml
72
+ - Gemfile
73
+ - Gemfile.lock
74
+ - LICENSE
75
+ - README.md
76
+ - Rakefile
77
+ - graphite-ruby.gemspec
78
+ - lib/graphite.rb
79
+ - spec/lib/graphite_spec.rb
80
+ - spec/spec_helper.rb
81
+ homepage: http://github.com/jeyb/graphite-ruby
82
+ licenses:
83
+ - MIT
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 1.9.2
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 1.8.24
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: Sends measurements to Graphite via UDP
106
+ test_files:
107
+ - spec/lib/graphite_spec.rb
108
+ - spec/spec_helper.rb
109
+ has_rdoc: