class Crometheus::Metric::LabeledMetric(LabelType, MetricType)

Overview

LabeledMetric is a generic type that acts as a collection of Metric objects exported under the same metric name, but with different labelsets. It takes two type parameters, one for the type of Metric to to collect, and one NamedTuple mapping label names to String values. Since this is cumbersome to type out, you generally won't refer to LabeledMetric directly in your code; instead, use Metric.[] or Crometheus.alias to generate an appropriate LabeledMetric type.

Storing labelsets as NamedTuples allows the compiler to enforce the constraint that every metric in the collection have the same set of label names.

Defined in:

crometheus/metric.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class Crometheus::Metric

docstring : String docstring, name : Symbol name, samples(&block : Sample -> 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?

Constructor Detail

def self.new(name : Symbol, docstring : String, register_with : Crometheus::Registry | Nil = Crometheus.default_registry, **metric_params) #

Creates a LabeledMetric, saving **metric_params for passage to the constructors of each metric in the collection.


[View source]

Class Method Detail

def self.type #

Returns MetricType.type. See Metric::Type.


[View source]

Instance Method Detail

def [](**labels : **LabelType) #

Fetches the metric with the given labelset. Takes one keyword argument for each of this metric's labels.


[View source]
def clear #

Deletes all metrics from the collection.


[View source]
def get_labels : Array(LabelType) #

Returns an array of every labelset currently ascribed to a metric.


[View source]
def remove(**labels : **LabelType) #

Deletes the metric with the given labelset from the collection. Takes one keyword argument for each of this metric's labels.


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

Iteratively calls #samples on each metric in the collection, yielding each received Sample. See Metric#samples.


[View source]