ramon 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/benchmarks.rb +23 -7
- data/lib/ramon/configuration.rb +5 -9
- data/lib/ramon/sender.rb +14 -16
- data/lib/ramon/version.rb +1 -1
- data/spec/web_spec.rb +1 -0
- metadata +4 -4
data/benchmarks.rb
CHANGED
@@ -5,23 +5,39 @@ require "logger"
|
|
5
5
|
require 'singleton'
|
6
6
|
require "zmq"
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
require 'net/http'
|
9
|
+
require 'json'
|
10
|
+
|
11
|
+
runs = 10
|
12
|
+
http_address = "http://127.0.0.1:2465"
|
13
|
+
key = "u6ljlx2glnf8xq45ut1etkpxghmjpe3e"
|
14
|
+
|
15
|
+
http_bench = true
|
16
|
+
zeromq_bench = false
|
17
|
+
standart_bench = false
|
13
18
|
|
14
19
|
puts "Runs: #{runs}"
|
15
20
|
|
21
|
+
#@post_path = "/api/log/#{key}"
|
22
|
+
#@url = URI.parse(http_address)
|
23
|
+
#@data = {"message" => 'ruby test' , "tags" => ['ruby']}.to_json
|
24
|
+
|
25
|
+
|
26
|
+
#req = Net::HTTP::Post.new(@post_path, initheader = {'Content-Type' =>'application/json'})
|
27
|
+
#req.body = @data
|
28
|
+
#response = Net::HTTP.new(@url.host, @url.port).start {|http| http.request(req) }
|
29
|
+
#puts "Response #{response.code} #{response.message}: #{response.body}"
|
30
|
+
|
16
31
|
if http_bench == true
|
17
32
|
Ramon.configure do |config|
|
18
33
|
config.address = http_address
|
19
|
-
config.
|
34
|
+
config.secret_key = "u6ljlx2glnf8xq45ut1etkpxghmjpe3e"
|
35
|
+
config.logger = Logger.new(STDOUT)
|
20
36
|
end
|
21
37
|
|
22
38
|
start_time = Time.now
|
23
39
|
(1..runs).each {
|
24
|
-
Ramon.log('test')
|
40
|
+
Ramon.log('ruby test')
|
25
41
|
}
|
26
42
|
end_time = Time.now
|
27
43
|
puts "HTTP logging #{(end_time - start_time)} seconds"
|
data/lib/ramon/configuration.rb
CHANGED
@@ -1,14 +1,11 @@
|
|
1
1
|
module Ramon
|
2
2
|
class Configuration
|
3
3
|
class ConfigurationException < StandardError; end
|
4
|
-
OPTIONS = [:
|
4
|
+
OPTIONS = [:secret_key, :address, :secret, :protocol,
|
5
5
|
:environment_name, :framework, :project_root].freeze
|
6
6
|
|
7
|
-
#
|
8
|
-
attr_accessor :
|
9
|
-
|
10
|
-
# Secret key, used for securely logging in the normal Amon version
|
11
|
-
attr_accessor :secret
|
7
|
+
# Secret key, used for securely logging
|
8
|
+
attr_accessor :secret_key
|
12
9
|
|
13
10
|
# The host to connect to (defaults to 127.0.0.1).
|
14
11
|
attr_accessor :address
|
@@ -32,9 +29,8 @@ module Ramon
|
|
32
29
|
attr_accessor :protocol
|
33
30
|
|
34
31
|
def initialize
|
35
|
-
@address
|
36
|
-
@
|
37
|
-
@secret = ''
|
32
|
+
@address = 'http://127.0.0.1:2464'
|
33
|
+
@secret_key = ''
|
38
34
|
@framework = 'Standalone'
|
39
35
|
@protocol = 'http'
|
40
36
|
end
|
data/lib/ramon/sender.rb
CHANGED
@@ -7,20 +7,16 @@ module Ramon
|
|
7
7
|
def initialize(options = {})
|
8
8
|
[ :address,
|
9
9
|
:protocol,
|
10
|
-
:
|
11
|
-
:secret
|
10
|
+
:secret_key
|
12
11
|
].each do |option|
|
13
12
|
instance_variable_set("@#{option}", options[option])
|
14
13
|
end
|
15
14
|
end
|
16
15
|
|
17
|
-
attr_reader :address,
|
18
|
-
:protocol,
|
19
|
-
:app_key,
|
20
|
-
:secret
|
16
|
+
attr_reader :address, :protocol, :secret_key
|
21
17
|
|
22
18
|
def log(level, message)
|
23
|
-
logger.send level, '
|
19
|
+
logger.send level, ''+ message
|
24
20
|
end
|
25
21
|
|
26
22
|
|
@@ -30,31 +26,32 @@ module Ramon
|
|
30
26
|
|
31
27
|
|
32
28
|
def url
|
33
|
-
URI.parse("#{address}
|
29
|
+
URI.parse("#{address}")
|
34
30
|
end
|
35
31
|
|
36
32
|
def post_http(type, data = {})
|
37
33
|
|
38
34
|
if type == 'log'
|
39
|
-
@
|
35
|
+
@path = "/api/log/#{secret_key}"
|
40
36
|
else
|
41
|
-
@
|
37
|
+
@path = "/api/exception/#{secret_key}"
|
42
38
|
end
|
43
39
|
|
44
|
-
request = Net::HTTP::Post.new(@
|
40
|
+
request = Net::HTTP::Post.new(@path, initheader = {'Content-Type' =>'application/json'})
|
45
41
|
request.body = data.to_json
|
46
42
|
|
47
43
|
begin
|
48
44
|
response = Net::HTTP.new(url.host, url.port).start {|http| http.request(request) }
|
45
|
+
|
49
46
|
case response
|
50
47
|
when Net::HTTPSuccess
|
51
|
-
log :info, "#{
|
48
|
+
log :info, "#{url}#{@path} - #{response.message}"
|
52
49
|
return response
|
53
50
|
else
|
54
|
-
log :error, "#{
|
51
|
+
log :error, "#{url}#{@path} - #{response.code} - #{response.message}"
|
55
52
|
end
|
56
53
|
rescue Exception => e
|
57
|
-
log :error, "[Ramon::Sender#post] Cannot send data to #{
|
54
|
+
log :error, "[Ramon::Sender#post] Cannot send data to #{url}#{@path} Error: #{e.class} - #{e.message}"
|
58
55
|
nil
|
59
56
|
end
|
60
57
|
end
|
@@ -62,8 +59,9 @@ module Ramon
|
|
62
59
|
def post_zeromq(type, data = {})
|
63
60
|
if defined?(ZMQ)
|
64
61
|
json_data = {:type => type, :content => data}
|
65
|
-
|
66
|
-
|
62
|
+
|
63
|
+
if secret_key
|
64
|
+
json_data['secret_key'] = secret_key
|
67
65
|
end
|
68
66
|
|
69
67
|
json_data = json_data.to_json
|
data/lib/ramon/version.rb
CHANGED
data/spec/web_spec.rb
CHANGED
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: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 4
|
10
|
+
version: 0.4.4
|
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-08-10 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: json
|