/
azathd
/
mutiagent
Обзор
Документация
Войти
/
azathd
/
mutiagent
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
scripts/validate_log_parse.py
46 строк
1 KB
Your Name
init
15 май 2026, 18:54
15 май 2026, 18:54
07c4701
Код
Авторство
О чём код?
#!/usr/bin/env python3 """Count how many lines in a log file parse successfully (run on host).""" from __future__ import annotations import argparse import sys from pathlib import Path # Allow: PYTHONPATH=src python scripts/validate_log_parse.py sys.path.insert(0, str(Path(__file__).resolve().parents[1])) from src.agents.collector.parser import parse_line # noqa: E402 def main() -> None: p = argparse.ArgumentParser() p.add_argument("path", type=Path) p.add_argument("--type", choices=("access", "error"), default="access") p.add_argument("--max-lines", type=int, default=0) args = p.parse_args() ok = fail = 0 samples: list[str] = [] with args.path.open(encoding="utf-8", errors="replace") as f: for i, line in enumerate(f, 1): if args.max_lines and i > args.max_lines: break if parse_line(line, log_type=args.type): ok += 1 else: fail += 1 if len(samples) < 5: samples.append(line.rstrip()[:200]) total = ok + fail pct = (100.0 * ok / total) if total else 0 print(f"file={args.path} type={args.type} ok={ok} fail={fail} ({pct:.1f}% parsed)") if samples: print("sample failures:") for s in samples: print(f" {s!r}") if __name__ == "__main__": main()