mirror of
https://github.com/logos-blockchain/logos-blockchain-simulations.git
synced 2026-01-06 07:03:10 +00:00
add python script for min, avg, and max
This commit is contained in:
parent
137bd72435
commit
0c03dcde86
48
simlib/blendnet-sims/scripts/monitor.py
Normal file
48
simlib/blendnet-sims/scripts/monitor.py
Normal file
@ -0,0 +1,48 @@
|
||||
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)
|
||||
Loading…
x
Reference in New Issue
Block a user