diff --git a/libra/worker/drivers/haproxy/stats.py b/libra/worker/drivers/haproxy/stats.py index 4238d964..ea433cd1 100644 --- a/libra/worker/drivers/haproxy/stats.py +++ b/libra/worker/drivers/haproxy/stats.py @@ -16,6 +16,10 @@ import datetime import os.path import simplejson +from libra.openstack.common import log + +LOG = log.getLogger(__name__) + class StatisticsManager(object): """ @@ -102,6 +106,7 @@ class StatisticsManager(object): self.UNREPORTED_TCP_BYTES_FIELD: unreported_tcp_bytes, self.UNREPORTED_HTTP_BYTES_FIELD: unreported_http_bytes } + LOG.debug("Saving statistics: %s" % obj) self._do_save(obj) def read(self): diff --git a/libra/worker/drivers/haproxy/ubuntu_services.py b/libra/worker/drivers/haproxy/ubuntu_services.py index c15c3bb5..a7386b93 100644 --- a/libra/worker/drivers/haproxy/ubuntu_services.py +++ b/libra/worker/drivers/haproxy/ubuntu_services.py @@ -55,6 +55,8 @@ class UbuntuServices(services_base.ServicesBase): tcp_bo = stats_mgr.get_last_tcp_bytes() http_bo = stats_mgr.get_last_http_bytes() + unrpt_tcp_bo = stats_mgr.get_unreported_tcp_bytes() + unrpt_http_bo = stats_mgr.get_unreported_http_bytes() curr_tcp_bo = 0 curr_http_bo = 0 @@ -63,6 +65,11 @@ class UbuntuServices(services_base.ServicesBase): if 'http' in results: curr_http_bo = results['http'] + # If we have unreported totals, then we haven't received a STATS + # call since the last restart and we need to carry over those totals. + curr_tcp_bo += unrpt_tcp_bo + curr_http_bo += unrpt_http_bo + stats_mgr.save(start, end, tcp_bytes=tcp_bo, http_bytes=http_bo, @@ -272,12 +279,14 @@ class UbuntuServices(services_base.ServicesBase): incremental_results = [] if 'http' in results: - incremental_results.append( - ('http', unrpt_http_bo + current_http_bo - prev_http_bo) - ) + value = unrpt_http_bo + current_http_bo - prev_http_bo + if value < 0: + LOG.error("Negative statistics value: %d" % value) + incremental_results.append(('http', value)) if 'tcp' in results: - incremental_results.append( - ('tcp', unrpt_tcp_bo + current_tcp_bo - prev_tcp_bo) - ) + value = unrpt_tcp_bo + current_tcp_bo - prev_tcp_bo + if value < 0: + LOG.error("Negative statistics value: %d" % value) + incremental_results.append(('tcp', value)) return str(new_start), str(new_end), incremental_results