Class: Sensu::Extension::ConnectionHandler
- Inherits:
-
EM::Connection
- Object
- EM::Connection
- Sensu::Extension::ConnectionHandler
- Defined in:
- lib/sensu/extensions/graphite.rb
Overview
Connection Handler
Constant Summary collapse
- MAX_RECONNECT_ATTEMPTS =
XXX: These should be runtime configurable.
0
- MAX_RECONNECT_TIME =
Attempt no reconnects. Drop if it can’t in favor for speed.
0
Instance Attribute Summary collapse
-
#connected ⇒ Object
Returns the value of attribute connected.
-
#connection_pool ⇒ Object
seconds.
-
#host ⇒ Object
Returns the value of attribute host.
-
#message_queue ⇒ Object
seconds.
-
#name ⇒ Object
Returns the value of attribute name.
-
#port ⇒ Object
Returns the value of attribute port.
-
#reconnect_timer ⇒ Object
Returns the value of attribute reconnect_timer.
Instance Method Summary collapse
- #close_connection(*args) ⇒ Object
- #comm_inactivity_timeout ⇒ Object
- #connection_completed ⇒ Object
- #get_reconnect_time ⇒ Object
- #logger ⇒ Object
-
#post_init ⇒ Object
ignore :reek:TooManyStatements.
-
#receive_data(data) ⇒ Object
Override EM::Connection.receive_data to prevent it from calling puts and randomly logging non-sense to sensu-server.log.
-
#reconnect(time) ⇒ Object
Reconnect normally attempts to connect at the end of the tick Delay the reconnect for some seconds.
- #schedule_reconnect ⇒ Object
- #send_data(*args) ⇒ Object
- #unbind ⇒ Object
Instance Attribute Details
#connected ⇒ Object
Returns the value of attribute connected.
43 44 45 |
# File 'lib/sensu/extensions/graphite.rb', line 43 def connected @connected end |
#connection_pool ⇒ Object
seconds
42 43 44 |
# File 'lib/sensu/extensions/graphite.rb', line 42 def connection_pool @connection_pool end |
#host ⇒ Object
Returns the value of attribute host.
43 44 45 |
# File 'lib/sensu/extensions/graphite.rb', line 43 def host @host end |
#message_queue ⇒ Object
seconds
42 43 44 |
# File 'lib/sensu/extensions/graphite.rb', line 42 def @message_queue end |
#name ⇒ Object
Returns the value of attribute name.
43 44 45 |
# File 'lib/sensu/extensions/graphite.rb', line 43 def name @name end |
#port ⇒ Object
Returns the value of attribute port.
43 44 45 |
# File 'lib/sensu/extensions/graphite.rb', line 43 def port @port end |
#reconnect_timer ⇒ Object
Returns the value of attribute reconnect_timer.
44 45 46 |
# File 'lib/sensu/extensions/graphite.rb', line 44 def reconnect_timer @reconnect_timer end |
Instance Method Details
#close_connection(*args) ⇒ Object
60 61 62 63 64 |
# File 'lib/sensu/extensions/graphite.rb', line 60 def close_connection(*args) @is_closed = true @connected = false super(*args) end |
#comm_inactivity_timeout ⇒ Object
66 67 68 69 |
# File 'lib/sensu/extensions/graphite.rb', line 66 def comm_inactivity_timeout logger.info("Graphite: Connection to #{@name} timed out.") schedule_reconnect end |
#connection_completed ⇒ Object
56 57 58 |
# File 'lib/sensu/extensions/graphite.rb', line 56 def connection_completed @connected = true end |
#get_reconnect_time ⇒ Object
97 98 99 100 101 102 |
# File 'lib/sensu/extensions/graphite.rb', line 97 def get_reconnect_time @reconnect_timer.get_reconnect_time( @max_reconnect_time, @connection_attempt_count ) end |
#logger ⇒ Object
114 115 116 |
# File 'lib/sensu/extensions/graphite.rb', line 114 def logger Sensu::Logger.get end |
#post_init ⇒ Object
ignore :reek:TooManyStatements
47 48 49 50 51 52 53 54 |
# File 'lib/sensu/extensions/graphite.rb', line 47 def post_init @is_closed = false @connection_attempt_count = 0 @max_reconnect_time = MAX_RECONNECT_TIME @comm_inactivity_timeout = 0 # disable inactivity timeout @pending_connect_timeout = 30 # seconds @reconnect_timer = ExponentialDecayTimer.new end |
#receive_data(data) ⇒ Object
Override EM::Connection.receive_data to prevent it from calling puts and randomly logging non-sense to sensu-server.log
85 86 |
# File 'lib/sensu/extensions/graphite.rb', line 85 def receive_data(data) end |
#reconnect(time) ⇒ Object
Reconnect normally attempts to connect at the end of the tick Delay the reconnect for some seconds.
90 91 92 93 94 95 |
# File 'lib/sensu/extensions/graphite.rb', line 90 def reconnect(time) EM.add_timer(time) do logger.info("Graphite: Attempting to reconnect relay channel: #{@name}.") super(@host, @port) end end |
#schedule_reconnect ⇒ Object
104 105 106 107 108 109 110 111 112 |
# File 'lib/sensu/extensions/graphite.rb', line 104 def schedule_reconnect unless @connected @connection_attempt_count += 1 reconnect_time = get_reconnect_time logger.info("Graphite: Scheduling reconnect in #{@reconnect_time} seconds for relay channel: #{@name}.") reconnect(reconnect_time) end reconnect_time end |
#send_data(*args) ⇒ Object
79 80 81 |
# File 'lib/sensu/extensions/graphite.rb', line 79 def send_data(*args) super(*args) end |
#unbind ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/sensu/extensions/graphite.rb', line 71 def unbind @connected = false unless @is_closed logger.info('Graphite: Connection closed unintentionally.') schedule_reconnect end end |