class Crometheus::Gauge

Overview

Gauge is a Metric type that stores a single value internally. This value can be modified freely via instance methods.

require "crometheus/gauge"

body_temperature = Crometheus::Gauge.new(
  :body_temperature, "Human body temperature")
body_temperature.set 98.6

# Running a fever...
body_temperature.inc 1.8
# Partial recovery
body_temperature.dec 0.6

body_temperature.get # => 99.8

Defined in:

crometheus/gauge.cr

Class Method Summary

Instance Method Summary

Instance methods inherited from class Crometheus::Metric

docstring : String docstring, name : Symbol name, samples(&block : Sample -> Nil) : Nil samples

Constructor methods inherited from class Crometheus::Metric

new(name : Symbol, docstring : String, register_with : Crometheus::Registry | Nil = Crometheus.default_registry) new

Class methods inherited from class Crometheus::Metric

type type, valid_label?(label : Symbol) : Bool valid_label?

Class Method Detail

def self.type #

Returns Type::Gauge. See Metric.type.


[View source]

Instance Method Detail

def count_concurrent(&) #

Increments the gauge value, yields, then decrements the gauge value. Wrap your event handlers with this to find out how many events are being processed at a time.


[View source]
def dec(x : Int | Float = 1.0) #

Decrements the gauge value by the given number, or 1.0.


[View source]
def get : Float64 #

Fetches the gauge value.


[View source]
def inc(x : Int | Float = 1.0) #

Increments the gauge value by the given number, or 1.0.


[View source]
def measure_runtime(&) #

Yields, then sets the gauge value to the block's runtime.


[View source]
def samples(&block : Sample -> Nil) : Nil #

Yields a single Sample bearing the gauge value. See Metric#samples.


[View source]
def set(x : Int | Float) #

Sets the gauge value to the given number.


[View source]
def set_to_current_time #

Sets the gauge value to the current UNIX timestamp.


[View source]