عرض المقاييس باستخدام Prometheus
تتبّع معدل الطلبات والأخطاء والمدة.
عرض المقاييس باستخدام Prometheus درس مجاني في MLOps Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في MLOps Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة MLOps Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Logs vs Metrics
Logs tell the story of one request. Metrics are numbers aggregated over many requests, so you can see trends like rate and error count at a glance. 📈
Meet Prometheus
Prometheus is the standard tool for collecting these numbers. Your service exposes metrics, and Prometheus regularly reads them for you.
Pull, Not Push
Prometheus uses a pull model: it scrapes a metrics URL on your service every few seconds. Your job is just to expose that endpoint.
The Python Client
The prometheus_client library lets your Python service define and serve metrics with almost no boilerplate.
from prometheus_client import Counter, Histogram, start_http_serverA Counter Counts Up
A Counter only ever increases. It is perfect for totals like how many predictions your model has served since startup.
predictions = Counter("predictions_total", "Total predictions served")
predictions.inc()A Histogram Times Things
A Histogram records a distribution, ideal for request duration. It buckets values so you can later read p50 and p99 latency.
latency = Histogram("predict_seconds", "Prediction latency in seconds")
with latency.time():
model.predict(x)Labels Add Dimensions
Labels split one metric by category, like model version or status. Then you can compare error rates per version side by side.
errors = Counter("errors_total", "Errors", ["model"])
errors.labels(model="churn-v3").inc()Expose the /metrics Endpoint
Prometheus scrapes a path conventionally named /metrics. The client can serve it for you on its own port.
start_http_server(8000)
# metrics now live at http://localhost:8000/metricsWhat a Metric Looks Like
On that endpoint each metric is plain text: a name, optional labels, and a value. Prometheus reads this format on every scrape.
predictions_total 1423.0
predict_seconds_bucket{le="0.1"} 1390.0Configure the Scrape
Tell Prometheus where to look by adding your service as a target in its config. Then it pulls metrics on a fixed interval.
scrape_configs:
- job_name: model-api
static_configs:
- targets: ["model-api:8000"]Pick the Right Type
Rule of thumb: use a Counter for things that only grow, a Histogram for durations, and a Gauge for values that go up and down.
Quick Check
You want to track request latency so you can later read p99. Which Prometheus metric type fits?
Recap
You exposed a /metrics endpoint with prometheus_client, using Counters and Histograms plus labels. Prometheus now pulls live numbers from your model service. ✅
الأسئلة الشائعة
هل درس «عرض المقاييس باستخدام Prometheus» مجاني؟
نعم — نص درس «عرض المقاييس باستخدام Prometheus» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة MLOps Academy، انتقل إلى CoddyKit PRO. تتضمن دورة MLOps Academy 4 دروس في المجموع.
ماذا ستتعلم في «عرض المقاييس باستخدام Prometheus»؟
تتبّع معدل الطلبات والأخطاء والمدة. تتمرن على MLOps Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ MLOps Academy؟
لا تُشترط خبرة سابقة. MLOps Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «عرض المقاييس باستخدام Prometheus»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس MLOps Academy هذا؟
نعم. كل درس في MLOps Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- سجلات منظمة للتنبؤات
- عرض المقاييس باستخدام Prometheus
- بناء لوحة Grafana
- التنبيه عند ارتفاعات زمن الاستجابة والأخطاء