haproxy2rpm 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -30,3 +30,12 @@ Tell haproxy to log to syslog. e.g:
30
30
  * Apdex
31
31
  * Histogram
32
32
  * Web transactions
33
+
34
+ ## Known issues
35
+
36
+ * Seems to stall after some time running
37
+ * Do not run with --daemonize when used inside monit.rc
38
+
39
+ ## Roadmap
40
+
41
+ * Improved logging and debugging (-l, --log)
data/bin/haproxy2rpm CHANGED
@@ -4,17 +4,20 @@ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
4
4
 
5
5
  require 'rubygems'
6
6
  require 'optparse'
7
+ require 'logger'
7
8
 
8
9
  options = {
9
10
  :daemonize => false,
10
11
  :version => false,
11
12
  :syslog => false,
12
13
  :port => 3333,
13
- :listen => '0.0.0.0'
14
+ :address => '0.0.0.0',
15
+ :log_to => STDOUT,
16
+ :log_level => Logger::INFO
14
17
  }
15
18
 
16
19
  opts = OptionParser.new do |opts|
17
- opts.on("-D", "--daemonize", "Daemonize") do
20
+ opts.on("-d", "--daemonize", "Daemonize") do
18
21
  options[:daemonize] = true
19
22
  end
20
23
 
@@ -22,8 +25,8 @@ opts = OptionParser.new do |opts|
22
25
  options[:syslog] = true
23
26
  end
24
27
 
25
- opts.on("-lIP", "--listen IP", "Set IP to listen on") do |ip|
26
- options[:listen] = ip
28
+ opts.on("-aHOST", "--address HOST", "Set host address to listen on") do |host|
29
+ options[:address] = host
27
30
  end
28
31
 
29
32
  opts.on("-pPORT", "--port PORT", "Set port to listen on") do |port|
@@ -38,6 +41,19 @@ opts = OptionParser.new do |opts|
38
41
  options[:env] = env
39
42
  end
40
43
 
44
+ opts.on("-PFILE", "--pid FILE", "specify Pid file") do |file|
45
+ options[:pid] = file
46
+ end
47
+
48
+ opts.on("-lFILE", "--log FILE", "File to redirect output") do |file|
49
+ options[:log_to] = File.open(file, 'a')
50
+ options[:log_to].sync = true
51
+ end
52
+
53
+ opts.on("-D", "--debug", "verbose logging") do
54
+ options[:log_level] = Logger::DEBUG
55
+ end
56
+
41
57
  opts.on_tail("-h", "--help", "Show this message") do
42
58
  puts opts
43
59
  exit
@@ -52,6 +68,10 @@ opts.parse!
52
68
 
53
69
  require 'haproxy2rpm'
54
70
 
71
+
72
+ Haproxy2Rpm.logger = Logger.new(options[:log_to])
73
+ Haproxy2Rpm.logger.level = options[:log_level]
74
+
55
75
  log_file = ARGV[0] || ''
56
76
 
57
77
  if(options[:version])
@@ -1,7 +1,7 @@
1
1
  module Haproxy2Rpm
2
2
  class Rpm
3
3
  def initialize(options = {})
4
- agent_options = {}
4
+ agent_options = {:log => Haproxy2Rpm.logger}
5
5
  agent_options[:app_name] = options[:app_name] if options[:app_name]
6
6
  agent_options[:env] = options[:env] if options[:env]
7
7
  NewRelic::Agent.manual_start agent_options
@@ -21,7 +21,9 @@ module Haproxy2Rpm
21
21
  end
22
22
 
23
23
  NewRelic::Agent.record_transaction(request.tr / 1000.0, params)
24
- @qt_stat.record_data_point(request.tw / 1000.0)
24
+ Haproxy2Rpm.logger.debug "RECORDING (transaction): #{params.inspect}"
25
+ result = @qt_stat.record_data_point(request.tw / 1000.0)
26
+ Haproxy2Rpm.logger.debug "RECORDING (data point): wait time #{request.tw}, #{result.inspect}"
25
27
  end
26
28
  end
27
29
  end
@@ -8,7 +8,9 @@ module Haproxy2Rpm
8
8
 
9
9
  def receive_data(data)
10
10
  message_start_index = data.index('haproxy')
11
- @rpm.process_and_send(data[message_start_index..-1])
11
+ message = data[message_start_index..-1]
12
+ Haproxy2Rpm.logger.debug "RECEIVED (syslog): #{message}"
13
+ @rpm.process_and_send(message)
12
14
  end
13
15
  end
14
16
  end
@@ -1,3 +1,3 @@
1
1
  module Haproxy2Rpm
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/haproxy2rpm.rb CHANGED
@@ -10,10 +10,15 @@ require "haproxy2rpm/syslog"
10
10
  require "haproxy2rpm/rpm"
11
11
 
12
12
  module Haproxy2Rpm
13
+
14
+ class << self
15
+ attr_accessor :logger
16
+ end
17
+
13
18
  def self.run(log_file, options)
14
19
  @rpm = Rpm.new(options)
15
20
  if(options[:daemonize])
16
- puts 'daemonizing'
21
+ logger.info 'daemonizing'
17
22
  run_daemonized(log_file, options)
18
23
  else
19
24
  if(options[:syslog])
@@ -25,13 +30,13 @@ module Haproxy2Rpm
25
30
  end
26
31
 
27
32
  def self.stop
28
- puts 'stopping new relic agent'
33
+ logger.info 'stopping new relic agent'
29
34
  NewRelic::Agent.shutdown
30
35
  end
31
36
 
32
37
  def self.run_syslog_server(options)
33
38
  EventMachine::run do
34
- EventMachine::open_datagram_socket(options[:listen], options[:port], SyslogHandler)
39
+ EventMachine::open_datagram_socket(options[:address], options[:port], SyslogHandler)
35
40
  end
36
41
  end
37
42
 
@@ -54,8 +59,8 @@ module Haproxy2Rpm
54
59
  default_run(log_file, options)
55
60
  end
56
61
  rescue => e
57
- puts e.message
58
- puts e.backtrace.join("\n")
62
+ logger.error e.message
63
+ logger.error e.backtrace.join("\n")
59
64
  abort "There was a fatal system error while starting haproxy2rpm"
60
65
  end
61
66
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haproxy2rpm
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Patrick Huesler
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-07-11 00:00:00 +02:00
19
+ date: 2011-07-12 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency