updated grpc throughputs to only check a specific session and verify the data being collected and sent is for that session, fixed data from throughputs being in hex getting converted to int, updated coretk to only run throughputs when enabled, updated grpc streams to return the stream to allow it being canceled

This commit is contained in:
Blake Harnden 2019-12-16 11:14:05 -08:00
parent 85521e8c8f
commit 424f69bb15
6 changed files with 47 additions and 23 deletions

View file

@ -385,23 +385,27 @@ class CoreGrpcClient:
:param int session_id: id of session
:param handler: handler for received events
:param list events: events to listen to, defaults to all
:return: nothing
:return: stream processing events, can be used to cancel stream
:raises grpc.RpcError: when session doesn't exist
"""
request = core_pb2.EventsRequest(session_id=session_id, events=events)
stream = self.stub.Events(request)
start_streamer(stream, handler)
return stream
def throughputs(self, handler):
def throughputs(self, session_id, handler):
"""
Listen for throughput events with information for interfaces and bridges.
:param int session_id: session id
:param handler: handler for every event
:return: nothing
:return: stream processing events, can be used to cancel stream
:raises grpc.RpcError: when session doesn't exist
"""
request = core_pb2.ThroughputsRequest()
request = core_pb2.ThroughputsRequest(session_id=session_id)
stream = self.stub.Throughputs(request)
start_streamer(stream, handler)
return stream
def add_node(self, session_id, node):
"""

View file

@ -27,7 +27,7 @@ from core.nodes.lxd import LxcNode
from core.services.coreservices import ServiceManager
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
_INTERFACE_REGEX = re.compile(r"\d+")
_INTERFACE_REGEX = re.compile(r"[0-9a-fA-F]+")
class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
@ -452,9 +452,11 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
:param grpc.SrevicerContext context: context object
:return: nothing
"""
session = self.get_session(request.session_id, context)
delay = 3
last_check = None
last_stats = None
while self._is_running(context):
now = time.monotonic()
stats = get_net_stats()
@ -462,7 +464,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
# calculate average
if last_check is not None:
interval = now - last_check
throughputs_event = core_pb2.ThroughputsEvent()
throughputs_event = core_pb2.ThroughputsEvent(session_id=session.id)
for key in stats:
current_rxtx = stats[key]
previous_rxtx = last_stats.get(key)
@ -477,8 +479,11 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
throughput = rx_kbps + tx_kbps
if key.startswith("veth"):
key = key.split(".")
node_id = int(_INTERFACE_REGEX.search(key[0]).group())
interface_id = int(key[1])
node_id = int(_INTERFACE_REGEX.search(key[0]).group(), base=16)
interface_id = int(key[1], base=16)
session_id = int(key[2], base=16)
if session.id != session_id:
continue
interface_throughput = (
throughputs_event.interface_throughputs.add()
)
@ -487,7 +492,11 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
interface_throughput.throughput = throughput
elif key.startswith("b."):
try:
node_id = int(key.split(".")[1])
key = key.split(".")
node_id = int(key[1], base=16)
session_id = int(key[2], base=16)
if session.id != session_id:
continue
bridge_throughput = (
throughputs_event.bridge_throughputs.add()
)