Commit c4fbcf88 authored by Alberts S's avatar Alberts S
Browse files

Visualizer improvements

parent 2670fbe6
......@@ -54,6 +54,10 @@ class CapybaraNetty(metaclass=MetaCapybaraNetty):
) as e:
return False
def translate_target_name(self, target):
target_optimization_translations = self.config["external_targets_for_optimizations_translations"]
return target_optimization_translations.get(target) or target
@staticmethod
def log_format_ip(ip):
return f"{ip:<16s}"
......
......@@ -108,5 +108,7 @@ class Pinger(CapybaraNetty):
try:
await self.get_ping()
except (asyncssh.misc.PermissionDenied, asyncio.exceptions.TimeoutError) as e:
self.__logger.warning(f"Pinger {self.log_format_ip(self.router_ip)} is unable to connect via SSH")
self.__logger.warning(
f"Pinger {self.log_format_ip(self.router_ip)} is unable to connect via SSH due to {repr(e)}"
)
await asyncio.sleep(interval_seconds)
......@@ -19,6 +19,8 @@ class Visualizer(CapybaraNetty):
self.external_targets_for_optimizations = []
self.optimization_threshold_ms = 0
self.include_factual_weight = False
self.pyvis_size_width = "1280px"
self.pyvis_size_height = "1280px"
async def run(self):
G_simple = await self.get_host_latency_overview()
......@@ -67,7 +69,7 @@ class Visualizer(CapybaraNetty):
G_subgraph = nx.subgraph_view(G, filter_node=filter_node)
lengths, paths = nx.single_source_dijkstra(G_subgraph, source=target, weight="weight")
palette = sns.color_palette("tab10")
palette = sns.color_palette("tab10").as_hex()
palette_index = 0
for key, path in paths.items():
if len(path) > 2 and not (
......@@ -81,7 +83,8 @@ class Visualizer(CapybaraNetty):
)
else:
color = palette[palette_index]
palette_index += 1
# It makes a bit more sense if not all nodes are differently colored since colors may overlap and override each other
palette_index = 0
for previous, current in zip(path, path[1:]):
G[previous][current]["color"] = color
G[previous][current]["improved_path"] = True
......@@ -124,16 +127,28 @@ class Visualizer(CapybaraNetty):
await self.draw_graph_pyvis(G, output_base_name, include_dummy_weight=True)
async def draw_graph_pyvis(self, G, output_base, include_dummy_weight: bool):
def get_edge_time_attribute(edge, time_key):
if not time_key in edge:
self.__logger.warning(f"Visualizer encountered an edge which is DOWN")
return edge.get(time_key, "DOWN")
# PyVis
net = Network("1280px", "1280px")
net = Network(self.pyvis_size_height, self.pyvis_size_width)
net.show_buttons(filter_=True)
net.from_nx(G)
net.barnes_hut(spring_length=250)
for edge in net.edges:
edge["width"] = 2
edge["label"] = f'{get_edge_time_attribute(edge, "weight")}'
if include_dummy_weight:
edge["label"] = f'{edge["weight"]} [{edge["weight_dummy"]}]'
edge["label"] += f' [{get_edge_time_attribute(edge, "weight_dummy")}]'
for node in net.nodes:
if node["type"] == "target":
node["label"] = self.translate_target_name(node["label"])
node["color"] = "red"
else:
edge["label"] = f'{edge["weight"]}'
node["color"] = "green"
output_name = f"{output_base}_pyvis{'_with_dummy' if include_dummy_weight else ''}.html"
self.__logger.info(f"Writing {output_name}")
......@@ -156,9 +171,17 @@ class Visualizer(CapybaraNetty):
async def run_daemon(self, pinger_data_fn):
while True:
self.optimization_threshold_ms = self.config["optimization_threshold_ms"]
self.pinger_data = pinger_data_fn()
self.external_targets_for_optimizations = self.config["external_targets_for_optimizations"]
self.include_factual_weight = self.config["visualizer_include_factual_weight"]
await self.run()
try:
self.optimization_threshold_ms = self.config["optimization_threshold_ms"]
self.pinger_data = pinger_data_fn()
self.external_targets_for_optimizations = self.config["external_targets_for_optimizations"]
self.include_factual_weight = self.config["visualizer_include_factual_weight"]
self.pyvis_size_height = self.config["visualizer_pyvis_size_height"]
self.pyvis_size_width = self.config["visualizer_pyvis_size_width"]
await self.run()
except Exception as e:
self.__logger.error(f"Visualizer encountered error: {repr(e)}")
raise e
await asyncio.sleep(self.config["visualizer_interval"])
......@@ -53,7 +53,7 @@ Pygments==2.11.2
pyparsing==3.0.7
python-dateutil==2.8.2
pytz==2022.1
pyvis==0.1.9
pyvis @ git+https://github.com/WestHealth/pyvis.git@v0.2.1
PyYAML==6.0
requests==2.27.1
scipy==1.8.0
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment