logjam_agent 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
data/lib/logjam_agent.rb
CHANGED
@@ -77,7 +77,7 @@ module LogjamAgent
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def format_exception(exception)
|
80
|
-
msg = "#{exception.class}
|
80
|
+
msg = "#{exception.class}(#{exception.message})"
|
81
81
|
if backtrace = exception.backtrace
|
82
82
|
backtrace = Rails.backtrace_cleaner.clean(backtrace, :all) if defined?(Rails)
|
83
83
|
msg << ":\n #{backtrace.join("\n ")}"
|
data/lib/logjam_agent/version.rb
CHANGED
@@ -0,0 +1,91 @@
|
|
1
|
+
module LogjamAgent
|
2
|
+
class ZMQForwarder
|
3
|
+
attr_reader :app, :env
|
4
|
+
|
5
|
+
def initialize(app, env, opts = {})
|
6
|
+
@app = app
|
7
|
+
@env = env
|
8
|
+
@config = default_options(app, env).merge!(opts)
|
9
|
+
@exchange = @config[:exchange]
|
10
|
+
@zmq_hosts = Array(@config[:host])
|
11
|
+
@zmq_port = @config[:port]
|
12
|
+
end
|
13
|
+
|
14
|
+
def default_options(app, env)
|
15
|
+
{
|
16
|
+
:host => "localhost",
|
17
|
+
:exchange => "request-stream-#{app}-#{env}",
|
18
|
+
:routing_key => "logs.#{app}.#{env}",
|
19
|
+
:port => 12345
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
@@mutex = Mutex.new
|
24
|
+
@@zmq_context = nil
|
25
|
+
|
26
|
+
def self.context
|
27
|
+
@@mutex.synchronize do
|
28
|
+
@@zmq_context ||=
|
29
|
+
begin
|
30
|
+
require 'ffi-rzmq'
|
31
|
+
context = ZMQ::Context.new(1)
|
32
|
+
at_exit { context.terminate }
|
33
|
+
context
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def socket
|
39
|
+
@socket ||=
|
40
|
+
begin
|
41
|
+
socket = self.class.context.socket(ZMQ::PUSH)
|
42
|
+
socket.setsockopt(ZMQ::LINGER, 100)
|
43
|
+
socket.setsockopt(ZMQ::SNDHWM, 10)
|
44
|
+
@zmq_hosts.each do |host|
|
45
|
+
socket.connect("tcp://#{host}:#{@zmq_port}")
|
46
|
+
end
|
47
|
+
at_exit { reset }
|
48
|
+
socket
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def reset
|
53
|
+
return unless @socket
|
54
|
+
# $stderr.puts "closing socket"
|
55
|
+
@socket.close
|
56
|
+
@socket = nil
|
57
|
+
end
|
58
|
+
|
59
|
+
def forward(msg, engine)
|
60
|
+
return if LogjamAgent.disabled
|
61
|
+
begin
|
62
|
+
key = @config[:routing_key]
|
63
|
+
key += ".#{engine}" if engine
|
64
|
+
publish(key, msg)
|
65
|
+
rescue Exception => exception
|
66
|
+
reraise_expectation_errors!
|
67
|
+
raise ForwardingError.new(exception.message)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def publish(key, data)
|
72
|
+
parts = [@exchange, key, data]
|
73
|
+
if socket.send_strings(parts, ZMQ::NonBlocking) < 0
|
74
|
+
raise "ZMQ error: #{ZMQ::Util.error_string}"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
if defined?(Mocha)
|
81
|
+
def reraise_expectation_errors! #:nodoc:
|
82
|
+
raise if $!.is_a?(Mocha::ExpectationError)
|
83
|
+
end
|
84
|
+
else
|
85
|
+
def reraise_expectation_errors! #:nodoc:
|
86
|
+
# noop
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logjam_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 2
|
10
|
+
version: 0.6.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Stefan Kaes
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2013-01-01 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rake
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- lib/logjam_agent/request.rb
|
114
114
|
- lib/logjam_agent/syslog_like_formatter.rb
|
115
115
|
- lib/logjam_agent/version.rb
|
116
|
+
- lib/logjam_agent/zmq_forwarder.rb
|
116
117
|
- logjam_agent.gemspec
|
117
118
|
- rails/init.rb
|
118
119
|
homepage: ""
|