Skip to main content
Version: 2.x

Gauge

A Gauge is a metric representing a single numerical value that may be set or adjusted. A typical use of this metric would be to track the current memory usage.

With a gauge, the quantity of interest is the current value, as opposed to a counter where the quantity of interest is the cumulative values over time.

A gauge is a named variable of type Double that can change over time. It can either be set to an absolute value or relative to the current value.

APIโ€‹

object Metric {
def gauge(name: String): Gauge[Double] = ???
}

Use Caseโ€‹

The gauge metric type is the best choice for things that their values can go down as well as up, such as queue size, and we don't want to query their rates. Thus, they are used to measuring things that have a particular value at a certain point in time:

  • Memory Usage
  • Queue Size
  • In-Progress Request Counts
  • Temperature

Examplesโ€‹

Create a gauge that can be set to absolute values, it can be applied to effects yielding a Double:

import zio._
import zio.metrics._
val absoluteGauge = Metric.gauge("setGauge")

Now we can apply these gauges to effects having an output type Double. Note that we can instrument an effect with any number of aspects if the type constraints are satisfied:

for {
_ <- Random.nextDoubleBetween(0.0d, 100.0d) @@ absoluteGauge @@ countAll
} yield ()

ZIO Chat

๐ŸŒŸ Greetings from ZIO Chat! ๐ŸŒŸ Have questions about ZIO? Look no further! I'm here to be your ZIO guru. Whether you're a seasoned pro or just starting out, I've got answers tailored just for you. Fire away with your ZIO queries, and I'll hit you back with the best insights I've got. Let's dive into the world of ZIO together!