Module: Opstat::Client
- Extended by:
- Logging
- Defined in:
- lib/opstat-client/client.rb
Class Method Summary collapse
Methods included from Logging
log_level, oplogger, preconfig_logger
Class Method Details
.main_loop ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/opstat-client/client.rb', line 49 def self.main_loop oplogger.info 'Starting client main loop' queue = EM::Queue.new mq_config = Opstat::Config.instance.get_mq_config send_data_interval = Opstat::Config.instance.get('client')['send_data_interval'] @a_plugins = Opstat::Plugins.create_plugins(queue) EventMachine::run do AMQP.start(mq_config) do |connection| connection.on_tcp_connection_loss do |conn, settings| oplogger.warn "[network failure] Trying to reconnect..." conn.reconnect(false, 2) end oplogger.info "Connecting to AMQP broker. Running #{AMQP::VERSION} version of the gem..." channel = AMQP::Channel.new(connection,:auto_recovery => true) channel.on_error do |ch, channel_close| oplogger.error "AMQP channel error" raise channel_close.reply_text end ampqqueue = channel.queue(mq_config['queue_name'], :auto_delete => false, :durable => true) exchange = channel.default_exchange @a_plugins.each do |task| if task.external_plugin_needed? task.set_external_plugin = EventMachine::open_datagram_socket task.external_plugin['address'], task.external_plugin['port'], Opstat::Plugins::UDPExternalPlugins::Apache2, task.external_plugin end EventMachine::add_periodic_timer(task.interval) {task.parse_and_queue} end EventMachine::add_periodic_timer(send_data_interval) { Opstat::SendData.send_from_queue(queue, exchange, ampqqueue.name) } end end #EventMachine::run do end |