wdstorer / speedtest-exporter

Prometheus exporter for speedtest-cli
4 stars 3 forks source link

Process crashed after several days of work #1

Open widgetii opened 6 years ago

widgetii commented 6 years ago

Hello, thank you for wonderful tool!

I've added your great program to our monitoring system for check metrics of our 4G wireless link and today found that it crashed at night. It seems that it would be very helpful to add some exception handling in case of connection errors in speedtest library.

13004748.3156
837615.98368                                                                                                                          
14524592.5378                                                                                                                         
1558531.87772                                                                                                                         
3319399.65134                                                                                                                         
1462846.98004                                                                                                                         
13033611.358                                                                                                                          
502204.085212                                                                                                                         
11905193.2834                                                                                                                         
Exception in thread Thread-115155:                                                                                                    
Traceback (most recent call last):                                                                                                    
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner                                                              
    self.run()                                                                                                                        
  File "/usr/lib/python2.7/site-packages/speedtest.py", line 841, in run                                                              
    f = self._opener(request)                                                                                                         
  File "/usr/lib/python2.7/urllib2.py", line 429, in open                                                                             
    response = self._open(req, data)                                                                                                  
  File "/usr/lib/python2.7/urllib2.py", line 447, in _open                                                                            
    '_open', req)                                                                                                                     
  File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain                                                                      
    result = func(*args)                                                                                                              
  File "/usr/lib/python2.7/site-packages/speedtest.py", line 482, in http_open                                                        
    req                                                                                                                               
  File "/usr/lib/python2.7/urllib2.py", line 1201, in do_open                                                                         
    r = h.getresponse(buffering=True)                                                                                                 
  File "/usr/lib/python2.7/httplib.py", line 1121, in getresponse                                                                     
    response.begin()                                                                                                                  
  File "/usr/lib/python2.7/httplib.py", line 438, in begin                                                                            
    version, status, reason = self._read_status()
  File "/usr/lib/python2.7/httplib.py", line 402, in _read_status
    raise BadStatusLine(line)
BadStatusLine: ''

Traceback (most recent call last):                                                                                                    
  File "./run-speedtest.py", line 36, in <module>                                                                                     
    process_request(60)                                                                                                               
  File "./run-speedtest.py", line 23, in process_request                                                                              
    s.upload()                                                                                                                        
  File "/usr/lib/python2.7/site-packages/speedtest.py", line 1574, in upload
    self.results.bytes_sent = sum(finished)
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
widgetii commented 6 years ago

Another crash but with different error:

21544208.3613
17802934.9623
7903060.24112
31066550.4245
21125041.9053
Traceback (most recent call last):
  File "./run-speedtest.py", line 36, in <module>
    process_request(60)
  File "./run-speedtest.py", line 20, in process_request
    s.get_servers(servers)
  File "/usr/lib/python2.7/site-packages/speedtest.py", line 1212, in get_servers
    stream = get_response_stream(uh)
  File "/usr/lib/python2.7/site-packages/speedtest.py", line 687, in get_response_stream
    return GzipDecodedResponse(response)
  File "/usr/lib/python2.7/site-packages/speedtest.py", line 565, in __init__
    chunk = response.read(1024)
  File "/usr/lib/python2.7/socket.py", line 384, in read
    data = self._sock.recv(left)
  File "/usr/lib/python2.7/httplib.py", line 597, in read
    s = self.fp.read(amt)
  File "/usr/lib/python2.7/socket.py", line 384, in read
    data = self._sock.recv(left)
socket.timeout: timed out
wdstorer commented 5 years ago

So sorry for missing this @widgetii ! Thanks a lot for the kind words and useful feedback. You're probably not using this anymore but I've pushed up a new version with error handling for the two exceptions you mentioned.