Skip to main content
A Gauge instrument that records non-additive values of type A. Gauges are used to record values that are not additive, such as room temperature or CPU usage.

Type Signature

trait Gauge[F[_], A]
Type Parameters:
  • F[_] - the higher-kinded type of a polymorphic effect
  • A - the type of values to record. Must have a MeasurementValue instance. Long and Double are supported out of the box.

Creating a Gauge

Gauges are created using the Meter API:
val meter: Meter[IO] = ???

val gauge: IO[Gauge[IO, Double]] =
  meter.gauge[Double]("cpu.usage")
    .withUnit("%")
    .withDescription("Current CPU usage percentage")
    .create

Backend Methods

record

Records a value with a set of attributes.
value
A
required
The value to record.
attributes
immutable.Iterable[Attribute[_]]
required
The set of attributes to associate with the value.
Returns: F[Unit] Example:
gauge.flatMap { g =>
  g.record(
    75.5,
    Attribute(AttributeKey.string("cpu.core"), "core-0")
  )
}

Builder Methods

withUnit

Sets the unit of measure for this gauge.
unit
String
required
The measurement unit. Must be 63 or fewer ASCII characters.
Returns: Gauge.Builder[F, A] Reference: Instrument Unit

withDescription

Sets the description for this gauge.
description
String
required
The description of the gauge.
Returns: Gauge.Builder[F, A] Reference: Instrument Description

create

Creates a Gauge with the configured unit and description. Returns: F[Gauge[F, A]]

See Also

Build docs developers (and LLMs) love