Murat ÖZDEMİR 03a3c5fb70 feat(monitoring): add BE microservice health monitoring with dedup and readable crash alerts
Adds two-layer BE-* microservice monitoring: an aggregate Stack Services replica check across the iklimco and monitoring Swarm stacks (checks/swarm_services.py), and per-service actuator/DNS health checks driven by a new microservice_monitors section in monitors.yml (checks/actuator.py). BE-* services are excluded from the Stack Services aggregate so a single service incident produces exactly one Slack alert instead of two.

Fixes found during QA of the initial implementation: RabbitMQ host derivation generated nonexistent numbered DNS names instead of using the real single-service topology, RabbitMQ and Patroni cluster checks did not push down status on node/member shortfall, and the etcd cluster check still used a hardcoded node list and quorum threshold instead of deriving them from CLUSTER_SIZE_ETCD.

Also hardens Docker event crash alerting: excludes ephemeral Gitea Actions runner containers from crash notifications, skips alerts for containers Swarm intentionally stopped (rolling update/scale-down, detected via task DesiredState) instead of alerting on every deploy, and adds human-readable exit code descriptions to the Slack message.

Uptime Kuma monitor names are now prefixed with "iklim [env]" since test and prod share one Kuma instance and unprefixed names collided. setup_uptime_kuma.py gained an ensure_push_monitor helper and a microservice push-monitor creation pass. Removed state.py and the unused restart_threshold config field (dead code, no longer referenced anywhere).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-10 17:31:11 +03:00

Environment Monitoring

Tüm izleme servisleri docker-stack-monitoring.yml stack'inde yönetilir: Portainer, node-exporter, cAdvisor, Loki ve Promtail.

Servisler

Portainer

Docker Swarm yönetim arayüzü.

  • portainer-agent — global mode, tüm node'larda çalışır; Docker socket ve volume bilgisini Portainer CE'ye aktarır
  • portainer — tek replica, manager node'da; portainer-net overlay üzerinden agent'lara bağlanır
  • Dış erişim SWAG üzerinden: portainer.iklim.co

node-exporter

Host / işletim sistemi metriklerini Prometheus'a aktarır. Her node'da çalışır (deploy.mode: global).

Toplanan metrikler: CPU kullanımı, bellek, disk I/O, ağ trafiği, sistem yükü, dosya sistemi doluluk oranları.

cAdvisor

Container ve Swarm servis bazlı kaynak tüketimini Prometheus'a aktarır. Her node'da çalışır (deploy.mode: global).

Toplanan metrikler: container başına CPU/bellek/ağ/disk I/O.

Loki

Container loglarını toplayan ve saklayan log aggregation servisi. Grafana'nın native Loki datasource entegrasyonu ile metriklerle birlikte sorgulanabilir.

  • Tek replica, node.labels.type == service node'unda çalışır
  • Log saklama süresi: 31 gün (limits_config.retention_period)
  • Konfigürasyon: build/loki/loki.yml

Promtail

Her node'daki container loglarını Docker API üzerinden toplayarak Loki'ye gönderir. Her node'da çalışır (deploy.mode: global).

  • Docker service discovery: container adı, servis adı, stack adı ve proje label'larını otomatik etiket olarak ekler
  • Konfigürasyon: build/promtail/promtail.yml

Health Agent

Cluster içi servis sağlığını Uptime Kuma'ya push eden Python servisi. Ayrıntılar için health-agent/README.md.


Grafana'da Log Görüntüleme

İlk Kurulum — Loki Datasource Ekleme

Loki deploy edildikten sonra tek seferlik yapılır:

  1. Grafana UI → Sol menü → Connections → Data sources
  2. Add new data sourceLoki seç
  3. URL: http://loki:3100
  4. Save & test — "Data source connected" mesajı görünmeli

Alternatif olarak template/grafana/provisioning/datasources/loki.yaml dosyasını Grafana'nın provisioning dizinine kopyalayarak otomatik yüklenebilir:

# Grafana veri dizinine provisioning dosyasını kopyala
cp template/grafana/provisioning/datasources/loki.yaml \
   <GRAFANA_DATA_DIR>/provisioning/datasources/loki.yaml
# Grafana'yı yeniden başlat
docker service update --force iklimco_grafana

Log Görüntüleme — Explore

  1. Sol menü → Explore (pusula ikonu)
  2. Üst sol köşeden datasource olarak Loki seç
  3. Label filters ile filtrele:
Etiket ıklama Örnek
service Swarm servis adı iklimco_vault
stack Stack adı iklimco
container Container adı iklimco_vault.1.xxx
project project label değeri co.iklim
logstream stdout / stderr stderr

LogQL Örnekleri

# Belirli bir servisin tüm logları
{service="iklimco_vault"}

# Tüm stack'teki hata logları
{stack="iklimco"} |= "ERROR"

# Exception içeren loglar (tüm servisler)
{project="co.iklim"} |= "Exception"

# APISIX erişim logları — sadece 5xx'ler
{service="iklimco_apisix"} | json | status >= 500

# Belirli zaman aralığında servis logları (UI'dan zaman seçimi de yapılabilir)
{service="iklimco_rabbitmq"} |= "error" | line_format "{{.line}}"

Metrik — Log Korelasyonu

Grafana'nın en güçlü özelliklerinden biri: bir Prometheus metriğinde anomali gördüğünde aynı zaman aralığındaki logları yan yana inceleyebilirsin.

  1. Prometheus dashboard panelinde anomali noktasına tıkla
  2. Explore linkine tıkla → aynı zaman aralığı Explore'da açılır
  3. Datasource'u Loki'ye geçir, ilgili servisi filtrele
  4. Metrik spike'ı ile log hataları aynı anda görünür

Dashboard'a Log Paneli Ekleme

Mevcut dashboard'lara log paneli eklemek için:

  1. Dashboard → EditAdd visualization
  2. Panel tipi: Logs seç
  3. Datasource: Loki
  4. Query: {service="<servis_adı>"}
  5. Deduplication seçeneğini açabilirsin (tekrar eden satırları gizler)

Ağ Yapısı

Network Tür Kullananlar
iklimco-net external overlay Portainer, node-exporter, cAdvisor, Loki, Promtail, Health Agent
portainer-net stack overlay portainer-agent ↔ portainer iletişimi

Deployment

docker stack deploy \
  --with-registry-auth \
  -c Environment_Monitoring/docker-stack-monitoring.yml \
  monitoring

Prod için Gitea workflow'u: Environment_Monitoring/.gitea/workflows/deploy-monitoring-prod.yml

Not: Loki ve Promtail custom image kullanır (build/loki/, build/promtail/). Deploy öncesinde imajların Harbor'a build edilip push edilmesi gerekir. .env dosyasında IMAGE_LOKI ve IMAGE_PROMTAIL değişkenlerinin tanımlı olması zorunludur.

Description
No description provided
Readme 276 KiB
Languages
Python 84.9%
Shell 13.6%
Smarty 0.8%
Dockerfile 0.7%