diff --git a/doc/worker/messages.rst b/doc/worker/messages.rst index 0d79a814..627b489d 100644 --- a/doc/worker/messages.rst +++ b/doc/worker/messages.rst @@ -31,11 +31,11 @@ Required Fields ^^^^^^^^^^^^^^^ * hpcs_action -* loadbalancers -* loadbalancers.protocol -* loadbalancers.nodes -* loadbalancers.nodes.address -* loadbalancers.nodes.port +* loadBalancers +* loadBalancers.protocol +* loadBalancers.nodes +* loadBalancers.nodes.address +* loadBalancers.nodes.port Example Request ^^^^^^^^^^^^^^^ @@ -44,7 +44,7 @@ Example Request { "hpcs_action": "UPDATE", - "loadbalancers": [ + "loadBalancers": [ { "name": "a-new-loadbalancer", "protocol": "http", @@ -66,7 +66,7 @@ Example Response { "hpcs_action": "UPDATE", - "loadbalancers": [ + "loadBalancers": [ { "name": "a-new-loadbalancer", "protocol": "http", @@ -271,8 +271,8 @@ Required Fields * hpcs_object_store_basepath * hpcs_object_store_endpoint * hpcs_object_store_token -* loadbalancers -* loadbalancers.protocol +* loadBalancers +* loadBalancers.protocol Example Request ^^^^^^^^^^^^^^^ @@ -285,7 +285,7 @@ Example Request "hpcs_object_store_endpoint": "https://example.com/v1/100", "hpcs_object_store_token": "MY_AUTH_TOKEN", "hpcs_object_store_type": "swift", - "loadbalancers": [ + "loadBalancers": [ { "id": "15", "name": "lb #1", @@ -305,7 +305,7 @@ Example Response "hpcs_object_store_endpoint": "https://example.com/v1/100", "hpcs_object_store_token": "MY_AUTH_TOKEN", "hpcs_object_store_type": "swift", - "loadbalancers": [ + "loadBalancers": [ { "id": "15", "name": "lb #1", @@ -320,9 +320,9 @@ Example Response STATS Message ------------- -The STATS message queries the worker for load balancer statistics. Currently, -this doesn't do more than verify that the HAProxy process is running and we -can successfully query its statistics socket. +The STATS message queries the worker for general availability (i.e., a ping) +Currently, this doesn't do more than verify that the HAProxy process is +running and we can successfully query its statistics socket. Required Fields ^^^^^^^^^^^^^^^ @@ -348,3 +348,47 @@ Example Response "hpcs_response": "PASS" } + +METRICS Message +--------------- + +The METRICS message queries the worker for load balancer usage metrics. +The number of bytes out for each load balancer defined on the device +is returned in the response. + +Required Fields +^^^^^^^^^^^^^^^ + +* hpcs_action + +Example Request +^^^^^^^^^^^^^^^ + +.. code-block:: json + + { + "hpcs_action": "METRICS" + } + +Example Response +^^^^^^^^^^^^^^^^ + +.. code-block:: json + + { + "hpcs_action": "METRICS", + "utc_start": "2014-01-09 15:11.45.704754", + "utc_end": "2014-01-09 16:10.00.72683", + "loadBalancers": [ + { + "protocol": "HTTP", + "bytes_out": "12345" + }, + { + "protocol": "TCP", + "bytes_out": "5678" + } + ], + "hpcs_response": "PASS" + } + diff --git a/libra/worker/controller.py b/libra/worker/controller.py index d95f3c64..bc6477f5 100644 --- a/libra/worker/controller.py +++ b/libra/worker/controller.py @@ -70,10 +70,10 @@ class LBaaSController(object): return self._action_discover() elif action == 'ARCHIVE': return self._action_archive() + elif action == 'METRICS': + return self._action_metrics() elif action == 'STATS': return self._action_stats() - elif action == 'PING': - return self._action_ping() elif action == 'DIAGNOSTICS': return self._action_diagnostic() else: @@ -488,7 +488,7 @@ class LBaaSController(object): self.msg[self.RESPONSE_FIELD] = self.RESPONSE_SUCCESS return self.msg - def _action_ping(self): + def _action_stats(self): """ Get load balancer and node status. @@ -500,18 +500,18 @@ class LBaaSController(object): try: nodes = self.driver.get_status() except NotImplementedError: - error = "Selected driver does not support PING action." + error = "Selected driver does not support STATS action." LOG.error(error) self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE self.msg[self.ERROR_FIELD] = error except DeletedStateError: - error = "Invalid operation PING on a deleted LB." + error = "Invalid operation STATS on a deleted LB." LOG.error(error) self.msg['status'] = 'DELETED' self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE self.msg[self.ERROR_FIELD] = error except Exception as e: - LOG.error("PING failed: %s, %s" % (e.__class__, e)) + LOG.error("STATS failed: %s, %s" % (e.__class__, e)) self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE self.msg[self.ERROR_FIELD] = str(e) else: @@ -522,9 +522,9 @@ class LBaaSController(object): return self.msg - def _action_stats(self): + def _action_metrics(self): """ - Get load balancer statistics + Get load balancer metrics This type of request gets the number of bytes out for each load balancer defined on the device. If both a TCP and HTTP load @@ -534,20 +534,20 @@ class LBaaSController(object): try: start, end, statistics = self.driver.get_statistics() except NotImplementedError: - error = "Selected driver does not support STATS action." + error = "Selected driver does not support METRICS action." LOG.error(error) self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE self.msg[self.ERROR_FIELD] = error return self.msg except DeletedStateError: - error = "Invalid operation STATS on a deleted LB." + error = "Invalid operation METRICS on a deleted LB." LOG.error(error) self.msg['status'] = 'DELETED' self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE self.msg[self.ERROR_FIELD] = error return self.msg except Exception as e: - LOG.error("STATS failed: %s, %s" % (e.__class__, e)) + LOG.error("METRICS failed: %s, %s" % (e.__class__, e)) self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE self.msg[self.ERROR_FIELD] = str(e) return self.msg diff --git a/libra/worker/drivers/haproxy/stats.py b/libra/worker/drivers/haproxy/stats.py index ea433cd1..61c2da57 100644 --- a/libra/worker/drivers/haproxy/stats.py +++ b/libra/worker/drivers/haproxy/stats.py @@ -35,7 +35,7 @@ class StatisticsManager(object): These are stats that we need to save because a state change in the HAProxy service is causing it to restart. Since HAProxy stores its stats in memory, they would otherwise be lost. We save them here - for consideration in the next STATS request. + for consideration in the next METRICS request. * Last queried stats These are total bytes out as reported from HAProxy the last time we diff --git a/libra/worker/drivers/haproxy/ubuntu_services.py b/libra/worker/drivers/haproxy/ubuntu_services.py index 6413a6c6..8c4aa43f 100644 --- a/libra/worker/drivers/haproxy/ubuntu_services.py +++ b/libra/worker/drivers/haproxy/ubuntu_services.py @@ -71,7 +71,7 @@ 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 + # If we have unreported totals, then we haven't received a METRICS # 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