About

A counter is a metrics type that:

  • increments its value by one starting from 0.
  • is reset to zero when:
    • the service restarts.
    • a maximum value is reached
  • is used to record occurrences of events
  • is plotted with a rate function into some specific interval.

This is the same as many counters in the world such as the mileage counter in a car.

Without rate aggregation over a time window, this metric is not really useful and represents only:

  • the velocity (the rapidity with which the counter is incremented)
  • and the longevity of the service.

Usage / Example

They are used to measure the rate (the throughput) at which some event is occurring over a given time interval.

Example:

  • the number of pages loaded
  • customer arrivals
  • in a queue, counters can measure things like the rate at which items are being inserted and removed.

Report

A counter reports:

  • the number of observations,
  • its current value
  • the minimum and maximum values.

Example

Micrometer

1)

Counter counter = Counter
    .builder("counter")
    .baseUnit("beans") // optional
    .description("a description of what this counter does") // optional
    .tags("region", "test") // optional
    .register(registry);