Metadata-Version: 2.4
Name: nginx-lens
Version: 1.1.0
Summary: CLI-инструмент для анализа, визуализации и диагностики конфигураций Nginx
Author-email: Daniil Astrouski <shelovesuastra@gmail.com>
License: MIT
Project-URL: Homepage, https://github.com/rainysundaynight/nginx-lens
Project-URL: Repository, https://github.com/rainysundaynight/nginx-lens
Project-URL: Issues, https://github.com/rainysundaynight/nginx-lens/issues
Project-URL: Documentation, https://github.com/rainysundaynight/nginx-lens/blob/main/docs/CONFIGURATION.md
Keywords: nginx,cli,devops,configuration,monitoring
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Intended Audience :: System Administrators
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: System :: Networking
Classifier: Topic :: System :: Systems Administration
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: typer[all]>=0.9.0
Requires-Dist: rich>=13.0.0
Requires-Dist: requests>=2.25.0
Requires-Dist: dnspython>=2.0.0
Requires-Dist: pyyaml>=5.4
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
Provides-Extra: web
Requires-Dist: fastapi>=0.109.0; extra == "web"
Requires-Dist: uvicorn[standard]>=0.27.0; extra == "web"
Requires-Dist: httpx>=0.26.0; extra == "web"
Requires-Dist: pydantic>=2.5.0; extra == "web"
Dynamic: license-file

# nginx-lens

CLI-инструмент для анализа, визуализации и диагностики конфигураций Nginx.

Проверяет upstream, находит проблемы в конфиге, анализирует логи и экспортирует отчёты в JSON/YAML/Prometheus. Опционально — HTTP-агенты и hub для централизованного мониторинга через UI.

## Установка

```bash
pip install nginx-lens
# или изолированно
pipx install nginx-lens
# или из исходников
git clone https://github.com/rainysundaynight/nginx-lens.git
cd nginx-lens && pipx install .
```

Web-стек (agent + hub):

```bash
pip install nginx-lens[web]
```

Инициализация конфига и автодополнения:

```bash
nginx-lens init
# системный конфиг (root):
sudo nginx-lens init --system
```

## Быстрый старт

```bash
# Проверка upstream
nginx-lens health /etc/nginx/nginx.conf

# Статический анализ (SSL, limits, rewrites, conflicts)
nginx-lens analyze /etc/nginx/nginx.conf

# Комплексная валидация для CI/CD
nginx-lens validate /etc/nginx/nginx.conf --json

# Какой location обработает URL
nginx-lens route http://example.com/api/v1/users

# Анализ access.log
nginx-lens logs /var/log/nginx/access.log --top 20

# Метрики конфигурации + Prometheus
nginx-lens metrics /etc/nginx/nginx.conf --prometheus
```

## Web-архитектура

```text
┌─────────────┐     ┌─────────────┐     ┌─────────────┐
│  nginx-host │     │  nginx-host │     │     UI      │
│   :8088     │     │   :8088     │     │  (browser)  │
│   agent     │     │   agent     │     └──────┬──────┘
└──────┬──────┘     └──────┬──────┘            │
       │                   │                   │
       └─────────┬─────────┘                   │
                 ▼                             │
          ┌─────────────┐                      │
          │ nginx-lens  │◄─────────────────────┘
          │    hub      │   GET /api/v1/*
          │   :8089     │
          └─────────────┘
```

На каждом nginx-сервере — `nginx-lens-agent`. Hub агрегирует snapshot с агентов; UI подключается к hub API.

Подробнее: [docs/WEB_DEPLOYMENT.md](docs/WEB_DEPLOYMENT.md)

## Основные команды

| Команда | Назначение |
|---------|------------|
| `health` | Доступность upstream (TCP/HTTP), DNS |
| `resolve` | DNS-резолвинг upstream |
| `analyze` | Статический анализ конфигурации |
| `validate` | syntax + analyze + upstream (для CI) |
| `syntax` | `nginx -t` с подсветкой ошибок |
| `tree` / `graph` / `include-tree` | Визуализация конфигурации |
| `route` | Маршрутизация URL → server/location |
| `diff` | Сравнение двух конфигов |
| `logs` | Статистика и аномалии в логах |
| `metrics` | Метрики конфигурации, Prometheus |
| `upstreams` | Сводка по upstream-блокам |
| `config` | Активный конфиг nginx-lens |
| `init` / `completion` | Первичная настройка |

Полный справочник: [docs/CONFIGURATION.md](docs/CONFIGURATION.md)

## Конфигурация

Файлы (по приоритету):

1. `.nginx-lens.yaml` в текущей директории
2. `/opt/nginx-lens/config.yaml` (с `--system`)
3. `~/.nginx-lens/config.yaml` (по умолчанию после `init`)

Переменные окружения: префикс `NGINX_LENS_` (например `NGINX_LENS_TIMEOUT`).

Пример: [example-config.yaml](example-config.yaml)

## Ограничения парсера

Парсер regex-based — не полный nginx grammar. Edge cases: `include` с переменными, сложные `if`, многострочные директивы. Для синтаксиса используйте `nginx-lens syntax` (`nginx -t`).

## Документация

- [Конфигурация и команды](docs/CONFIGURATION.md)
- [Web-деплой (agent + hub + UI)](docs/WEB_DEPLOYMENT.md)
- [ngx_dynamic_upstream](docs/DYNAMIC_UPSTREAM_COMPATIBILITY.md)
- [CHANGELOG](CHANGELOG.md)

## Разработка

```bash
pip install -e ".[dev,web]"
pytest tests/ -v
```

## Лицензия

MIT — см. [LICENSE](LICENSE)
