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]: def get_net_stats() -> Dict[str, Dict]:
""" """
Retrieve status about the current interfaces in the system 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 :return: send and receive status of the interfaces in the system
""" """
with open("/proc/net/dev", "r") as f: with open("/proc/net/dev", "r") as f:
data = f.readlines()[2:] lines = f.readlines()[2:]
return parse_proc_net_dev(lines)
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
def session_location(session: Session, location: core_pb2.SessionLocation) -> None: 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__) logger = logging.getLogger(__name__)
_ONE_DAY_IN_SECONDS: int = 60 * 60 * 24 _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 _MAX_WORKERS = 1000
@ -482,7 +482,6 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
while self._is_running(context): while self._is_running(context):
now = time.monotonic() now = time.monotonic()
stats = get_net_stats() stats = get_net_stats()
# calculate average # calculate average
if last_check is not None: if last_check is not None:
interval = now - last_check interval = now - last_check
@ -499,7 +498,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
(current_rxtx["tx"] - previous_rxtx["tx"]) * 8.0 / interval (current_rxtx["tx"] - previous_rxtx["tx"]) * 8.0 / interval
) )
throughput = rx_kbps + tx_kbps throughput = rx_kbps + tx_kbps
if key.startswith("veth"): if key.startswith("beth"):
key = key.split(".") key = key.split(".")
node_id = _INTERFACE_REGEX.search(key[0]).group("node") node_id = _INTERFACE_REGEX.search(key[0]).group("node")
node_id = int(node_id, base=16) node_id = int(node_id, base=16)
@ -525,7 +524,6 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
bridge_throughput.throughput = throughput bridge_throughput.throughput = throughput
except ValueError: except ValueError:
pass pass
yield throughputs_event yield throughputs_event
last_check = now last_check = now

View file

@ -667,12 +667,10 @@ class CoreClient:
self.links[edge.token] = edge self.links[edge.token] = edge
src_node = edge.src.core_node src_node = edge.src.core_node
dst_node = edge.dst.core_node dst_node = edge.dst.core_node
if nutils.is_container(src_node): src_iface_id = edge.link.iface1.id
src_iface_id = edge.link.iface1.id self.iface_to_edge[(src_node.id, src_iface_id)] = edge
self.iface_to_edge[(src_node.id, src_iface_id)] = edge dst_iface_id = edge.link.iface2.id
if nutils.is_container(dst_node): self.iface_to_edge[(dst_node.id, dst_iface_id)] = edge
dst_iface_id = edge.link.iface2.id
self.iface_to_edge[(dst_node.id, dst_iface_id)] = edge
def get_wlan_configs(self) -> List[Tuple[int, Dict[str, str]]]: def get_wlan_configs(self) -> List[Tuple[int, Dict[str, str]]]:
configs = [] configs = []

View file

@ -276,8 +276,9 @@ class NodeBase(abc.ABC):
mtu = DEFAULT_MTU mtu = DEFAULT_MTU
if iface_data and iface_data.mtu is not None: if iface_data and iface_data.mtu is not None:
mtu = iface_data.mtu mtu = iface_data.mtu
name = f"veth{self.id}.{iface_id}.{self.session.short_session_id()}" unique_name = f"{self.id}.{iface_id}.{self.session.short_session_id()}"
localname = f"{name}p" name = f"veth{unique_name}"
localname = f"beth{unique_name}"
iface = CoreInterface( iface = CoreInterface(
iface_id, iface_id,
name, name,

View file

@ -68,6 +68,7 @@ def cleanup_interfaces() -> None:
name = values[0] name = values[0]
if ( if (
name.startswith("veth") name.startswith("veth")
or name.startswith("beth")
or name.startswith("gt.") or name.startswith("gt.")
or name.startswith("b.") or name.startswith("b.")
or name.startswith("ctrl") or name.startswith("ctrl")