ramon 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,23 +5,39 @@ require "logger"
5
5
  require 'singleton'
6
6
  require "zmq"
7
7
 
8
- runs = 10000
9
- http_address = 'http://127.0.0.1:2464'
10
- http_bench = false
11
- zeromq_bench = true
12
- standart_bench = true
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.logger = Logger.new("/dev/null")
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"
@@ -1,14 +1,11 @@
1
1
  module Ramon
2
2
  class Configuration
3
3
  class ConfigurationException < StandardError; end
4
- OPTIONS = [:app_key, :address, :secret, :protocol,
4
+ OPTIONS = [:secret_key, :address, :secret, :protocol,
5
5
  :environment_name, :framework, :project_root].freeze
6
6
 
7
- # The Aplication key. Only in Amon Plus.
8
- attr_accessor :app_key
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 = 'http://127.0.0.1:2464'
36
- @app_key = ''
37
- @secret = ''
32
+ @address = 'http://127.0.0.1:2464'
33
+ @secret_key = ''
38
34
  @framework = 'Standalone'
39
35
  @protocol = 'http'
40
36
  end
@@ -7,20 +7,16 @@ module Ramon
7
7
  def initialize(options = {})
8
8
  [ :address,
9
9
  :protocol,
10
- :app_key,
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, '** Amon '+ message
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}/api/")
29
+ URI.parse("#{address}")
34
30
  end
35
31
 
36
32
  def post_http(type, data = {})
37
33
 
38
34
  if type == 'log'
39
- @url = "#{url}log/#{app_key}"
35
+ @path = "/api/log/#{secret_key}"
40
36
  else
41
- @url = "#{url}exception/#{app_key}"
37
+ @path = "/api/exception/#{secret_key}"
42
38
  end
43
39
 
44
- request = Net::HTTP::Post.new(@url, initheader = {'Content-Type' =>'application/json'})
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, "#{@url} - #{response.message}"
48
+ log :info, "#{url}#{@path} - #{response.message}"
52
49
  return response
53
50
  else
54
- log :error, "#{@url} - #{response.code} - #{response.message}"
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 #{@url} Error: #{e.class} - #{e.message}"
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
- if app_key
66
- json_data['app_key'] = app_key
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
@@ -1,3 +1,3 @@
1
1
  module Ramon
2
- VERSION = "0.4.3"
2
+ VERSION = "0.4.4"
3
3
  end
@@ -9,6 +9,7 @@ module Ramon
9
9
 
10
10
  Ramon.configure do |config|
11
11
  config.address = 'http://127.0.0.1:2465'
12
+ config.secret_key = "u6ljlx2glnf8xq45ut1etkpxghmjpe3e"
12
13
  config.logger = Logger.new(STDOUT)
13
14
  end
14
15
 
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: 9
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 3
10
- version: 0.4.3
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-04-27 00:00:00 Z
18
+ date: 2012-08-10 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: json