# Мониторинг

Руководство по мониторингу системы OneAPA.

## Точки мониторинга

| Компонент      | Что мониторить            |
| -------------- | ------------------------- |
| Proxy-сервер   | Доступность, время ответа |
| LLM провайдеры | Ошибки, лимиты            |
| 1С сервер      | Производительность        |
| Агенты         | Использование, ошибки     |

## Мониторинг Proxy

### Health Check

```bash
# Проверка доступности
curl http://proxy:9000/health

# Ожидаемый ответ
{
  "message": "OK",
  "version": "1.0.1"
}
```

### Автоматическая проверка

```bash
#!/bin/bash
# Скрипт мониторинга

PROXY_URL="http://proxy:9000/health"
ALERT_EMAIL="admin@company.ru"

response=$(curl -s -o /dev/null -w "%{http_code}" $PROXY_URL)

if [ "$response" != "200" ]; then
    echo "OneAPA Proxy недоступен" | mail -s "ALERT: OneAPA" $ALERT_EMAIL
fi
```

### Docker мониторинг

```bash
# Статус контейнера
docker ps --filter "name=oneapa"

# Использование ресурсов
docker stats oneapa-proxy

# Логи
docker logs --tail 100 oneapa-proxy
```

## Метрики

### Основные метрики

| Метрика             | Описание                    | Порог               |
| ------------------- | --------------------------- | ------------------- |
| Время ответа        | Среднее время ответа агента | < 30 сек            |
| Ошибки LLM          | Количество ошибок в час     | < 10                |
| Вызовы инструментов | Количество вызовов          | -                   |
| Активные сессии     | Параллельные диалоги        | Зависит от ресурсов |

### Prometheus

```yaml
# prometheus.yml
scrape_configs:
  - job_name: 'oneapa'
    static_configs:
      - targets: ['proxy:9000']
    metrics_path: /metrics
```

## Мониторинг LLM

### OpenAI

* Проверяйте баланс
* Следите за rate limits
* Мониторьте ошибки 429

### Yandex GPT

* Проверяйте IAM токен (истекает через 12ч)
* Следите за квотами

### Ollama

* Мониторьте использование GPU
* Проверяйте загрузку RAM

## Алерты

### Критические

* Proxy недоступен
* 100% ошибок LLM
* Нет места на диске

### Предупреждения

* Время ответа > 60 сек
* Ошибки > 10% запросов
* Низкий баланс LLM провайдера

## Dashboard

### Grafana пример

```
┌─────────────────────────────────────────────────────────────┐
│                    OneAPA Dashboard                          │
├─────────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────────┐ │
│ │ Status: ✅  │ │ Requests/h  │ │ Avg Response Time       │ │
│ │   ONLINE    │ │    1,234    │ │      12.5 sec           │ │
│ └─────────────┘ └─────────────┘ └─────────────────────────┘ │
│                                                              │
│ [График запросов за сутки]                                  │
│                                                              │
│ [График ошибок]                                             │
└─────────────────────────────────────────────────────────────┘
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.onerpa.ru/ai-platforma-oneapa/administrirovanie/monitoring.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
