Add alert manager and telegram notifications

This commit is contained in:
Leo
2026-09-23 17:01:25 +05:00
parent f457c51dcb
commit 20e498e885
14 changed files with 110 additions and 24 deletions
+20
View File
@@ -0,0 +1,20 @@
route:
receiver: 'telegram'
group_wait: 30s
repeat_interval: 1h
receivers:
- name: 'telegram'
telegram_configs:
- bot_token: "{{ telegram_bot_token }}"
chat_id: {{ telegram_chat_id }}
message: >-
{% raw %}
{{ if eq .Status "firing" }}🔥{{ else }}✅{{ end }}
*{{ .GroupLabels.alertname }}*
{{ range .Alerts }}
*Сервер:* `{{ .Labels.instance }}`
*Статус:* {{ .Status }}
*Описание:* {{ .Annotations.description }}
{{ end }}
{% endraw %}
+30
View File
@@ -0,0 +1,30 @@
groups:
- name: main
rules:
# Алерт 1: Сервер недоступен
- alert: InstanceDown
expr: up == 0
for: 1m
annotations:
description: "{% raw %}Сервер {{ $labels.instance }} недоступен{% endraw %}"
# Алерт 2: Высокая загрузка CPU (любой сервер)
- alert: HighCpuLoad
expr: (1 - avg by(instance)(rate(node_cpu_seconds_total{mode="idle"}[1m]))) * 100 > 80
for: 1m
annotations:
description: >-
{% raw %}Сервер {{ $labels.instance }}: загрузка CPU {{ printf "%.1f" $value }}% (порог 80%){% endraw %}
# Алерт 3: Высокий трафик на general_server (сумма вход + выход > 10 МБ/с)
- alert: HighNetworkTraffic
expr: >-
sum by(instance) (
rate(node_network_receive_bytes_total{nodename="general_server", device!="lo"}[1m]) +
rate(node_network_transmit_bytes_total{nodename="general_server", device!="lo"}[1m])
) / 1024 / 1024 > 10
for: 1m
annotations:
description: >-
{% raw %}general_server: суммарный трафик {{ printf "%.1f" $value }} МБ/с превысил порог 10 МБ/с{% endraw %}
+11 -1
View File
@@ -7,6 +7,7 @@ services:
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
- ./prometheus-web.yml:/etc/prometheus/prometheus-web.yml:ro
- ./alerts.rules.yml:/etc/prometheus/alerts.rules.yml:ro
- prom_data:/prometheus
command:
@@ -22,7 +23,7 @@ services:
image: grafana/grafana:latest
container_name: grafana
ports:
- "3001:3000"
- "127.0.0.1:3001:3000"
volumes:
- ./grafana_provisioning/datasource.yml:/etc/grafana/provisioning/datasources/datasource.yml:ro
- grafana_data:/var/lib/grafana
@@ -37,6 +38,15 @@ services:
depends_on:
- prometheus
alertmanager:
image: prom/alertmanager:latest
container_name: alertmanager
volumes:
- ./alertmanager.yml:/etc/alertmanager/alertmanager.yml
ports:
- "127.0.0.1:9093:9093"
restart: unless-stopped
volumes:
prom_data:
grafana_data:
+12 -1
View File
@@ -7,6 +7,7 @@ services:
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
- ./prometheus-web.yml:/etc/prometheus/prometheus-web.yml:ro
- ./alerts.rules.yml:/etc/prometheus/alerts.rules.yml:ro
- prom_data:/prometheus
command:
@@ -22,7 +23,7 @@ services:
image: grafana/grafana:latest
container_name: grafana
ports:
- "127.0.0.1:3001:3000"
- "3001:3000"
volumes:
- ./grafana_provisioning/datasource.yml:/etc/grafana/provisioning/datasources/datasource.yml:ro
- grafana_data:/var/lib/grafana
@@ -37,6 +38,16 @@ services:
depends_on:
- prometheus
alertmanager:
image: prom/alertmanager:latest
container_name: alertmanager
volumes:
- ./alertmanager.yml:/etc/alertmanager/alertmanager.yml
ports:
- "127.0.0.1:9093:9093"
restart: unless-stopped
volumes:
prom_data:
grafana_data:
Binary file not shown.
Binary file not shown.
+1
View File
@@ -18,3 +18,4 @@ server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
+6
View File
@@ -21,3 +21,9 @@ scrape_configs:
nodename: "{{ host }}"
{% endfor %}
alerting:
alertmanagers:
- static_configs:
- targets: ['alertmanager:9093']
rule_files:
- /etc/prometheus/alerts.rules.yml
Binary file not shown.