[WORKER] Fix unreported stats carry over bug
If HAProxy was restarted more than once before delivering a STATS response, we were not carrying over the unreported total properly. This fixes that. Also add some more logging to assist in finding statistics bugs. Change-Id: If2e1ef8d0d473e2fb9554a9dc89219086e80e55a
This commit is contained in:
@@ -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):
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user