Metriken mit Prometheus bereitstellen
Verfolgen Sie Anfrage rate, Fehler und Dauer.
Metriken mit Prometheus bereitstellen ist eine kostenlose MLOps Academy-Lektion auf CoddyKit. Dies ist Lektion 2 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des MLOps Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der MLOps Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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. ✅
Häufig gestellte Fragen
Ist die Lektion „Metriken mit Prometheus bereitstellen“ kostenlos?
Ja — der vollständige Text von „Metriken mit Prometheus bereitstellen“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des MLOps Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der MLOps Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Metriken mit Prometheus bereitstellen“?
Verfolgen Sie Anfrage rate, Fehler und Dauer. Du übst MLOps Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um MLOps Academy zu starten?
Keine Vorkenntnisse erforderlich. MLOps Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 2 von 4.
Wie lange dauert die Lektion „Metriken mit Prometheus bereitstellen“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser MLOps Academy-Lektion Code schreiben und ausführen?
Ja. Jede MLOps Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Strukturierte Logs für Vorhersagen
- Metriken mit Prometheus bereitstellen
- Ein Grafana-Dashboard erstellen
- Bei Latenz- und Fehlerspitzen alarmieren