Added more nodes/app to the table

This commit is contained in:
jvved 2025-02-04 19:31:48 -05:00
parent a2fc85b152
commit 6cbfc82e94
2 changed files with 70 additions and 64 deletions

View File

@ -7,6 +7,6 @@ threads = true
wsgi-file = foobar.py wsgi-file = foobar.py
socket=127.0.0.1:9029 socket=127.0.0.1:9029
stats-server=run/app1_stats.sock stats-server=run/9029_stats.sock
subscribe2=addr=127.0.0.1:9027,key=app1.pikesquares.local,server=127.0.0.1:9700 subscribe2=addr=127.0.0.1:9029,key=app2.pikesquares.local,server=127.0.0.1:9701

View File

@ -7,8 +7,10 @@ import socket
import stats import stats
from stats import WorkerAppStats from stats import WorkerAppStats
from stats import AppStats from stats import AppStats
from collections import Counter
from rich.console import Console from rich.console import Console
import sys
import glob
from stats import RouterSubscription from stats import RouterSubscription
import time import time
@ -16,6 +18,33 @@ from rich.live import Live
from rich.table import Table from rich.table import Table
import pydantic import pydantic
class SocketStats(pydantic.BaseModel):
name: str
queue: int
class WorkerStats(pydantic.BaseModel):
id: int
accepting: int
class AppStats(pydantic.BaseModel):
model_config = pydantic.ConfigDict(strict=True)
version: str
listen_queue: int = 0
listen_queue_errors: int = 0
signal_queue: int
load: int
pid: int
uid: int
gid: int
cwd: str
locks: list[dict[str, int]]
sockets: list[SocketStats]
workers: list[WorkerStats]
# import ipdb;ipdb.set_trace()
class RouterStats(pydantic.BaseModel): class RouterStats(pydantic.BaseModel):
model_config = pydantic.ConfigDict(strict=True) model_config = pydantic.ConfigDict(strict=True)
version: str version: str
@ -28,7 +57,7 @@ class RouterStats(pydantic.BaseModel):
subscriptions: list[RouterSubscription] subscriptions: list[RouterSubscription]
cheap: int = pydantic.Field(ge=0) cheap: int = pydantic.Field(ge=0)
def run(stats_address): def read_stats(stats_address):
if not all([stats_address.exists(), stats_address.is_socket()]): if not all([stats_address.exists(), stats_address.is_socket()]):
raise Exception(f"unable to read stats from {(stats_address)}") raise Exception(f"unable to read stats from {(stats_address)}")
@ -70,59 +99,36 @@ def run(stats_address):
print(js) print(js)
if __name__ == "__main__": if __name__ == "__main__":
stats_address = Path("run/sub1-stats.sock") # ini_directory = Path("/home/jvved/dev/testpks/")
stats = run(stats_address) # ini_file = ini_directory.glob("sub*.ini")
# print(ini_file)
stats_list = ["run/sub1-stats.sock", "run/sub2-stats.sock"]
for stats in stats_list:
stats_address = Path(stats_list)
stats = read_stats(stats_address)
print(stats) print(stats)
class SocketStats(pydantic.BaseModel):
name:str
queue: int
class WorkerStats(pydantic.BaseModel):
id:int
accepting:int
class AppStats(pydantic.BaseModel):
model_config = pydantic.ConfigDict(strict=True)
version: str
listen_queue: int = 0
listen_queue_errors: int = 0
signal_queue: int
load: int
pid: int
uid: int
gid: int
cwd: str
locks: list[dict[str, int]]
sockets: list[SocketStats]
workers: list[WorkerStats]
for sub in stats["subscriptions"]:
print(sub)
for node in sub["nodes"]:
print(node)
node_name = node["name"]
print(f"{node_name}")
port = node_name.split(":")[-1]
print(f"{port}")
# stats_address2 = f"{port}_stats.sock"
stats_address2 = Path(f"run/{port}_stats.sock")
stats2 = run(stats_address2)
print(stats2)
for sub2 in stats2["workers"]:
print(sub2)
app_stats = AppStats(**stats2)
print(app_stats)
worker_amount = app_stats.workers
print(len(app_stats.workers)) # print amount workers
router_stats = RouterStats(**stats) router_stats = RouterStats(**stats)
print(router_stats) all_app_stats = {}
total_workers = 0
for sub in router_stats.subscriptions:
print(sub)
for node in sub.nodes:
print(node.name)
port = node.name.split(":")[-1]
print(port)
stats_address2 = Path(f"run/{port}_stats.sock")
stats2 = read_stats(stats_address2)
app_stats = AppStats(**stats2)
print(f"App Stats for {port}:{app_stats}")
print(app_stats.workers)
print(len(app_stats.workers))
worker_amount = len(app_stats.workers)
total_workers = total_workers + worker_amount
print(total_workers)
print(router_stats)
#import ipdb;ipdb.set_trace() #import ipdb;ipdb.set_trace()
for sub in router_stats.subscriptions: for sub in router_stats.subscriptions:
print(f"{sub.key=}") print(f"{sub.key=}")
@ -131,7 +137,7 @@ table = Table()
table.add_column("Virtual Hosts", justify="right", style="cyan", no_wrap=True) table.add_column("Virtual Hosts", justify="right", style="cyan", no_wrap=True)
table.add_column("Nodes", style="magenta") table.add_column("Nodes", style="magenta")
table.add_column("Total Workers", style="magenta") table.add_column("Total Workers", style="magenta")
table.add_row(sub.key, f"{len(sub.nodes)}", f"{len(app_stats.workers)}") table.add_row(sub.key, f"{len(sub.nodes)}", f"{total_workers}")
console = Console() console = Console()
console.print(table) console.print(table)