forked from mtusi2026/mtusi2026lab6
ЛР6: OpenTelemetry, Collector, Prometheus/Loki/Tempo, Grafana, алерты, исследование цены наблюдаемости
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Генератор dashboard JSON (infra/grafana/dashboards/messenger.json). Запуск: python infra/grafana/build_dashboard.py
|
||||
Dashboard хранится в Git как JSON и импортируется provisioning-ом автоматически; генератор — только удобство правки."""
|
||||
import json
|
||||
import os
|
||||
|
||||
PROM = {"type": "prometheus", "uid": "prometheus"}
|
||||
LOKI = {"type": "loki", "uid": "loki"}
|
||||
TEMPO = {"type": "tempo", "uid": "tempo"}
|
||||
panel_id = [0]
|
||||
|
||||
|
||||
def _id():
|
||||
panel_id[0] += 1
|
||||
return panel_id[0]
|
||||
|
||||
|
||||
def stat_or_ts(title, exprs, x, y, w=8, h=7, unit="short", kind="timeseries", desc="", thresholds=None, ds=PROM, legends=None):
|
||||
p = {"id": _id(), "type": kind, "title": title, "description": desc, "datasource": ds,
|
||||
"gridPos": {"x": x, "y": y, "w": w, "h": h},
|
||||
"targets": [{"refId": chr(65 + i), "expr": e, "datasource": ds, "legendFormat": (legends or [""] * len(exprs))[i]}
|
||||
for i, e in enumerate(exprs)],
|
||||
"fieldConfig": {"defaults": {"unit": unit, "custom": {"lineWidth": 1, "fillOpacity": 10}}, "overrides": []},
|
||||
"options": {"legend": {"displayMode": "list", "placement": "bottom"}}}
|
||||
if thresholds:
|
||||
p["fieldConfig"]["defaults"]["thresholds"] = {"mode": "absolute", "steps": thresholds}
|
||||
return p
|
||||
|
||||
|
||||
def row(title, y):
|
||||
return {"id": _id(), "type": "row", "title": title, "gridPos": {"x": 0, "y": y, "w": 24, "h": 1}, "collapsed": False, "panels": []}
|
||||
|
||||
|
||||
NB = '{http_route!~"/health.*"}'
|
||||
panels = []
|
||||
y = 0
|
||||
panels.append(row("API (бизнес-запросы без /health) — запросы, ошибки, задержки", y)); y += 1
|
||||
panels += [
|
||||
stat_or_ts("RPS по маршрутам", ['sum by (http_route) (rate(http_server_request_duration_seconds_count%s[1m]))' % NB], 0, y,
|
||||
unit="reqps", legends=["{{http_route}}"], desc="Единицы: запросов в секунду. Источник: http_server_request_duration_seconds_count."),
|
||||
stat_or_ts("Доля ошибок 5xx (SLI)", ['sli:http_error_ratio:1m'], 8, y, unit="percentunit",
|
||||
desc="Числитель: 5xx; знаменатель: все запросы кроме /health. 4xx (в т.ч. неверный пароль) не считаются отказом сервиса.",
|
||||
thresholds=[{"color": "green", "value": None}, {"color": "red", "value": 0.05}]),
|
||||
stat_or_ts("Latency p50 / p95 / p99", [
|
||||
'histogram_quantile(0.50, sum by (le) (rate(http_server_request_duration_seconds_bucket%s[1m])))' % NB,
|
||||
'histogram_quantile(0.95, sum by (le) (rate(http_server_request_duration_seconds_bucket%s[1m])))' % NB,
|
||||
'histogram_quantile(0.99, sum by (le) (rate(http_server_request_duration_seconds_bucket%s[1m])))' % NB],
|
||||
16, y, unit="s", legends=["p50", "p95", "p99"],
|
||||
desc="Процентили считаются из суммарной гистограммы всех реплик (sum by le), а не усреднением p95 реплик."),
|
||||
]
|
||||
y += 7
|
||||
panels += [
|
||||
stat_or_ts("RPS по статус-кодам", ['sum by (http_response_status_code) (rate(http_server_request_duration_seconds_count%s[1m]))' % NB],
|
||||
0, y, unit="reqps", legends=["{{http_response_status_code}}"]),
|
||||
stat_or_ts("Latency p95 по маршрутам", ['histogram_quantile(0.95, sum by (le, http_route) (rate(http_server_request_duration_seconds_bucket%s[1m])))' % NB],
|
||||
8, y, unit="s", legends=["{{http_route}}"]),
|
||||
stat_or_ts("DB pool: занято / простаивает / ожидают", ['sum(db_client_connections_usage{state="used"})', 'sum(db_client_connections_usage{state="idle"})',
|
||||
'sum(db_client_connections_waiting)'], 16, y, unit="short",
|
||||
legends=["used", "idle", "waiting"], desc="Пул соединений PostgreSQL по всем репликам API. Рост waiting — насыщение пула."),
|
||||
]
|
||||
y += 7
|
||||
panels.append(row("Задания (worker) и очередь", y)); y += 1
|
||||
panels += [
|
||||
stat_or_ts("Задания по исходам", ['sum by (outcome) (rate(messenger_jobs_processed_total[1m]))'], 0, y, unit="ops", legends=["{{outcome}}"],
|
||||
desc="ready — успешно; failed — финальная ошибка; retried — временная ошибка, запланирован повтор; noop — повторная доставка."),
|
||||
stat_or_ts("Длительность обработки p50 / p95 (worker)", [
|
||||
'histogram_quantile(0.50, sum by (le) (rate(messenger_job_duration_seconds_bucket[1m])))',
|
||||
'histogram_quantile(0.95, sum by (le) (rate(messenger_job_duration_seconds_bucket[1m])))'], 8, y, unit="s", legends=["p50", "p95"]),
|
||||
stat_or_ts("Время до ready p50 / p95", [
|
||||
'histogram_quantile(0.50, sum by (le) (rate(messenger_job_time_to_ready_seconds_bucket[1m])))',
|
||||
'histogram_quantile(0.95, sum by (le) (rate(messenger_job_time_to_ready_seconds_bucket[1m])))'], 16, y, unit="s", legends=["p50", "p95"],
|
||||
desc="От устойчивого приёма загрузки (202) до ready. Включает ожидание в очереди."),
|
||||
]
|
||||
y += 7
|
||||
panels += [
|
||||
stat_or_ts("Глубина очереди (queued + processing)", ['max(messenger_queue_depth)'], 0, y, unit="short", legends=["jobs"]),
|
||||
stat_or_ts("Возраст старейшей задачи", ['max(messenger_queue_oldest_job_age_seconds)'], 8, y, unit="s", legends=["oldest"],
|
||||
thresholds=[{"color": "green", "value": None}, {"color": "red", "value": 30}],
|
||||
desc="Backlog — не задержка обработки: показывает, как долго ждёт самое старое задание."),
|
||||
stat_or_ts("Worker: занято / ёмкость", ['sum(messenger_worker_busy)', 'sum(messenger_worker_capacity)'], 16, y, legends=["busy", "capacity"],
|
||||
desc="Насыщение worker: busy == capacity при растущей очереди означает нехватку мощности."),
|
||||
]
|
||||
y += 7
|
||||
panels.append(row("Ресурсы процессов", y)); y += 1
|
||||
panels += [
|
||||
stat_or_ts("RSS по сервисам", ['sum by (service_name) (process_memory_rss_bytes)'], 0, y, unit="bytes", legends=["{{service_name}}"]),
|
||||
stat_or_ts("CPU по сервисам (ядра)", ['sum by (service_name) (rate(process_cpu_time_seconds_total[1m]))'], 8, y, unit="short", legends=["{{service_name}}"],
|
||||
desc="rate накопленного CPU-времени процесса: 1.0 = одно ядро."),
|
||||
stat_or_ts("Collector: очередь экспорта и отказы", ['sum by (exporter) (otelcol_exporter_queue_size)',
|
||||
'sum by (exporter) (rate(otelcol_exporter_send_failed_spans[1m]))',
|
||||
'sum(rate(otelcol_processor_memory_limiter_refused_spans[1m]))'], 16, y, legends=["queue {{exporter}}", "failed spans {{exporter}}", "refused (memory_limiter)"],
|
||||
desc="Поведение Collector при недоступном backend: ограниченная очередь, отказы, memory_limiter."),
|
||||
]
|
||||
y += 7
|
||||
panels.append(row("Логи и алерты", y)); y += 1
|
||||
panels.append({"id": _id(), "type": "logs", "title": "Структурные логи (API и worker), ошибки и предупреждения", "datasource": LOKI,
|
||||
"gridPos": {"x": 0, "y": y, "w": 16, "h": 10},
|
||||
"targets": [{"refId": "A", "datasource": LOKI, "expr": '{service_name=~"messenger-.*"} | detected_level=~"warn|warning|error|ERROR|WARN"'}],
|
||||
"options": {"showTime": True, "wrapLogMessage": True, "enableLogDetails": True, "sortOrder": "Descending"}})
|
||||
panels.append({"id": _id(), "type": "alertlist", "title": "Алерты (firing / pending)", "datasource": PROM,
|
||||
"gridPos": {"x": 16, "y": y, "w": 8, "h": 10},
|
||||
"options": {"alertInstanceLabelFilter": "", "alertName": "", "dashboardAlerts": False, "groupBy": [], "groupMode": "default",
|
||||
"maxItems": 20, "sortOrder": 1, "stateFilter": {"firing": True, "pending": True, "noData": True, "normal": False, "error": True}}})
|
||||
y += 10
|
||||
panels.append({"id": _id(), "type": "traces", "title": "Последние трассы API (Tempo)", "datasource": TEMPO,
|
||||
"gridPos": {"x": 0, "y": y, "w": 24, "h": 8},
|
||||
"targets": [{"refId": "A", "datasource": TEMPO, "queryType": "traceql", "query": '{ resource.service.name = "messenger-api" }', "limit": 20}]})
|
||||
|
||||
dashboard = {"uid": "messenger-overview", "title": "Messenger: API, очередь, worker", "tags": ["messenger", "lab6"], "timezone": "browser",
|
||||
"schemaVersion": 39, "version": 1, "refresh": "5s", "time": {"from": "now-15m", "to": "now"}, "panels": panels,
|
||||
"annotations": {"list": []}, "templating": {"list": []}}
|
||||
out = os.path.join(os.path.dirname(os.path.abspath(__file__)), "dashboards", "messenger.json")
|
||||
with open(out, "w", encoding="utf-8") as fh:
|
||||
json.dump(dashboard, fh, ensure_ascii=False, indent=1)
|
||||
print("saved", out)
|
||||
@@ -0,0 +1,917 @@
|
||||
{
|
||||
"uid": "messenger-overview",
|
||||
"title": "Messenger: API, очередь, worker",
|
||||
"tags": [
|
||||
"messenger",
|
||||
"lab6"
|
||||
],
|
||||
"timezone": "browser",
|
||||
"schemaVersion": 39,
|
||||
"version": 1,
|
||||
"refresh": "5s",
|
||||
"time": {
|
||||
"from": "now-15m",
|
||||
"to": "now"
|
||||
},
|
||||
"panels": [
|
||||
{
|
||||
"id": 1,
|
||||
"type": "row",
|
||||
"title": "API (бизнес-запросы без /health) — запросы, ошибки, задержки",
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"w": 24,
|
||||
"h": 1
|
||||
},
|
||||
"collapsed": false,
|
||||
"panels": []
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"type": "timeseries",
|
||||
"title": "RPS по маршрутам",
|
||||
"description": "Единицы: запросов в секунду. Источник: http_server_request_duration_seconds_count.",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 1,
|
||||
"w": 8,
|
||||
"h": 7
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum by (http_route) (rate(http_server_request_duration_seconds_count{http_route!~\"/health.*\"}[1m]))",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"legendFormat": "{{http_route}}"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "reqps",
|
||||
"custom": {
|
||||
"lineWidth": 1,
|
||||
"fillOpacity": 10
|
||||
}
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"type": "timeseries",
|
||||
"title": "Доля ошибок 5xx (SLI)",
|
||||
"description": "Числитель: 5xx; знаменатель: все запросы кроме /health. 4xx (в т.ч. неверный пароль) не считаются отказом сервиса.",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 8,
|
||||
"y": 1,
|
||||
"w": 8,
|
||||
"h": 7
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sli:http_error_ratio:1m",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"legendFormat": ""
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "percentunit",
|
||||
"custom": {
|
||||
"lineWidth": 1,
|
||||
"fillOpacity": 10
|
||||
},
|
||||
"thresholds": {
|
||||
"mode": "absolute",
|
||||
"steps": [
|
||||
{
|
||||
"color": "green",
|
||||
"value": null
|
||||
},
|
||||
{
|
||||
"color": "red",
|
||||
"value": 0.05
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"type": "timeseries",
|
||||
"title": "Latency p50 / p95 / p99",
|
||||
"description": "Процентили считаются из суммарной гистограммы всех реплик (sum by le), а не усреднением p95 реплик.",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 16,
|
||||
"y": 1,
|
||||
"w": 8,
|
||||
"h": 7
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "histogram_quantile(0.50, sum by (le) (rate(http_server_request_duration_seconds_bucket{http_route!~\"/health.*\"}[1m])))",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"legendFormat": "p50"
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"expr": "histogram_quantile(0.95, sum by (le) (rate(http_server_request_duration_seconds_bucket{http_route!~\"/health.*\"}[1m])))",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"legendFormat": "p95"
|
||||
},
|
||||
{
|
||||
"refId": "C",
|
||||
"expr": "histogram_quantile(0.99, sum by (le) (rate(http_server_request_duration_seconds_bucket{http_route!~\"/health.*\"}[1m])))",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"legendFormat": "p99"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "s",
|
||||
"custom": {
|
||||
"lineWidth": 1,
|
||||
"fillOpacity": 10
|
||||
}
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"type": "timeseries",
|
||||
"title": "RPS по статус-кодам",
|
||||
"description": "",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 8,
|
||||
"w": 8,
|
||||
"h": 7
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum by (http_response_status_code) (rate(http_server_request_duration_seconds_count{http_route!~\"/health.*\"}[1m]))",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"legendFormat": "{{http_response_status_code}}"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "reqps",
|
||||
"custom": {
|
||||
"lineWidth": 1,
|
||||
"fillOpacity": 10
|
||||
}
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"type": "timeseries",
|
||||
"title": "Latency p95 по маршрутам",
|
||||
"description": "",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 8,
|
||||
"y": 8,
|
||||
"w": 8,
|
||||
"h": 7
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "histogram_quantile(0.95, sum by (le, http_route) (rate(http_server_request_duration_seconds_bucket{http_route!~\"/health.*\"}[1m])))",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"legendFormat": "{{http_route}}"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "s",
|
||||
"custom": {
|
||||
"lineWidth": 1,
|
||||
"fillOpacity": 10
|
||||
}
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"type": "timeseries",
|
||||
"title": "DB pool: занято / простаивает / ожидают",
|
||||
"description": "Пул соединений PostgreSQL по всем репликам API. Рост waiting — насыщение пула.",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 16,
|
||||
"y": 8,
|
||||
"w": 8,
|
||||
"h": 7
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum(db_client_connections_usage{state=\"used\"})",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"legendFormat": "used"
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"expr": "sum(db_client_connections_usage{state=\"idle\"})",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"legendFormat": "idle"
|
||||
},
|
||||
{
|
||||
"refId": "C",
|
||||
"expr": "sum(db_client_connections_waiting)",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"legendFormat": "waiting"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "short",
|
||||
"custom": {
|
||||
"lineWidth": 1,
|
||||
"fillOpacity": 10
|
||||
}
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"type": "row",
|
||||
"title": "Задания (worker) и очередь",
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 15,
|
||||
"w": 24,
|
||||
"h": 1
|
||||
},
|
||||
"collapsed": false,
|
||||
"panels": []
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"type": "timeseries",
|
||||
"title": "Задания по исходам",
|
||||
"description": "ready — успешно; failed — финальная ошибка; retried — временная ошибка, запланирован повтор; noop — повторная доставка.",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 16,
|
||||
"w": 8,
|
||||
"h": 7
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum by (outcome) (rate(messenger_jobs_processed_total[1m]))",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"legendFormat": "{{outcome}}"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "ops",
|
||||
"custom": {
|
||||
"lineWidth": 1,
|
||||
"fillOpacity": 10
|
||||
}
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"type": "timeseries",
|
||||
"title": "Длительность обработки p50 / p95 (worker)",
|
||||
"description": "",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 8,
|
||||
"y": 16,
|
||||
"w": 8,
|
||||
"h": 7
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "histogram_quantile(0.50, sum by (le) (rate(messenger_job_duration_seconds_bucket[1m])))",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"legendFormat": "p50"
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_job_duration_seconds_bucket[1m])))",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"legendFormat": "p95"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "s",
|
||||
"custom": {
|
||||
"lineWidth": 1,
|
||||
"fillOpacity": 10
|
||||
}
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 11,
|
||||
"type": "timeseries",
|
||||
"title": "Время до ready p50 / p95",
|
||||
"description": "От устойчивого приёма загрузки (202) до ready. Включает ожидание в очереди.",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 16,
|
||||
"y": 16,
|
||||
"w": 8,
|
||||
"h": 7
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "histogram_quantile(0.50, sum by (le) (rate(messenger_job_time_to_ready_seconds_bucket[1m])))",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"legendFormat": "p50"
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_job_time_to_ready_seconds_bucket[1m])))",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"legendFormat": "p95"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "s",
|
||||
"custom": {
|
||||
"lineWidth": 1,
|
||||
"fillOpacity": 10
|
||||
}
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 12,
|
||||
"type": "timeseries",
|
||||
"title": "Глубина очереди (queued + processing)",
|
||||
"description": "",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 23,
|
||||
"w": 8,
|
||||
"h": 7
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "max(messenger_queue_depth)",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"legendFormat": "jobs"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "short",
|
||||
"custom": {
|
||||
"lineWidth": 1,
|
||||
"fillOpacity": 10
|
||||
}
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 13,
|
||||
"type": "timeseries",
|
||||
"title": "Возраст старейшей задачи",
|
||||
"description": "Backlog — не задержка обработки: показывает, как долго ждёт самое старое задание.",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 8,
|
||||
"y": 23,
|
||||
"w": 8,
|
||||
"h": 7
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "max(messenger_queue_oldest_job_age_seconds)",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"legendFormat": "oldest"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "s",
|
||||
"custom": {
|
||||
"lineWidth": 1,
|
||||
"fillOpacity": 10
|
||||
},
|
||||
"thresholds": {
|
||||
"mode": "absolute",
|
||||
"steps": [
|
||||
{
|
||||
"color": "green",
|
||||
"value": null
|
||||
},
|
||||
{
|
||||
"color": "red",
|
||||
"value": 30
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 14,
|
||||
"type": "timeseries",
|
||||
"title": "Worker: занято / ёмкость",
|
||||
"description": "Насыщение worker: busy == capacity при растущей очереди означает нехватку мощности.",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 16,
|
||||
"y": 23,
|
||||
"w": 8,
|
||||
"h": 7
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum(messenger_worker_busy)",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"legendFormat": "busy"
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"expr": "sum(messenger_worker_capacity)",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"legendFormat": "capacity"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "short",
|
||||
"custom": {
|
||||
"lineWidth": 1,
|
||||
"fillOpacity": 10
|
||||
}
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 15,
|
||||
"type": "row",
|
||||
"title": "Ресурсы процессов",
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 30,
|
||||
"w": 24,
|
||||
"h": 1
|
||||
},
|
||||
"collapsed": false,
|
||||
"panels": []
|
||||
},
|
||||
{
|
||||
"id": 16,
|
||||
"type": "timeseries",
|
||||
"title": "RSS по сервисам",
|
||||
"description": "",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 31,
|
||||
"w": 8,
|
||||
"h": 7
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum by (service_name) (process_memory_rss_bytes)",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"legendFormat": "{{service_name}}"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "bytes",
|
||||
"custom": {
|
||||
"lineWidth": 1,
|
||||
"fillOpacity": 10
|
||||
}
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 17,
|
||||
"type": "timeseries",
|
||||
"title": "CPU по сервисам (ядра)",
|
||||
"description": "rate накопленного CPU-времени процесса: 1.0 = одно ядро.",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 8,
|
||||
"y": 31,
|
||||
"w": 8,
|
||||
"h": 7
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum by (service_name) (rate(process_cpu_time_seconds_total[1m]))",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"legendFormat": "{{service_name}}"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "short",
|
||||
"custom": {
|
||||
"lineWidth": 1,
|
||||
"fillOpacity": 10
|
||||
}
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 18,
|
||||
"type": "timeseries",
|
||||
"title": "Collector: очередь экспорта и отказы",
|
||||
"description": "Поведение Collector при недоступном backend: ограниченная очередь, отказы, memory_limiter.",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 16,
|
||||
"y": 31,
|
||||
"w": 8,
|
||||
"h": 7
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"expr": "sum by (exporter) (otelcol_exporter_queue_size)",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"legendFormat": "queue {{exporter}}"
|
||||
},
|
||||
{
|
||||
"refId": "B",
|
||||
"expr": "sum by (exporter) (rate(otelcol_exporter_send_failed_spans[1m]))",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"legendFormat": "failed spans {{exporter}}"
|
||||
},
|
||||
{
|
||||
"refId": "C",
|
||||
"expr": "sum(rate(otelcol_processor_memory_limiter_refused_spans[1m]))",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"legendFormat": "refused (memory_limiter)"
|
||||
}
|
||||
],
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"unit": "short",
|
||||
"custom": {
|
||||
"lineWidth": 1,
|
||||
"fillOpacity": 10
|
||||
}
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"options": {
|
||||
"legend": {
|
||||
"displayMode": "list",
|
||||
"placement": "bottom"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 19,
|
||||
"type": "row",
|
||||
"title": "Логи и алерты",
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 38,
|
||||
"w": 24,
|
||||
"h": 1
|
||||
},
|
||||
"collapsed": false,
|
||||
"panels": []
|
||||
},
|
||||
{
|
||||
"id": 20,
|
||||
"type": "logs",
|
||||
"title": "Структурные логи (API и worker), ошибки и предупреждения",
|
||||
"datasource": {
|
||||
"type": "loki",
|
||||
"uid": "loki"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 39,
|
||||
"w": 16,
|
||||
"h": 10
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"datasource": {
|
||||
"type": "loki",
|
||||
"uid": "loki"
|
||||
},
|
||||
"expr": "{service_name=~\"messenger-.*\"} | detected_level=~\"warn|warning|error|ERROR|WARN\""
|
||||
}
|
||||
],
|
||||
"options": {
|
||||
"showTime": true,
|
||||
"wrapLogMessage": true,
|
||||
"enableLogDetails": true,
|
||||
"sortOrder": "Descending"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 21,
|
||||
"type": "alertlist",
|
||||
"title": "Алерты (firing / pending)",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 16,
|
||||
"y": 39,
|
||||
"w": 8,
|
||||
"h": 10
|
||||
},
|
||||
"options": {
|
||||
"alertInstanceLabelFilter": "",
|
||||
"alertName": "",
|
||||
"dashboardAlerts": false,
|
||||
"groupBy": [],
|
||||
"groupMode": "default",
|
||||
"maxItems": 20,
|
||||
"sortOrder": 1,
|
||||
"stateFilter": {
|
||||
"firing": true,
|
||||
"pending": true,
|
||||
"noData": true,
|
||||
"normal": false,
|
||||
"error": true
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 22,
|
||||
"type": "traces",
|
||||
"title": "Последние трассы API (Tempo)",
|
||||
"datasource": {
|
||||
"type": "tempo",
|
||||
"uid": "tempo"
|
||||
},
|
||||
"gridPos": {
|
||||
"x": 0,
|
||||
"y": 49,
|
||||
"w": 24,
|
||||
"h": 8
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"refId": "A",
|
||||
"datasource": {
|
||||
"type": "tempo",
|
||||
"uid": "tempo"
|
||||
},
|
||||
"queryType": "traceql",
|
||||
"query": "{ resource.service.name = \"messenger-api\" }",
|
||||
"limit": 20
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"annotations": {
|
||||
"list": []
|
||||
},
|
||||
"templating": {
|
||||
"list": []
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
apiVersion: 1
|
||||
providers:
|
||||
- name: messenger
|
||||
orgId: 1
|
||||
folder: Messenger
|
||||
type: file
|
||||
disableDeletion: false
|
||||
allowUiUpdates: false
|
||||
updateIntervalSeconds: 10
|
||||
options:
|
||||
path: /var/lib/grafana/dashboards
|
||||
@@ -0,0 +1,41 @@
|
||||
apiVersion: 1
|
||||
# Источники данных Grafana: Prometheus (метрики), Loki (логи), Tempo (трассы). Связи: лог -> трасса (derivedFields),
|
||||
# трасса -> логи (tracesToLogsV2), трасса -> метрики.
|
||||
datasources:
|
||||
- name: Prometheus
|
||||
uid: prometheus
|
||||
type: prometheus
|
||||
access: proxy
|
||||
url: http://prometheus:9090
|
||||
isDefault: true
|
||||
jsonData:
|
||||
timeInterval: 5s
|
||||
- name: Loki
|
||||
uid: loki
|
||||
type: loki
|
||||
access: proxy
|
||||
url: http://loki:3100
|
||||
jsonData:
|
||||
derivedFields:
|
||||
- name: trace_id
|
||||
matcherType: label
|
||||
matcherRegex: trace_id
|
||||
url: "$${__value.raw}"
|
||||
datasourceUid: tempo
|
||||
- name: Tempo
|
||||
uid: tempo
|
||||
type: tempo
|
||||
access: proxy
|
||||
url: http://tempo:3200
|
||||
jsonData:
|
||||
tracesToLogsV2:
|
||||
datasourceUid: loki
|
||||
spanStartTimeShift: "-1m"
|
||||
spanEndTimeShift: "1m"
|
||||
filterByTraceID: true
|
||||
customQuery: true
|
||||
query: '{service_name="$${__span.tags["service.name"]}"} | trace_id="$${__span.traceId}"'
|
||||
tracesToMetrics:
|
||||
datasourceUid: prometheus
|
||||
serviceMap:
|
||||
datasourceUid: prometheus
|
||||
Reference in New Issue
Block a user