rapporteur-load_check 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZDYwMTM0OTM0YmI1ZWE4NTI0YmQzMWE0NDA1NjVjMDY1ODBlOTA4MQ==
5
+ data.tar.gz: !binary |-
6
+ OTQ3MmI4MTIwMTBjN2MwNDJmOWVjNWExYTg3OGJmOGMzNWE3OGY0OA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MjcwMjVhOThlY2UyN2E3MGJkZGQxOTE5NTYwMzdiNWJiNjEyMmM3M2FhYWVj
10
+ MjIwMmUwZmFmNjU0ZmVhMDZlNjZkZThmNGUwNzQ1OWNlZTM0YmQ3NjY0NWYx
11
+ OGU4NmY0MzE4NmIzYmZlYzY2YzA2YmJmNjc5NzY5ODFkMTI4ODM=
12
+ data.tar.gz: !binary |-
13
+ MzkwYWRjNzc4NzMwNjcxZWFjOGExNmY0ZTgzZDZiODhmY2Y0MjYxNjVmMTk0
14
+ NDFjN2I2NGJhOWVmMjgwZTc2NjU3ZDk3NTk2ZDljZGZiYTdkMzUyNDNkNDI3
15
+ MDA1MjFiYzZjNzE1MTZlOTAzMjhjN2NhODc5NTQ5ZDgxOWMxYjg=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - jruby
6
+ notifications:
7
+ email: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Rapporteur Load Check changelog
2
+
3
+ ## [HEAD][unreleased] / unreleased
4
+
5
+ * No significant changes.
6
+
7
+ ## 1.0.0 / 2013-05-30
8
+
9
+ * Initial public release.
10
+
11
+ [unreleased]: https://github.com/codeschool/rapporteur-load_check/compare/1.0.0...master
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
5
+ gem "sqlite3", :platforms => :ruby
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Dray Lacy
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,35 @@
1
+ # Rapporteur Load Check
2
+
3
+ Load checking for [Rapporteur](https://github.com/codeschool/rapporteur).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rapporteur-load_check'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rapporteur-load_check
18
+
19
+ ## Usage
20
+
21
+ To add the check to your application, define the check in your environment or
22
+ application configuration files or initializers, such as:
23
+
24
+ ```ruby
25
+ # config/initializers/production.rb
26
+ Rapporteur::Checker.add_check(Rapporteur::Checks::LoadCheck)
27
+ ```
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
data/config.ru ADDED
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.require :default, :development
5
+
6
+ Combustion.initialize!
7
+ run Combustion::Application
@@ -0,0 +1,31 @@
1
+ require "ffi"
2
+ require "rapporteur"
3
+
4
+ module Rapporteur
5
+ module Checks
6
+ class LoadCheck
7
+ extend FFI::Library
8
+
9
+ ffi_lib FFI::Library::LIBC
10
+
11
+ attach_function :getloadavg, [:pointer, :int], :int
12
+ attach_function :strerror, [:int], :string
13
+
14
+ private_class_method :getloadavg, :strerror
15
+
16
+ def self.call(checker)
17
+ loadavg = current_load
18
+ checker.add_error(:excess_load) if loadavg > 8.0
19
+ checker.add_message(:load, loadavg)
20
+ end
21
+
22
+ def self.current_load
23
+ loadavg = FFI::MemoryPointer.new(:double, 1)
24
+ if getloadavg(loadavg, 1) == -1
25
+ raise SystemCallError, "getloadavg() - #{strerror(FFI.errno)}"
26
+ end
27
+ loadavg.read_double
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rapporteur-load_check"
7
+ spec.version = "1.0.0"
8
+ spec.authors = ["Envy Labs", "Code School"]
9
+ spec.email = [""]
10
+ spec.description = %q{Machine load reporting for rapporteur}
11
+ spec.summary = spec.description
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "ffi"
21
+ spec.add_dependency "rapporteur", "~> 1.1"
22
+
23
+ spec.add_development_dependency "combustion", "~> 0.5"
24
+ spec.add_development_dependency "rails", "~> 3.1"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec-rails", "~> 2.11"
27
+ end
@@ -0,0 +1,3 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: db/combustion_test.sqlite
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ #
3
+ end
@@ -0,0 +1,3 @@
1
+ ActiveRecord::Schema.define do
2
+ #
3
+ end
@@ -0,0 +1 @@
1
+ *.log
File without changes
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'A status request with a LoadCheck' do
4
+ before do
5
+ Rapporteur::Checker.add_check(Rapporteur::Checks::LoadCheck)
6
+ Rapporteur::Checks::LoadCheck.stub(:current_load).and_return(current_load)
7
+ end
8
+
9
+ subject { get(status_path) ; response }
10
+
11
+ context 'with a load below the threshold' do
12
+ let(:current_load) { 1.0 }
13
+
14
+ it_behaves_like 'a successful status response'
15
+
16
+ it 'contains the load value in the messages' do
17
+ json = JSON.parse(subject.body)
18
+ expect(json["messages"]["load"]).to eq(1.0)
19
+ end
20
+ end
21
+
22
+ context 'with a load above the threshold' do
23
+ let(:current_load) { 9.0 }
24
+
25
+ it_behaves_like 'an erred status response'
26
+
27
+ it 'contains a message regarding the excess load' do
28
+ expect(subject).to include_status_error_message(I18n.t('activemodel.errors.models.rapporteur/checker.attributes.base.excess_load'))
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,20 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+ require "combustion"
4
+
5
+ ENV["RAILS_ENV"] ||= "test"
6
+ Combustion.initialize!(:action_controller, :active_record)
7
+
8
+ require "rspec/rails"
9
+ require "rapporteur/rspec"
10
+ require "rapporteur/load_check"
11
+
12
+ RSpec.configure do |config|
13
+ config.treat_symbols_as_metadata_keys_with_true_values = true
14
+ config.run_all_when_everything_filtered = true
15
+ config.filter_run :focus
16
+
17
+ config.order = "random"
18
+
19
+ config.before { Rapporteur::Checker.clear }
20
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rapporteur-load_check
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Envy Labs
8
+ - Code School
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: ffi
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ! '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ! '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rapporteur
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: '1.1'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: '1.1'
42
+ - !ruby/object:Gem::Dependency
43
+ name: combustion
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: '0.5'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '0.5'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rails
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '3.1'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '3.1'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rspec-rails
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ version: '2.11'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ~>
96
+ - !ruby/object:Gem::Version
97
+ version: '2.11'
98
+ description: Machine load reporting for rapporteur
99
+ email:
100
+ - ''
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - .gitignore
106
+ - .rspec
107
+ - .travis.yml
108
+ - CHANGELOG.md
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - config.ru
114
+ - lib/rapporteur/load_check.rb
115
+ - rapporteur-load_check.gemspec
116
+ - spec/internal/config/database.yml
117
+ - spec/internal/config/routes.rb
118
+ - spec/internal/db/combustion_test.sqlite
119
+ - spec/internal/db/schema.rb
120
+ - spec/internal/log/.gitignore
121
+ - spec/internal/public/favicon.ico
122
+ - spec/requests/load_check_spec.rb
123
+ - spec/spec_helper.rb
124
+ homepage: ''
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.0.3
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Machine load reporting for rapporteur
148
+ test_files:
149
+ - spec/internal/config/database.yml
150
+ - spec/internal/config/routes.rb
151
+ - spec/internal/db/combustion_test.sqlite
152
+ - spec/internal/db/schema.rb
153
+ - spec/internal/log/.gitignore
154
+ - spec/internal/public/favicon.ico
155
+ - spec/requests/load_check_spec.rb
156
+ - spec/spec_helper.rb