Реализовать лабораторную 7

This commit is contained in:
Krep4334
2026-12-01 17:47:59 +03:00
parent 20afc2c790
commit 9ffa60daef
89 changed files with 5054 additions and 69 deletions
+20
View File
@@ -0,0 +1,20 @@
groups:
- name: messenger
interval: 5s
rules:
- alert: MessengerHighErrors
expr: sum(rate(http_requests_total{status_class="5xx",route!~"/health/.*"}[1m])) / clamp_min(sum(rate(http_requests_total{route!~"/health/.*"}[1m])),0.001) > 0.2
for: 10s
labels:
severity: warning
annotations:
summary: API error ratio exceeds 20 percent
description: Inspect postgresql.transaction spans and db_pool_waiting. Restore db and verify ready.
- alert: MessengerQueueLag
expr: max(queue{measurement="oldest_seconds"}) > 10
for: 10s
labels:
severity: warning
annotations:
summary: Oldest unfinished job is older than ten seconds
description: Inspect worker_busy, jobs_processed_total and worker logs. Restore worker and verify backlog drains.
+7
View File
@@ -0,0 +1,7 @@
#!/bin/sh
set -eu
mkdir -p /tmp/db-tls
cp /tls/cert.pem /tls/key.pem /tmp/db-tls/
chown -R postgres:postgres /tmp/db-tls
chmod 600 /tmp/db-tls/key.pem
exec docker-entrypoint.sh "$@"
+401
View File
@@ -0,0 +1,401 @@
{
"uid": "messenger",
"title": "Messenger",
"schemaVersion": 40,
"panels": [
{
"id": 1,
"title": "RPS",
"type": "timeseries",
"datasource": {
"uid": "prometheus",
"type": "prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "reqps"
}
},
"gridPos": {
"x": 0,
"y": 0,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "sum(rate(http_requests_total{route!~\"/health/.*\"}[1m]))",
"refId": "A"
}
]
},
{
"id": 2,
"title": "Server error ratio",
"type": "timeseries",
"datasource": {
"uid": "prometheus",
"type": "prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "percentunit"
}
},
"gridPos": {
"x": 12,
"y": 0,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "sum(rate(http_requests_total{status_class=\"5xx\",route!~\"/health/.*\"}[1m])) / clamp_min(sum(rate(http_requests_total{route!~\"/health/.*\"}[1m])),0.001)",
"refId": "A"
}
]
},
{
"id": 3,
"title": "HTTP p50",
"type": "timeseries",
"datasource": {
"uid": "prometheus",
"type": "prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "s"
}
},
"gridPos": {
"x": 0,
"y": 8,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "histogram_quantile(0.5, sum by (le) (rate(http_duration_seconds_bucket[1m])))",
"refId": "A"
}
]
},
{
"id": 4,
"title": "HTTP p95",
"type": "timeseries",
"datasource": {
"uid": "prometheus",
"type": "prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "s"
}
},
"gridPos": {
"x": 12,
"y": 8,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "histogram_quantile(0.95, sum by (le) (rate(http_duration_seconds_bucket[1m])))",
"refId": "A"
}
]
},
{
"id": 5,
"title": "HTTP p99",
"type": "timeseries",
"datasource": {
"uid": "prometheus",
"type": "prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "s"
}
},
"gridPos": {
"x": 0,
"y": 16,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "histogram_quantile(0.99, sum by (le) (rate(http_duration_seconds_bucket[1m])))",
"refId": "A"
}
]
},
{
"id": 6,
"title": "Jobs by outcome",
"type": "timeseries",
"datasource": {
"uid": "prometheus",
"type": "prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "ops"
}
},
"gridPos": {
"x": 12,
"y": 16,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "sum by(outcome)(rate(jobs_processed_total[1m]))",
"refId": "A"
}
]
},
{
"id": 7,
"title": "Worker p95",
"type": "timeseries",
"datasource": {
"uid": "prometheus",
"type": "prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "s"
}
},
"gridPos": {
"x": 0,
"y": 24,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "histogram_quantile(0.95,sum by(le)(rate(job_duration_seconds_bucket[1m])))",
"refId": "A"
}
]
},
{
"id": 8,
"title": "Time to ready p95",
"type": "timeseries",
"datasource": {
"uid": "prometheus",
"type": "prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "s"
}
},
"gridPos": {
"x": 12,
"y": 24,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "histogram_quantile(0.95,sum by(le)(rate(attachment_ready_duration_seconds_bucket[1m])))",
"refId": "A"
}
]
},
{
"id": 9,
"title": "Queue depth",
"type": "timeseries",
"datasource": {
"uid": "prometheus",
"type": "prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "short"
}
},
"gridPos": {
"x": 0,
"y": 32,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "max(queue{measurement=\"depth\"})",
"refId": "A"
}
]
},
{
"id": 10,
"title": "Oldest job",
"type": "timeseries",
"datasource": {
"uid": "prometheus",
"type": "prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "s"
}
},
"gridPos": {
"x": 12,
"y": 32,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "max(queue{measurement=\"oldest_seconds\"})",
"refId": "A"
}
]
},
{
"id": 11,
"title": "DB pool used",
"type": "timeseries",
"datasource": {
"uid": "prometheus",
"type": "prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "short"
}
},
"gridPos": {
"x": 0,
"y": 40,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "db_pool_used",
"refId": "A"
}
]
},
{
"id": 12,
"title": "DB pool waiting",
"type": "timeseries",
"datasource": {
"uid": "prometheus",
"type": "prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "short"
}
},
"gridPos": {
"x": 12,
"y": 40,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "db_pool_waiting",
"refId": "A"
}
]
},
{
"id": 13,
"title": "Worker busy",
"type": "timeseries",
"datasource": {
"uid": "prometheus",
"type": "prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "short"
}
},
"gridPos": {
"x": 0,
"y": 48,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "worker_busy",
"refId": "A"
}
]
},
{
"id": 14,
"title": "Process peak RSS",
"type": "timeseries",
"datasource": {
"uid": "prometheus",
"type": "prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "bytes"
}
},
"gridPos": {
"x": 12,
"y": 48,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "process_memory_bytes",
"refId": "A"
}
]
},
{
"id": 15,
"title": "Process CPU",
"type": "timeseries",
"datasource": {
"uid": "prometheus",
"type": "prometheus"
},
"fieldConfig": {
"defaults": {
"unit": "percentunit"
}
},
"gridPos": {
"x": 0,
"y": 56,
"w": 12,
"h": 8
},
"targets": [
{
"expr": "rate(process_cpu_seconds_total[1m])",
"refId": "A"
}
]
}
],
"time": {
"from": "now-15m",
"to": "now"
}
}
@@ -0,0 +1,6 @@
apiVersion: 1
providers:
- name: Messenger
type: file
options:
path: /var/lib/grafana/dashboards
+34
View File
@@ -0,0 +1,34 @@
global
log stdout format raw local0
defaults
mode http
log global
option httplog
option http-server-close
timeout connect 1s
timeout client 15s
timeout server 12s
timeout http-request 8s
timeout check 1s
retries 0
resolvers docker
nameserver dns 127.0.0.11:53
resolve_retries 2
timeout resolve 500ms
timeout retry 500ms
hold valid 1s
hold nx 1s
frontend messenger
bind :8443 ssl crt /tls/bundle.pem
default_backend api
backend api
balance roundrobin
option httpchk GET /health/ready
http-check expect status 200
default-server check inter 1s fall 2 rise 1 resolvers docker resolve-prefer ipv4 init-addr libc,none
server api-a api-a:8443 ssl verify required ca-file /tls/ca.pem crt /tls/bundle.pem verifyhost api-a
server api-b api-b:8443 ssl verify required ca-file /tls/ca.pem crt /tls/bundle.pem verifyhost api-b
+25
View File
@@ -0,0 +1,25 @@
auth_enabled: false
server:
http_listen_port: 3100
http_listen_address: 127.0.0.1
grpc_listen_address: 127.0.0.1
common:
path_prefix: /loki
replication_factor: 1
ring:
kvstore:
store: inmemory
storage:
filesystem:
chunks_directory: /loki/chunks
rules_directory: /loki/rules
instance_addr: 127.0.0.1
schema_config:
configs:
- from: 2024-01-01
store: tsdb
object_store: filesystem
schema: v13
index:
prefix: index_
period: 24h
+11
View File
@@ -0,0 +1,11 @@
ui = true
disable_mlock = true
storage "file" { path = "/bao/data" }
listener "tcp" {
address = "0.0.0.0:8200"
tls_cert_file = "/tls/cert.pem"
tls_key_file = "/tls/key.pem"
tls_client_ca_file = "/tls/ca.pem"
}
api_addr = "https://openbao:8200"
+69
View File
@@ -0,0 +1,69 @@
receivers:
otlp:
protocols:
http:
endpoint: 127.0.0.1:4318
processors:
memory_limiter:
check_interval: 1s
limit_mib: 128
spike_limit_mib: 32
batch:
send_batch_size: 128
timeout: 2s
exporters:
prometheus:
endpoint: 127.0.0.1:8889
resource_to_telemetry_conversion:
enabled: true
otlphttp/tempo:
endpoint: https://tempo:4319
sending_queue:
queue_size: 128
retry_on_failure:
max_elapsed_time: 10s
max_interval: 5s
tls:
ca_file: /tls/ca.pem
cert_file: /tls/cert.pem
key_file: /tls/key.pem
otlphttp/loki:
endpoint: https://loki:3101/otlp
sending_queue:
queue_size: 128
retry_on_failure:
max_elapsed_time: 10s
max_interval: 5s
tls:
ca_file: /tls/ca.pem
cert_file: /tls/cert.pem
key_file: /tls/key.pem
service:
pipelines:
metrics:
receivers:
- otlp
processors:
- memory_limiter
- batch
exporters:
- prometheus
traces:
receivers:
- otlp
processors:
- memory_limiter
- batch
exporters:
- otlphttp/tempo
logs:
receivers:
- otlp
processors:
- memory_limiter
- batch
exporters:
- otlphttp/loki
telemetry:
metrics:
level: none
+3
View File
@@ -0,0 +1,3 @@
local all all trust
hostssl all all all scram-sha-256
hostnossl all all all reject
+15
View File
@@ -0,0 +1,15 @@
global:
scrape_interval: 5s
scrape_configs:
- job_name: messenger
scheme: https
static_configs:
- targets:
- otel-collector:8890
tls_config:
ca_file: /tls/ca.pem
cert_file: /tls/cert.pem
key_file: /tls/key.pem
server_name: otel-collector
rule_files:
- /etc/prometheus/alerts.yaml
+27
View File
@@ -0,0 +1,27 @@
server:
http_listen_port: 3200
http_listen_address: 127.0.0.1
grpc_listen_address: 127.0.0.1
distributor:
receivers:
otlp:
protocols:
http:
endpoint: 127.0.0.1:4318
storage:
trace:
backend: local
local:
path: /var/tempo/traces
wal:
path: /var/tempo/wal
compactor:
compaction:
block_retention: 24h
ingester:
lifecycler:
address: 127.0.0.1
ring:
kvstore:
store: inmemory
replication_factor: 1
+10
View File
@@ -0,0 +1,10 @@
{
"listen": 8443,
"backend": 8080,
"clients": {
"lb": [],
"operator": [
"GET"
]
}
}
+10
View File
@@ -0,0 +1,10 @@
{
"listen": 8443,
"backend": 8080,
"clients": {
"lb": [],
"operator": [
"GET"
]
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"listen": 6380,
"backend": 6379,
"clients": {
"worker": [],
"dispatcher": []
}
}
+10
View File
@@ -0,0 +1,10 @@
{
"listen": 6380,
"backend": 6379,
"clients": {
"api-a": [],
"api-b": [],
"worker": [],
"dispatcher": []
}
}
+15
View File
@@ -0,0 +1,15 @@
{
"listen": 3101,
"backend": 3100,
"clients": {
"otel-collector": [
"POST"
],
"grafana": [
"GET"
],
"operator": [
"GET"
]
}
}
+18
View File
@@ -0,0 +1,18 @@
{
"listen": 4319,
"backend": 4318,
"clients": {
"api-a": [
"POST"
],
"api-b": [
"POST"
],
"worker": [
"POST"
],
"dispatcher": [
"POST"
]
}
}
+9
View File
@@ -0,0 +1,9 @@
{
"listen": 8890,
"backend": 8889,
"clients": {
"prometheus": [
"GET"
]
}
}
+12
View File
@@ -0,0 +1,12 @@
{
"listen": 9091,
"backend": 9090,
"clients": {
"grafana": [
"GET"
],
"operator": [
"GET"
]
}
}
+37
View File
@@ -0,0 +1,37 @@
{
"listen": 9002,
"backend": 9000,
"clients": {
"api-a": [
"HEAD",
"GET",
"PUT"
],
"api-b": [
"HEAD",
"GET",
"PUT"
],
"worker": [
"HEAD",
"GET",
"PUT",
"DELETE"
],
"s3-init": [
"HEAD",
"GET",
"PUT"
],
"operator": [
"HEAD",
"GET",
"PUT",
"DELETE"
]
},
"write_prefixes": {
"api-a": "/messenger-attachments/staging/",
"api-b": "/messenger-attachments/staging/"
}
}
+9
View File
@@ -0,0 +1,9 @@
{
"listen": 4319,
"backend": 4318,
"clients": {
"otel-collector": [
"POST"
]
}
}
+12
View File
@@ -0,0 +1,12 @@
{
"listen": 3201,
"backend": 3200,
"clients": {
"grafana": [
"GET"
],
"operator": [
"GET"
]
}
}