Class: YourKarma::Benchmarker
- Inherits:
-
Object
- Object
- YourKarma::Benchmarker
- Defined in:
- lib/yourkarma/benchmarker.rb
Defined Under Namespace
Classes: ConnectionError
Constant Summary collapse
- HTTP_ERRORS =
[Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, Errno::ENETUNREACH, Errno::ETIMEDOUT, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, SocketError]
- DEFAULT_OPTIONS =
{ timeout: 10, benchmark: 'http://yourkarma.com/dashboard' }
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #benchmark ⇒ Object
-
#initialize(options = {}) ⇒ Benchmarker
constructor
A new instance of Benchmarker.
Constructor Details
#initialize(options = {}) ⇒ Benchmarker
Returns a new instance of Benchmarker.
22 23 24 |
# File 'lib/yourkarma/benchmarker.rb', line 22 def initialize( = {}) self. = DEFAULT_OPTIONS.merge() end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
20 21 22 |
# File 'lib/yourkarma/benchmarker.rb', line 20 def @options end |
Instance Method Details
#benchmark ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/yourkarma/benchmarker.rb', line 26 def benchmark uri = URI([:benchmark]) Timeout::timeout([:timeout]) do duration = Benchmark.realtime do Net::HTTP.get_response(uri) end return duration / [:timeout].to_f end rescue *HTTP_ERRORS => e raise ConnectionError end |