Class: Graylog2::Resque::FailureHandler
- Inherits:
-
Resque::Failure::Base
- Object
- Resque::Failure::Base
- Graylog2::Resque::FailureHandler
- Defined in:
- lib/graylog2-resque/failure_handler.rb
Overview
A Failure backend that sends exceptions to Graylog
Graylog2::Resque::FailureHandler.configure do |config|
# required
config.gelf_server = "server"
config.gelf_port = "port"
# optional
# config.host = "myhost"
# config.facility = "rails_worker_exceptions"
# config.level = GELF::FATAL
# config.max_chunk_size = 'LAN'
end
Class Attribute Summary collapse
-
.facility ⇒ Object
optional.
-
.gelf_port ⇒ Object
required.
-
.gelf_server ⇒ Object
required.
-
.host ⇒ Object
optional.
-
.level ⇒ Object
optional.
-
.max_chunk_size ⇒ Object
optional.
Class Method Summary collapse
Instance Method Summary collapse
Class Attribute Details
.facility ⇒ Object
optional
27 28 29 |
# File 'lib/graylog2-resque/failure_handler.rb', line 27 def facility @facility end |
.gelf_port ⇒ Object
required
25 26 27 |
# File 'lib/graylog2-resque/failure_handler.rb', line 25 def gelf_port @gelf_port end |
.gelf_server ⇒ Object
required
25 26 27 |
# File 'lib/graylog2-resque/failure_handler.rb', line 25 def gelf_server @gelf_server end |
.host ⇒ Object
optional
27 28 29 |
# File 'lib/graylog2-resque/failure_handler.rb', line 27 def host @host end |
.level ⇒ Object
optional
27 28 29 |
# File 'lib/graylog2-resque/failure_handler.rb', line 27 def level @level end |
.max_chunk_size ⇒ Object
optional
27 28 29 |
# File 'lib/graylog2-resque/failure_handler.rb', line 27 def max_chunk_size @max_chunk_size end |
Class Method Details
.configure {|_self| ... } ⇒ Object
30 31 32 33 34 |
# File 'lib/graylog2-resque/failure_handler.rb', line 30 def self.configure yield self raise "Graylog server and port needed for resque failure handler" unless gelf_server && gelf_port ::Resque::Failure.backend = self end |
.count ⇒ Object
63 64 65 66 67 |
# File 'lib/graylog2-resque/failure_handler.rb', line 63 def self.count # We can't get the total # of errors from graylog so we fake it # by asking Resque how many errors it has seen. ::Resque::Stat[:failed] end |
Instance Method Details
#save ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/graylog2-resque/failure_handler.rb', line 36 def save begin data = {} trace = Array(exception.backtrace) if trace[0] data[:file] = trace[0].split(":")[0] data[:line] = trace[0].split(":")[1] end data[:facility] = self.class.facility if self.class.facility data[:level] = self.class.level || GELF::FATAL data[:host] = self.class.host if self.class.host data[:short_message] = "#{exception.class}: #{exception.}" data[:full_message] = "Backtrace:\n" + trace.join("\n") data["_resque_worker"] = worker.to_s data["_resque_queue"] = queue.to_s data["_resque_class"] = payload['class'].to_s data["_resque_args"] = payload['args'].inspect.to_s notifier = GELF::Notifier.new(self.class.gelf_server, self.class.gelf_port, self.class.max_chunk_size || 'LAN') notifier.notify!(data) rescue Exception => e puts "Failed to send resque failure to graylog: #{e}" end end |