ramon 0.4.0 → 0.4.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/Gemfile +3 -0
- data/lib/ramon/configuration.rb +7 -4
- data/lib/ramon/sender.rb +38 -9
- data/lib/ramon/version.rb +1 -1
- data/spec/config_spec.rb +2 -2
- data/spec/web_spec.rb +4 -3
- data/spec/zeromq_spec.rb +32 -0
- metadata +5 -4
data/Gemfile
CHANGED
data/lib/ramon/configuration.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Ramon
|
2
2
|
class Configuration
|
3
3
|
class ConfigurationException < StandardError; end
|
4
|
-
OPTIONS = [:app_key, :
|
4
|
+
OPTIONS = [:app_key, :address, :secret, :protocol,
|
5
5
|
:environment_name, :framework, :project_root].freeze
|
6
6
|
|
7
7
|
# The Aplication key. Only in Amon Plus.
|
@@ -11,7 +11,7 @@ module Ramon
|
|
11
11
|
attr_accessor :secret
|
12
12
|
|
13
13
|
# The host to connect to (defaults to 127.0.0.1).
|
14
|
-
attr_accessor :
|
14
|
+
attr_accessor :address
|
15
15
|
|
16
16
|
# The port on which your Amon instance runs. Defaults to 2464
|
17
17
|
attr_accessor :port
|
@@ -28,12 +28,15 @@ module Ramon
|
|
28
28
|
# The logger used by Amon
|
29
29
|
attr_accessor :logger
|
30
30
|
|
31
|
+
# The name of the procotol used to log data - (http/zeromq)
|
32
|
+
attr_accessor :protocol
|
33
|
+
|
31
34
|
def initialize
|
32
|
-
@
|
33
|
-
@port = 2464
|
35
|
+
@address = 'http://127.0.0.1:2464'
|
34
36
|
@app_key = ''
|
35
37
|
@secret = ''
|
36
38
|
@framework = 'Standalone'
|
39
|
+
@protocol = 'http'
|
37
40
|
end
|
38
41
|
|
39
42
|
|
data/lib/ramon/sender.rb
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'json'
|
3
3
|
require 'zlib'
|
4
|
+
begin
|
5
|
+
require 'zmq'
|
6
|
+
rescue LoadError
|
7
|
+
end
|
4
8
|
|
5
9
|
module Ramon
|
6
10
|
class Sender
|
7
11
|
def initialize(options = {})
|
8
|
-
[ :
|
9
|
-
:
|
12
|
+
[ :address,
|
13
|
+
:protocol,
|
10
14
|
:app_key,
|
11
15
|
:secret
|
12
16
|
].each do |option|
|
@@ -14,9 +18,8 @@ module Ramon
|
|
14
18
|
end
|
15
19
|
end
|
16
20
|
|
17
|
-
|
18
|
-
|
19
|
-
:port,
|
21
|
+
attr_reader :address,
|
22
|
+
:protocol,
|
20
23
|
:app_key,
|
21
24
|
:secret
|
22
25
|
|
@@ -31,11 +34,11 @@ module Ramon
|
|
31
34
|
|
32
35
|
|
33
36
|
def url
|
34
|
-
URI.parse("#{
|
37
|
+
URI.parse("#{address}/api/")
|
35
38
|
end
|
36
39
|
|
37
|
-
def
|
38
|
-
|
40
|
+
def post_http(type, data = {})
|
41
|
+
|
39
42
|
if type == 'log'
|
40
43
|
@url = "#{url}log/#{app_key}"
|
41
44
|
else
|
@@ -49,7 +52,7 @@ module Ramon
|
|
49
52
|
response = Net::HTTP.new(url.host, url.port).start {|http| http.request(request) }
|
50
53
|
case response
|
51
54
|
when Net::HTTPSuccess
|
52
|
-
log :
|
55
|
+
log :info, "#{@url} - #{response.message}"
|
53
56
|
return response
|
54
57
|
else
|
55
58
|
log :error, "#{@url} - #{response.code} - #{response.message}"
|
@@ -58,7 +61,33 @@ module Ramon
|
|
58
61
|
log :error, "[Ramon::Sender#post] Cannot send data to #{@url} Error: #{e.class} - #{e.message}"
|
59
62
|
nil
|
60
63
|
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def post_zeromq(type, data = {})
|
67
|
+
if defined?(ZMQ)
|
68
|
+
context = ZMQ::Context.new()
|
69
|
+
socket = context.socket(ZMQ::DEALER)
|
70
|
+
socket.connect("tcp://#{address}")
|
71
|
+
json_data = {:type => type,
|
72
|
+
:content => data}
|
73
|
+
if app_key
|
74
|
+
json_data['app_key'] = app_key
|
75
|
+
end
|
76
|
+
|
77
|
+
json_data = json_data.to_json
|
78
|
+
|
79
|
+
socket.send(json_data, ZMQ::NOBLOCK)
|
80
|
+
socket.close()
|
81
|
+
true
|
82
|
+
end
|
83
|
+
end
|
61
84
|
|
85
|
+
def post(type, data)
|
86
|
+
if protocol == 'zeromq'
|
87
|
+
post_zeromq(type, data)
|
88
|
+
elsif protocol == 'http'
|
89
|
+
post_http(type, data)
|
90
|
+
end
|
62
91
|
end
|
63
92
|
|
64
93
|
end # Class end
|
data/lib/ramon/version.rb
CHANGED
data/spec/config_spec.rb
CHANGED
@@ -5,8 +5,8 @@ describe Configuration do
|
|
5
5
|
|
6
6
|
it "should provide default values" do
|
7
7
|
config = Ramon::Configuration.new
|
8
|
-
config.
|
9
|
-
config.
|
8
|
+
config.address.should == 'http://127.0.0.1:2464'
|
9
|
+
config.protocol.should == 'http'
|
10
10
|
end
|
11
11
|
|
12
12
|
end
|
data/spec/web_spec.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require "logger"
|
2
3
|
|
3
4
|
module Ramon
|
4
5
|
# Works only when the Amon application is started
|
5
|
-
describe 'Web app test' do
|
6
|
+
describe 'Web app http test' do
|
6
7
|
|
7
8
|
it 'Test logging' do
|
8
9
|
|
9
10
|
Ramon.configure do |config|
|
10
|
-
config.
|
11
|
-
config.
|
11
|
+
config.address = 'http://127.0.0.1:2465'
|
12
|
+
config.logger = Logger.new(STDOUT)
|
12
13
|
end
|
13
14
|
|
14
15
|
Ramon.log([1,2,3,4]).response.code.should == "200"
|
data/spec/zeromq_spec.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require "logger"
|
3
|
+
|
4
|
+
module Ramon
|
5
|
+
# Works only when the AmonMQ server is started
|
6
|
+
describe 'Web app zeromq test' do
|
7
|
+
|
8
|
+
it 'Test ZeroMQ logging' do
|
9
|
+
|
10
|
+
Ramon.configure do |config|
|
11
|
+
config.address = '127.0.0.1:5464'
|
12
|
+
config.protocol = 'zeromq'
|
13
|
+
config.logger = Logger.new(STDOUT)
|
14
|
+
end
|
15
|
+
|
16
|
+
Ramon.log([1,2,3,4]).should == true
|
17
|
+
Ramon.log({:test => 'zeromq data', :more_test => 'more zeromq data'}).should == true
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'Test logging with multiple tags' do
|
21
|
+
Ramon.log("test zeromq", ['debug', 'benchmark']).should == true
|
22
|
+
Ramon.log({:test => 'data', :more_test => 'more_data'}, ['info','warning','user']).should == true
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
it 'Test Exceptions' do
|
27
|
+
Ramon.post('exception', {:url => 'test', :exception_class => 'test_me zeromq'}).should == true
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ramon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 1
|
10
|
+
version: 0.4.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- martinrusev
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-04-07 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- spec/rails_integration_spec.rb
|
63
63
|
- spec/spec_helper.rb
|
64
64
|
- spec/web_spec.rb
|
65
|
+
- spec/zeromq_spec.rb
|
65
66
|
has_rdoc: true
|
66
67
|
homepage: http://amon.cx
|
67
68
|
licenses: []
|