liveBook · Manning

Counter

As explained in Machine Learning Platform Engineering

A counter is a monotonically nondecreasing metric intended to count occurrences such as requests.

A counter is a cumulative metric for occurrences such as HTTP requests or ranked recommendations. Its value increases over time and can reset to zero when the application restarts. section 3.5 section 11.1.2

Implement a counter in an application by:

  • Defining it with the Prometheus client library and a name and description. section 3.5
  • Incrementing it with its inc method when the tracked event occurs. section 3.5
  • Exposing the application's /metrics endpoint so Prometheus can scrape the value. section 3.5
  • Querying and charting the resulting time series in Prometheus and Grafana. section 3.5 section 11.1.2

Counting ranked recommendations

A movie recommender can increment a Counter whenever ranked movies are present in a request. Plotting that counter in Grafana reveals cumulative activity and helps teams monitor trends or detect anomalies. section 11.1.2

Figure 3.17 Application 1 and Application 2 expose an endpoint for metrics. Prometheus scrapes those metrics, which are then visualized by Grafana. Alertmanager uses those metrics to check if any alerts need to be routed to a channel; in this case, it’s an email.
A diagram of a diagram

AI-generated content may be incorrect.

Trace the production path from application metrics endpoints through Prometheus scraping and Grafana visualization, with Alertmanager available for routing alerts. section 3.5

How Machine Learning Platform Engineering covers it

How deep it goes
Defines monotonicity, demonstrates declaration and incrementing, and distinguishes counters from gauges and histograms.
Examples
Counts HTTP requests and ranked-movie responses, then visualizes cumulative activity as Grafana time series.
What it assumes
Assumes an instrumented application and monitoring stack while teaching Counter declaration, incrementing, and exposure.
What you can do after
Apply it via prometheus-client by defining a Counter, incrementing events, exposing /metrics, and charting activity.
How it connects
Connects Prometheus scraping, Grafana dashboards, PromQL queries, metrics endpoints, and application monitoring.

Also explained in

Compare how 4 books explain counter →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning Platform Engineering. The section links point to the parts of the book it draws on.