@@ -20,6 +20,9 @@ class RabbitMQ(base.Plugin):
2020 DEFAULT_HOST = 'localhost'
2121 DEFAULT_PORT = 80
2222 DEFAULT_API_PATH = '/api'
23+ # support standard requests timeout values: (connect, read) or single value for both
24+ # http://docs.python-requests.org/en/master/user/advanced/#timeouts
25+ DEFAULT_TIMEOUT = (3.05 , 30 )
2326
2427 DUMMY_STATS = {'ack' : 0 ,
2528 'deliver' : 0 ,
@@ -221,8 +224,8 @@ def add_queue_datapoints(self, queue_data):
221224
222225 """
223226 count = 0
224- available , consumers , deliver , publish , redeliver , unacked = \
225- 0 , 0 , 0 , 0 , 0 , 0
227+ available , deliver , publish , redeliver , unacked = \
228+ 0 , 0 , 0 , 0 , 0
226229 for count , queue in enumerate (queue_data ):
227230 if queue ['name' ][0 :7 ] == 'amq.gen' :
228231 LOGGER .debug ('Skipping auto-named queue: %s' , queue ['name' ])
@@ -290,18 +293,23 @@ def http_get(self, url, params=None):
290293 :param dict params: Get query string parameters
291294
292295 """
293- kwargs = {'url' : url ,
294- 'auth' : (self .config .get ('username' , self .DEFAULT_USER ),
295- self .config .get ('password' , self .DEFAULT_PASSWORD )),
296- 'verify' : self .config .get ('verify_ssl_cert' , True )}
296+ kwargs = {
297+ 'url' : url ,
298+ 'auth' : (self .config .get ('username' , self .DEFAULT_USER ),
299+ self .config .get ('password' , self .DEFAULT_PASSWORD )),
300+ 'verify' : self .config .get ('verify_ssl_cert' , True ),
301+ 'timeout' : self .config .get ('timeout' , self .DEFAULT_TIMEOUT )
302+ }
303+ if isinstance (kwargs ['timeout' ], list ):
304+ # convert list to tuple form
305+ kwargs ['timeout' ] = tuple (kwargs ['timeout' ])
297306 if params :
298307 kwargs ['params' ] = params
299308
300- try :
301- return self .requests_session .get (** kwargs )
302- except requests .ConnectionError as error :
303- LOGGER .error ('Error fetching data from %s: %s' , url , error )
304- return None
309+ s = time .time ()
310+ r = self .requests_session .get (** kwargs )
311+ LOGGER .debug ('%s took %.2f seconds' , url , time .time () - s )
312+ return r
305313
306314 def fetch_data (self , data_type , columns = None ):
307315 """Fetch the data from the RabbitMQ server for the specified data type
@@ -362,16 +370,24 @@ def poll(self):
362370 self .rate = dict ()
363371 self .consumers = 0
364372
365- # Fetch the data from RabbitMQ
366- channel_data = self .fetch_channel_data ()
367- node_data = self .fetch_node_data ()
368- queue_data = self .fetch_queue_data ()
369-
370- # Create all of the metrics
371- self .add_queue_datapoints (queue_data )
372- self .add_node_datapoints (node_data , queue_data , channel_data )
373- LOGGER .info ('Polling complete in %.2f seconds' ,
374- time .time () - start_time )
373+ try :
374+ # Fetch the data from RabbitMQ
375+ channel_data = self .fetch_channel_data ()
376+ node_data = self .fetch_node_data ()
377+ queue_data = self .fetch_queue_data ()
378+
379+ # Create all of the metrics
380+ self .add_queue_datapoints (queue_data )
381+ self .add_node_datapoints (node_data , queue_data , channel_data )
382+ LOGGER .info ('Polling complete in %.2f seconds' ,
383+ time .time () - start_time )
384+
385+ except requests .exceptions .RequestException as error :
386+ LOGGER .error ('Polling failed after %.2f seconds' ,
387+ time .time () - start_time , extra = {"error" : error })
388+ except Exception :
389+ LOGGER .exception ('Polling failed after %.2f seconds' ,
390+ time .time () - start_time )
375391
376392 @property
377393 def rabbitmq_base_url (self ):
0 commit comments