Skip to content

Commit cb07095

Browse files
author
Alan Christie
committed
chore: Add more stats to ws-listener
1 parent fc81cda commit cb07095

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

ws_listener.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,23 @@ def main(c_args: argparse.Namespace):
1919
elif c_args.ordinal_offset:
2020
headers["X-StreamFromOrdinal"] = c_args.ordinal_offset
2121

22+
total_bytes = 0
23+
total_messages = 0
24+
min_bytes = 1_000_000
25+
max_bytes = 0
2226
ws = Client.connect(c_args.location, headers=headers)
2327
try:
2428
while True:
29+
2530
data = ws.receive()
31+
32+
# Collect some stats
33+
data_len = len(data)
34+
total_bytes += data_len
35+
min_bytes = min(min_bytes, data_len)
36+
max_bytes = max(max_bytes, data_len)
37+
total_messages += 1
38+
2639
msg_type = "(unknown)"
2740
msg = "(unknown)"
2841
ordinal = "(unknown)"
@@ -46,11 +59,15 @@ def main(c_args: argparse.Namespace):
4659
else:
4760
ordinal = "(not present)"
4861
timestamp = "(not present)"
49-
print("---------")
50-
print(f" ORDINAL: {ordinal}")
51-
print(f"TIMESTAMP: {timestamp}")
52-
print(f" TYPE: {msg_type}")
53-
print(f" BODY: {msg}")
62+
print("-----------")
63+
print(f" ORDINAL: {ordinal}")
64+
print(f" TIMESTAMP: {timestamp}")
65+
print(f" TYPE: {msg_type}")
66+
print(f" BODY: {msg}")
67+
print(f"TOTAL BYTES: {total_bytes}")
68+
print(f" MIN BYTES: {min_bytes}")
69+
print(f" MAX BYTES: {max_bytes}")
70+
print(f" AVG BYTES: {int(total_bytes/total_messages + 0.5)}")
5471
except (KeyboardInterrupt, EOFError, ConnectionClosed):
5572
ws.close()
5673

0 commit comments

Comments
 (0)