Prometheus و Grafana و Loki و OpenTelemetry
الهدف من الدرس
Section titled “الهدف من الدرس”ستفهم أدوار Prometheus و Grafana و Loki و OpenTelemetry، وكيف تربطها بمؤشرات Production مثل latency و error rate و saturation.
الفكرة ببساطة
Section titled “الفكرة ببساطة”Observability تجيب عن: ماذا يحدث؟ لماذا يحدث؟ من تأثر؟ وهل نحتاج rollback؟
stack عملي
Section titled “stack عملي”flowchart LR App[Application] --> Metrics[Prometheus] App --> Logs[Loki] App --> Traces[OpenTelemetry Collector] Metrics --> Grafana[Grafana] Logs --> Grafana Traces --> Grafana Metrics --> Alertmanager[Alertmanager]تثبيت kube-prometheus-stack
Section titled “تثبيت kube-prometheus-stack”helm repo add prometheus-community https://prometheus-community.github.io/helm-chartshelm repo updatehelm upgrade --install monitoring prometheus-community/kube-prometheus-stack \ --namespace monitoring --create-namespacekubectl -n monitoring get podsExpected output:
monitoring-grafana-... 3/3 Runningmonitoring-kube-prometheus... 1/1 Runningmonitoring-prometheus... 2/2 Runningمؤشرات مهمة
Section titled “مؤشرات مهمة”| المؤشر | لماذا يهم؟ |
|---|---|
| Request rate | حجم traffic |
| Error rate | نسبة الفشل |
| Duration p95/p99 | تجربة المستخدم |
| CPU/Memory | ضغط الموارد |
| Restarts | استقرار Pods |
مثال ServiceMonitor
Section titled “مثال ServiceMonitor”apiVersion: monitoring.coreos.com/v1kind: ServiceMonitormetadata: name: web labels: release: monitoringspec: selector: matchLabels: app: web endpoints: - port: metrics path: /metrics interval: 30sLab: تشغيل monitoring stack محلي
الهدف: تثبيت kube-prometheus-stack وفحص Pods وفتح Grafana.
Prerequisites
Section titled “Prerequisites”- Helm مثبت.
- Cluster محلي بموارد كافية.
helm repo add prometheus-community https://prometheus-community.github.io/helm-chartshelm repo updatehelm upgrade --install monitoring prometheus-community/kube-prometheus-stack --namespace monitoring --create-namespacekubectl -n monitoring get podskubectl -n monitoring port-forward svc/monitoring-grafana 3000:80Expected output
Section titled “Expected output”Forwarding from 127.0.0.1:3000 -> 3000Cleanup
Section titled “Cleanup”helm uninstall monitoring -n monitoringkubectl delete namespace monitoringأخطاء شائعة
Section titled “أخطاء شائعة”| الخطأ | الحل |
|---|---|
| alerts كثيرة بلا action | اجعل كل alert مرتبطا بإجراء واضح |
| logs فقط بدون metrics | لن تعرف التأثير الكلي |
| metrics بلا labels جيدة | صعب فصل services والبيئات |