graphiterb 0.0.1

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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/CHANGELOG ADDED
@@ -0,0 +1 @@
1
+ 2010-03-02 Initial functionality
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Philip (flip) Kromer (@mrflip)
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.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = graphiterb
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Philip (flip) Kromer (@mrflip). See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "graphiterb"
8
+ gem.summary = %Q{Fast Ubiquitous Dashboard Logs with Graphite (http://graphite.wikidot.com)}
9
+ gem.description = %Q{Uses http://github.com/mrflip/configliere and http://graphite.wikidot.com}
10
+ gem.email = "info@infochimps.org"
11
+ gem.homepage = "http://github.com/mrflip/graphiterb"
12
+ gem.authors = ["Philip (flip) Kromer (@mrflip)"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_development_dependency "yard", ">= 0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
38
+ begin
39
+ require 'yard'
40
+ YARD::Rake::YardocTask.new
41
+ rescue LoadError
42
+ task :yardoc do
43
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
44
+ end
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ $: << File.dirname(__FILE__)+'/../lib'
4
+ require 'graphiterb'
5
+ Configliere.use :commandline, :config_file
6
+
7
+ Settings.read 'graphite.yaml'
8
+ Settings.resolve!
9
+ Log = Logger.new($stderr) unless defined?(Log)
10
+
11
+ class LoadavgGraphiteSender < GraphiteRb::GraphiteSender
12
+ def loadavgs
13
+ File.open('/proc/loadavg').read.strip.split[0..2]
14
+ end
15
+
16
+ def loadavgs_metrics
17
+ %w[1min 5min 15min].zip(loadavgs).map do |duration, avg|
18
+ ["system_rb.loadavg_#{duration}", avg]
19
+ end
20
+ end
21
+
22
+ def send_loop
23
+ loop do
24
+ send *loadavgs_metrics
25
+ Log.info "Sleeping #{Settings.update_delay}"
26
+ sleep Settings.update_delay.to_i
27
+ end
28
+ end
29
+ end
30
+
31
+ LoadavgGraphiteSender.new.send_loop
@@ -0,0 +1,63 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{graphiterb}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Philip (flip) Kromer (@mrflip)"]
12
+ s.date = %q{2010-03-02}
13
+ s.default_executable = %q{example-client.rb}
14
+ s.description = %q{Uses http://github.com/mrflip/configliere and http://graphite.wikidot.com}
15
+ s.email = %q{info@infochimps.org}
16
+ s.executables = ["example-client.rb"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "CHANGELOG",
25
+ "LICENSE",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "bin/example-client.rb",
30
+ "graphiterb.gemspec",
31
+ "lib/graphiterb.rb",
32
+ "lib/graphiterb/graphite_sender.rb",
33
+ "spec/graphiterb_spec.rb",
34
+ "spec/spec.opts",
35
+ "spec/spec_helper.rb"
36
+ ]
37
+ s.homepage = %q{http://github.com/mrflip/graphiterb}
38
+ s.rdoc_options = ["--charset=UTF-8"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = %q{1.3.6}
41
+ s.summary = %q{Fast Ubiquitous Dashboard Logs with Graphite (http://graphite.wikidot.com)}
42
+ s.test_files = [
43
+ "spec/spec_helper.rb",
44
+ "spec/graphiterb_spec.rb"
45
+ ]
46
+
47
+ if s.respond_to? :specification_version then
48
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
49
+ s.specification_version = 3
50
+
51
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
52
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
53
+ s.add_development_dependency(%q<yard>, [">= 0"])
54
+ else
55
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
56
+ s.add_dependency(%q<yard>, [">= 0"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
60
+ s.add_dependency(%q<yard>, [">= 0"])
61
+ end
62
+ end
63
+
@@ -0,0 +1,50 @@
1
+ module GraphiteRb
2
+ #
3
+ # @example:
4
+ # # in initialize, perhaps
5
+ # self.sender = GraphiteSender
6
+ #
7
+ # # ... somewhere else ...
8
+ # sender.send( ['webserver.pages', pages_this_hour], ['webserver.errors', errors_this_hour] )
9
+ #
10
+ class GraphiteSender
11
+ attr_accessor :socket
12
+
13
+ def initialize
14
+ open!
15
+ end
16
+
17
+ def open!
18
+ begin
19
+ warn "Connecting to server #{Settings.carbon_server} port #{Settings.carbon_port}"
20
+ self.socket = TCPSocket.new(Settings.carbon_server, Settings.carbon_port)
21
+ rescue StandardError => e
22
+ Log.warn "Couldn't connect to server #{Settings.carbon_server} port #{Settings.carbon_port}: #{e.class} #{e}"
23
+ raise e
24
+ end
25
+ end
26
+
27
+ def safely &block
28
+ begin
29
+ block.call
30
+ rescue StandardError => e
31
+ Log.warn "Sleeping #{Settings.on_error_delay}: #{e.class} #{e}"
32
+ sleep Settings.on_error_delay
33
+ return nil
34
+ end
35
+ end
36
+
37
+ def timestamp
38
+ Time.now.to_i
39
+ end
40
+
41
+ def send *metrics
42
+ now = timestamp
43
+ message = metrics.map{|metric, val| [metric, val, now].join(" ") }.join("\n")
44
+ safely do
45
+ socket.puts(message)
46
+ Log.debug "Sent:\n#{message}\n#{'-'*80}"
47
+ end
48
+ end
49
+ end
50
+ end
data/lib/graphiterb.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'socket'
2
+ require 'logger'
3
+
4
+ require 'configliere'
5
+ Configliere.use :define
6
+ Settings.define :carbon_server, :default => 'localhost', :description => "Host address for carbon database server", :required => true
7
+ Settings.define :carbon_port, :default => '2003', :description => "Port for carbon database server", :required => true
8
+ Settings.define :update_delay, :default => 60, :description => "How long to wait between updates", :required => true, :type => Integer
9
+ Settings.define :on_error_delay, :default => 60, :description => "How long to wait on connect errors", :required => true, :type => Integer
10
+
11
+ require 'graphiterb/graphite_sender'
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Graphiterb" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'graphiterb'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: graphiterb
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Philip (flip) Kromer (@mrflip)
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-02 00:00:00 +00:00
18
+ default_executable: example-client.rb
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 9
31
+ version: 1.2.9
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: yard
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :development
45
+ version_requirements: *id002
46
+ description: Uses http://github.com/mrflip/configliere and http://graphite.wikidot.com
47
+ email: info@infochimps.org
48
+ executables:
49
+ - example-client.rb
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - LICENSE
54
+ - README.rdoc
55
+ files:
56
+ - .document
57
+ - .gitignore
58
+ - CHANGELOG
59
+ - LICENSE
60
+ - README.rdoc
61
+ - Rakefile
62
+ - VERSION
63
+ - bin/example-client.rb
64
+ - graphiterb.gemspec
65
+ - lib/graphiterb.rb
66
+ - lib/graphiterb/graphite_sender.rb
67
+ - spec/graphiterb_spec.rb
68
+ - spec/spec.opts
69
+ - spec/spec_helper.rb
70
+ has_rdoc: true
71
+ homepage: http://github.com/mrflip/graphiterb
72
+ licenses: []
73
+
74
+ post_install_message:
75
+ rdoc_options:
76
+ - --charset=UTF-8
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ requirements: []
94
+
95
+ rubyforge_project:
96
+ rubygems_version: 1.3.6
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: Fast Ubiquitous Dashboard Logs with Graphite (http://graphite.wikidot.com)
100
+ test_files:
101
+ - spec/spec_helper.rb
102
+ - spec/graphiterb_spec.rb