Emonhub: problem with Apache server on shared host linux

Hello

My provider told me they restart their Apache servers at around Midnight every day.
The consequence is that the emonhub_reporter.py script is throwing an exception which looks like this message:

2015-06-25 23:59:12,212 WARNING <server name> couldn't send to server, URLError:
[Errno 111] Connection refused
2015-06-25 23:59:12,214 WARNING <server name> send failure: wanted 'ok' but got ''

I digged a bit in the code and would like your advise before I update it.
There is a timeout of 60 secs if there is no response.
Can I just increase that time and put 120 or something like that?
Is there any other and better solution?

        reply = ""
        request = urllib2.Request(post_url, post_body)
        try:
            response = urllib2.urlopen(request, timeout=60)
        except urllib2.HTTPError as e:
            self._log.warning(self.name + " couldn't send to server, HTTPError: " +
                              str(e.code))
        except urllib2.URLError as e:
            self._log.warning(self.name + " couldn't send to server, URLError: " +
                              str(e.reason))
        except httplib.HTTPException:
            self._log.warning(self.name + " couldn't send to server, HTTPException")
        except Exception:
            import traceback
            self._log.warning(self.name + " couldn't send to server, Exception: " +
                              traceback.format_exc())
        else:
            reply = response.read()
        finally:
            return reply
            

Thanks for your support

Walter

pb66's picture

Re: Emonhub: problem with Apache server on shared host linux

Is this a problem? ie does emonhub "throw an exception"? I see an exception being raised to accurately handle the fact that the server isn't responding and a log message being recorded so you know what has happened.

You could certainly try extending the timeout if you want to, i don't think that would cause any issues but how long does it take for their servers to restart? is 120secs definitely always going to be long enough?

if emonhub cannot deliver the data 1st time it will just keep trying until it can so you shouldn't lose any data.

Paul

daturach's picture

Re: Emonhub: problem with Apache server on shared host linux

This is my last log (extract):

2015-06-28 23:59:11,464 WARNING <server name> couldn't send to server, 
URLError: [Errno 111] Connection refused
2015-06-28 23:59:11,467 WARNING <server name> send failure: wanted 'ok' but got ''
etc.. until
2015-06-28 23:59:14,958 WARNING <server name> couldn't send to server, 
URLError: [Errno 111] Connection refused
2015-06-28 23:59:14,961 WARNING <server name> send failure: wanted 'ok' but got ''

I can assume it took 3.3 secs to restart the Apache server. I think I will leave the script as it is.

Thanks for your help.

Walter

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.