From 5e6423f3cf574a06297986628045df0302e514fd Mon Sep 17 00:00:00 2001 From: Kobi Samoray Date: Tue, 6 Jun 2017 15:20:13 +0300 Subject: [PATCH] NSXv: add lbaas statistics support Change-Id: I174e697bd15cdd5bc569d1ae57e8f53c79c2a850 --- .../lbaas/nsx_v/v2/loadbalancer_mgr.py | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/vmware_nsx/services/lbaas/nsx_v/v2/loadbalancer_mgr.py b/vmware_nsx/services/lbaas/nsx_v/v2/loadbalancer_mgr.py index cf6c230c30..aa0467886d 100644 --- a/vmware_nsx/services/lbaas/nsx_v/v2/loadbalancer_mgr.py +++ b/vmware_nsx/services/lbaas/nsx_v/v2/loadbalancer_mgr.py @@ -130,12 +130,30 @@ class EdgeLoadBalancerManager(base_mgr.EdgeLoadbalancerBaseManager): @log_helpers.log_method_call def stats(self, context, lb): - # TODO(kobis): implement stats = {'bytes_in': 0, 'bytes_out': 0, 'active_connections': 0, 'total_connections': 0} + binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(context.session, + lb.id) + + try: + lb_stats = self.vcns.get_loadbalancer_statistics( + binding['edge_id']) + + except nsxv_exc.VcnsApiException: + msg = (_('Failed to read load balancer statistics, edge: %s') % + binding['edge_id']) + raise n_exc.BadRequest(resource='edge-lbaas', msg=msg) + + pools_stats = lb_stats[1].get('pool', []) + for pool_stats in pools_stats: + stats['bytes_in'] += pool_stats.get('bytesIn', 0) + stats['bytes_out'] += pool_stats.get('bytesOut', 0) + stats['active_connections'] += pool_stats.get('curSessions', 0) + stats['total_connections'] += pool_stats.get('totalSessions', 0) + return stats def _handle_subnet_gw_change(self, *args, **kwargs):