grpc: updates to fix throughput parsing, accounting for new connection changes, now supports throughput for network to network links

This commit is contained in:
Blake Harnden 2022-10-12 14:04:48 -07:00
parent 9218fb0b6f
commit b5b7b8cdf9
5 changed files with 30 additions and 24 deletions

View file

@ -581,6 +581,24 @@ def convert_link(
)
def parse_proc_net_dev(lines: List[str]) -> Dict[str, Any]:
"""
Parse lines of output from /proc/net/dev.
:param lines: lines of /proc/net/dev
:return: parsed device to tx/rx values
"""
stats = {}
for line in lines[2:]:
line = line.strip()
if not line:
continue
line = line.split()
line[0] = line[0].strip(":")
stats[line[0]] = {"rx": float(line[1]), "tx": float(line[9])}
return stats
def get_net_stats() -> Dict[str, Dict]:
"""
Retrieve status about the current interfaces in the system
@ -588,18 +606,8 @@ def get_net_stats() -> Dict[str, Dict]:
:return: send and receive status of the interfaces in the system
"""
with open("/proc/net/dev", "r") as f:
data = f.readlines()[2:]
stats = {}
for line in data:
line = line.strip()
if not line:
continue
line = line.split()
line[0] = line[0].strip(":")
stats[line[0]] = {"rx": float(line[1]), "tx": float(line[9])}
return stats
lines = f.readlines()[2:]
return parse_proc_net_dev(lines)
def session_location(session: Session, location: core_pb2.SessionLocation) -> None:

View file

@ -104,7 +104,7 @@ from core.services.coreservices import ServiceManager
logger = logging.getLogger(__name__)
_ONE_DAY_IN_SECONDS: int = 60 * 60 * 24
_INTERFACE_REGEX: Pattern = re.compile(r"veth(?P<node>[0-9a-fA-F]+)")
_INTERFACE_REGEX: Pattern = re.compile(r"beth(?P<node>[0-9a-fA-F]+)")
_MAX_WORKERS = 1000
@ -482,7 +482,6 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
while self._is_running(context):
now = time.monotonic()
stats = get_net_stats()
# calculate average
if last_check is not None:
interval = now - last_check
@ -499,7 +498,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
(current_rxtx["tx"] - previous_rxtx["tx"]) * 8.0 / interval
)
throughput = rx_kbps + tx_kbps
if key.startswith("veth"):
if key.startswith("beth"):
key = key.split(".")
node_id = _INTERFACE_REGEX.search(key[0]).group("node")
node_id = int(node_id, base=16)
@ -525,7 +524,6 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
bridge_throughput.throughput = throughput
except ValueError:
pass
yield throughputs_event
last_check = now