Files
docs/infrastructure/test-contour/guides/monitoring.md
T

124 lines
3.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Grafana, Prometheus и Loki
В test-контуре мониторинг разделён:
| Инструмент | URL | Задача |
|------------|-----|--------|
| **Prometheus** | http://prometheus.sova.local | метрики, targets, PromQL |
| **Grafana** | http://grafana.sova.local | дашборды + **логи через Loki** |
| **Loki** | только через Grafana Explore | агрегация логов pod'ов |
Prometheus **не хранит логи** — для логов используйте Grafana → Explore → datasource **Loki**.
Установка Loki/Promtail: `./scripts/deploy-monitoring-logs.sh`
## Grafana
### Вход
http://grafana.sova.local — **admin** / пароль:
```bash
kubectl -n monitoring get secret kube-prometheus-grafana \
-o jsonpath='{.data.admin-password}' | base64 -d && echo
```
![Grafana login](../screenshots/12-grafana-login.png)
### Главная
Дашборды kube-prometheus (CPU, memory, pod restarts). Полезно для общего health кластера:
![Grafana home](../screenshots/13-grafana-home.png)
### Loki — логи приложений
**Explore** (иконка компаса) → datasource **Loki** → LogQL:
```logql
{namespace="sova-test"}
```
Уточнение по pod:
```logql
{namespace="sova-test", pod=~"backend.*"} |= "error"
```
![Grafana Explore Loki](../screenshots/14-grafana-loki-explore.png)
::: tip Нет логов?
1. `./scripts/deploy-monitoring-logs.sh`
2. Проверьте Promtail: `kubectl get pods -n monitoring -l app.kubernetes.io/name=promtail`
3. В Grafana: Configuration → Data sources → Loki должен быть **green**
:::
### Типовые сценарии
| Задача | Действие |
|--------|----------|
| 500 от API | Loki `{namespace="sova-test", pod=~"backend.*"}` |
| CronJob упал | `{namespace="sova-test"} \|= "backend-sync-doctors"` |
| Ingress 502 | `{namespace="ingress-nginx"}` |
## Prometheus
Отдельный UI без логина (test-контур).
### Graph — PromQL запросы
http://prometheus.sova.local/graph
Примеры:
```promql
up # живые targets
rate(http_requests_total[5m]) # RPS (если есть метрика)
container_memory_working_set_bytes{namespace="sova-test"}
```
![Prometheus Graph](../screenshots/15-prometheus-graph.png)
### Targets — кто отдаёт метрики
http://prometheus.sova.local/targets
**UP** (зелёный) — scrape OK. **DOWN** — проверьте ServiceMonitor / pod.
![Prometheus Targets](../screenshots/16-prometheus-targets.png)
### Быстрая проверка «всё живо»
Запрос `up` за последний час:
![Prometheus up query](../screenshots/17-prometheus-up-query.png)
Значение **1** — target доступен, **0** — проблема.
## Сводка: куда смотреть
```mermaid
flowchart LR
subgraph metrics["Метрики"]
prom["Prometheus<br/>prometheus.sova.local"]
graf_m["Grafana dashboards"]
end
subgraph logs["Логи"]
loki["Loki"]
graf_l["Grafana Explore"]
promtail["Promtail"]
end
pods["Pod logs"] --> promtail --> loki --> graf_l
pods --> prom
prom --> graf_m
```
| Симптом | Куда |
|---------|------|
| Медленный API, restarts | Grafana dashboards / Prometheus `container_*` |
| Ошибка в коде, stack trace | Grafana → Loki |
| ServiceMonitor не работает | Prometheus → Targets |
| Нет datasource Loki | `./scripts/deploy-monitoring-logs.sh` |
Назад: [Gitea CI/CD](./gitea-ci) · [ArgoCD](./argocd)