mirror of
https://github.com/logos-blockchain/logos-blockchain-simulations.git
synced 2026-01-10 00:53:11 +00:00
49 lines
1.1 KiB
Python
49 lines
1.1 KiB
Python
import argparse
|
|
import json
|
|
from collections.abc import Iterable
|
|
from typing import Any
|
|
|
|
import pandas as pd
|
|
|
|
import mixlog
|
|
|
|
|
|
def analyze_monitors(input_stream: Iterable[str]) -> None:
|
|
df = pd.DataFrame(monitor_records(input_stream))
|
|
|
|
result = {
|
|
"min": df["min"].min(),
|
|
"avg": (df["num_conns"] * df["avg"]).sum() / df["num_conns"].sum(),
|
|
"max": df["max"].max(),
|
|
}
|
|
print(result)
|
|
|
|
|
|
def monitor_records(input_stream: Iterable[str]) -> list[Any]:
|
|
records = []
|
|
|
|
for line in input_stream:
|
|
try:
|
|
record = json.loads(line)
|
|
except json.JSONDecodeError:
|
|
continue
|
|
|
|
if "message_type" in record and "num_conns" in record:
|
|
records.append(record)
|
|
|
|
return records
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description="Mix connection monitor analysis")
|
|
parser.add_argument(
|
|
"--log-path",
|
|
nargs="?",
|
|
type=str,
|
|
help="An input log file path. If not provided, input will be read from stdin.",
|
|
)
|
|
args = parser.parse_args()
|
|
|
|
input = mixlog.get_input_stream(args.log_path)
|
|
analyze_monitors(input)
|