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

View file

@ -667,12 +667,10 @@ class CoreClient:
self.links[edge.token] = edge
src_node = edge.src.core_node
dst_node = edge.dst.core_node
if nutils.is_container(src_node):
src_iface_id = edge.link.iface1.id
self.iface_to_edge[(src_node.id, src_iface_id)] = edge
if nutils.is_container(dst_node):
dst_iface_id = edge.link.iface2.id
self.iface_to_edge[(dst_node.id, dst_iface_id)] = edge
src_iface_id = edge.link.iface1.id
self.iface_to_edge[(src_node.id, src_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]]]:
configs = []

View file

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

View file

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