Prometheus.ex v3.0.5 Prometheus.Metric.Gauge View Source

Gauge metric, to report instantaneous values.

Gauge is a metric that represents a single numerical value that can arbitrarily go up and down.

A Gauge is typically used for measured values like temperatures or current memory usage, but also "counts" that can go up and down, like the number of running processes.

Example use cases for Gauges:

  • Inprogress requests;
  • Number of items in a queue;
  • Free memory;
  • Total memory;
  • Temperature.

Example:

defmodule MyPoolInstrumenter do

  use Prometheus.Metric

  ## to be called at app/supervisor startup.
  ## to tolerate restarts use declare.
  def setup() do
    Gauge.declare([name: :my_pool_size,
                   help: "Pool size."])

    Gauge.declare([name: :my_pool_checked_out,
                   help: "Number of sockets checked out from the pool"])
  end

  def set_size(size) do
    Gauge.set([name: :my_pool_size], size)
  end

  def track_checked_out_sockets(checkout_fun) do
    Gauge.track_inprogress([name: :my_pool_checked_out], checkout_fun.())
  end

  def track_checked_out_sockets_block(socket) do
    Gauge.track_inprogress([name: :my_pool_checked_out]) do
      # checkout code
      socket
    end
  end

end

Link to this section Summary

Functions

Decrements the gauge identified by spec by value

Creates a gauge using spec. If a gauge with the same spec exists returns false

Increments the gauge identified by spec by value

Creates a gauge using spec

Removes gauge series identified by spec

Resets the value of the gauge identified by spec

Sets the gauge identified by spec to value

Tracks the amount of time spent executing body

Sets the gauge identified by spec to the current unixtime

Sets the gauge identified by spec to the number of currently executing bodys

Returns the value of the gauge identified by spec

Link to this section Functions

Decrements the gauge identified by spec by value.

Raises Prometheus.InvalidValueError exception if value isn't a number.
Raises Prometheus.UnknownMetricError exception if a gauge for spec can't be found.
Raises Prometheus.InvalidMetricArityError exception if labels count mismatch.

Creates a gauge using spec. If a gauge with the same spec exists returns false.

Raises Prometheus.MissingMetricSpecKeyError if required spec key is missing.
Raises Prometheus.InvalidMetricNameError if metric name is invalid.
Raises Prometheus.InvalidMetricHelpError if help is invalid.
Raises Prometheus.InvalidMetricLabelsError if labels isn't a list.
Raises Prometheus.InvalidMetricNameError if label name is invalid.
Raises Prometheus.InvalidValueError exception if duration_unit is unknown or doesn't match metric name.

Increments the gauge identified by spec by value.

Raises Prometheus.InvalidValueError exception if value isn't a number.
Raises Prometheus.UnknownMetricError exception if a gauge for spec can't be found.
Raises Prometheus.InvalidMetricArityError exception if labels count mismatch.

Creates a gauge using spec.

Raises Prometheus.MissingMetricSpecKeyError if required spec key is missing.
Raises Prometheus.InvalidMetricNameError if metric name is invalid.
Raises Prometheus.InvalidMetricHelpError if help is invalid.
Raises Prometheus.InvalidMetricLabelsError if labels isn't a list.
Raises Prometheus.InvalidMetricNameError if label name is invalid.
Raises Prometheus.InvalidValueError exception if duration_unit is unknown or doesn't match metric name.
Raises Prometheus.MFAlreadyExistsError if a gauge with the same spec exists.

Removes gauge series identified by spec.

Raises Prometheus.UnknownMetricError exception if a gauge for spec can't be found.
Raises Prometheus.InvalidMetricArityError exception if labels count mismatch.

Resets the value of the gauge identified by spec.

Raises Prometheus.UnknownMetricError exception if a gauge for spec can't be found.
Raises Prometheus.InvalidMetricArityError exception if labels count mismatch.

Sets the gauge identified by spec to value.

Raises Prometheus.InvalidValueError exception if value isn't a number or :undefined.
Raises Prometheus.UnknownMetricError exception if a gauge for spec can't be found.
Raises Prometheus.InvalidMetricArityError exception if labels count mismatch.

Link to this macro

set_duration(spec, body) View Source (macro)

Tracks the amount of time spent executing body.

Raises Prometheus.UnknownMetricError exception if a gauge for spec can't be found.
Raises Prometheus.InvalidMetricArityError exception if labels count mismatch. Raises Prometheus.InvalidValueError exception if fun isn't a function or block.

Link to this function

set_to_current_time(spec) View Source

Sets the gauge identified by spec to the current unixtime.

Raises Prometheus.UnknownMetricError exception if a gauge for spec can't be found.
Raises Prometheus.InvalidMetricArityError exception if labels count mismatch.

Link to this macro

track_inprogress(spec, body) View Source (macro)

Sets the gauge identified by spec to the number of currently executing bodys.

Raises Prometheus.UnknownMetricError exception if a gauge for spec can't be found.
Raises Prometheus.InvalidMetricArityError exception if labels count mismatch. Raises Prometheus.InvalidValueError exception if fun isn't a function or block.

Returns the value of the gauge identified by spec.

If duration unit set, value will be converted to the duration unit. Read more here.

Raises Prometheus.UnknownMetricError exception if a gauge for spec can't be found.
Raises Prometheus.InvalidMetricArityError exception if labels count mismatch.