Skip to content

Repository files navigation

English version

Log Analyzer CLI

CLI-утилита на Go для анализа access-логов nginx в формате combined log format. Разбирает лог-файл и выводит топ IP-адресов по количеству запросов, распределение по HTTP статус-кодам и перцентили латентности p50/p90/p99.

Возможности

  • Потоковый разбор лог-файлов без загрузки всего файла в память
  • Устойчивость к битым строкам: невалидные строки пишутся как предупреждения, обработка продолжается
  • Топ N IP-адресов по количеству запросов
  • Распределение запросов по статус-кодам
  • Точные перцентили латентности по методу nearest-rank
  • Вывод в человекочитаемой таблице или JSON

Установка

go install github.com/Zaywoo66/log-analyzer/cmd/loganalyzer@latest

Или сборка из исходников:

git clone https://github.com/Zaywoo66/log-analyzer.git
cd log-analyzer
go build -o bin/loganalyzer ./cmd/loganalyzer

Использование

loganalyzer --file access.log
loganalyzer --file access.log --top 5
loganalyzer --file access.log --format json

Флаги

Флаг Короткий Обязателен По умолчанию Описание
--file -f да - Путь к файлу access-лога
--top -n нет 10 Сколько IP показывать в топе
--format - нет table table или json

Пример вывода table

Top IPs
IP              Requests
192.168.1.10    342
192.168.1.11    128

Status Codes
Code    Count
200     401
404     52
500     17

Latency Percentiles
p50     12.30ms
p90     45.80ms
p99     98.10ms

Total requests: 470

Пример вывода JSON

{
  "total_requests": 470,
  "top_ips": [
    { "ip": "192.168.1.10", "count": 342 }
  ],
  "status_codes": {
    "200": 401,
    "404": 52,
    "500": 17
  },
  "latency": {
    "p50": "12.30ms",
    "p90": "45.80ms",
    "p99": "98.10ms"
  },
  "latency_samples": 470
}

Архитектура

Проект разбит на изолированные слои: parser (разбор строк лога) -> stats (агрегация) -> report (форматирование вывода) -> cmd (CLI-обвязка на Cobra). Подробнее: ARCHITECTURE.md.

Разработка

Проект реализован итеративно по формальным контрактам из docs/contracts/. Правила работы агента и процесс приёмки описаны в AGENTS.md.

make fmt
make lint
make test

Русская версия выше

Log Analyzer CLI

A Go CLI tool for analyzing nginx access logs in combined log format. It parses a log file and reports top IP addresses by request count, HTTP status code distribution, and latency percentiles p50/p90/p99.

Features

  • Streaming parser that does not load the entire file into memory
  • Resilient handling of malformed lines: invalid lines are logged as warnings and processing continues
  • Top N IP addresses by request count
  • HTTP status code distribution
  • Exact latency percentiles using the nearest-rank method
  • Human-readable table output or JSON

Installation

go install github.com/Zaywoo66/log-analyzer/cmd/loganalyzer@latest

Or build from source:

git clone https://github.com/Zaywoo66/log-analyzer.git
cd log-analyzer
go build -o bin/loganalyzer ./cmd/loganalyzer

Usage

loganalyzer --file access.log
loganalyzer --file access.log --top 5
loganalyzer --file access.log --format json

Flags

Flag Short Required Default Description
--file -f yes - Path to the access log file
--top -n no 10 Number of IPs to include in the top list
--format - no table table or json

Sample table output

Top IPs
IP              Requests
192.168.1.10    342
192.168.1.11    128

Status Codes
Code    Count
200     401
404     52
500     17

Latency Percentiles
p50     12.30ms
p90     45.80ms
p99     98.10ms

Total requests: 470

Sample JSON output

{
  "total_requests": 470,
  "top_ips": [
    { "ip": "192.168.1.10", "count": 342 }
  ],
  "status_codes": {
    "200": 401,
    "404": 52,
    "500": 17
  },
  "latency": {
    "p50": "12.30ms",
    "p90": "45.80ms",
    "p99": "98.10ms"
  },
  "latency_samples": 470
}

Architecture

The project is split into isolated layers: parser (log line parsing) -> stats (aggregation) -> report (output formatting) -> cmd (CLI wiring via Cobra). See ARCHITECTURE.md for details.

Development

The project was implemented iteratively against formal contracts in docs/contracts/. Agent rules and acceptance workflow are documented in AGENTS.md.

make fmt
make lint
make test

About

CLI tool for analyzing nginx access logs — top IPs, status code distribution, and latency percentiles

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages