module Crometheus

Overview

Crometheus is a Prometheus client library for instrumenting programs written in the Crystal programming language. The official site is located at https://gitlab.com/ezrast/crometheus.

Defined in:

crometheus.cr
crometheus/counter.cr
crometheus/exceptions.cr
crometheus/gauge.cr
crometheus/histogram.cr
crometheus/metric.cr
crometheus/middleware/http_collector.cr
crometheus/registry.cr
crometheus/sample.cr
crometheus/standard_exports.cr
crometheus/stringify.cr
crometheus/summary.cr
crometheus/version.cr

Constant Summary

VERSION = "0.2.0"

Class Method Summary

Macro Summary

Class Method Detail

def self.default_registry(include_standard_exports = true) #

Returns the default Registry. All new Metric instances get registered to this by default.

The first time this is called, setting include_standard_exports to false will pass that argument to Registry#new. This is done so that the user may exclude process statistics from the default registry by calling .default_registry(false) prior to creating any metrics.


[View source]
def self.make_standard_exports(*args, **kwargs) #

Checks for system capabilities and instantiates the appropriate StandardExports type with the given arguments. Will return an instance of either StandardExports or StandardExports::ProcFSExports. Unless disabled, each new Registry object will call this automatically at creation. See Registry#new and .default_registry.


[View source]
def self.stringify(ff : Float64) : String | Float64 #

Represents NaN's and infinities in the same format as Prometheus. Prometheus represents infinities as "+Inf" or "-Inf" and NaN's as "NaN". We want to use those representations instead of the ones Crystal uses, to ensure compatability and minimize surprise in histogram labels. Note that this only performs a conversion to String if the Float64 has one of the mentioned values; this is to avoid extra String allocations in use cases like io << stringify(my_float). If you want a guaranteed String returned you'll still need to use to_s on the result.


[View source]

Macro Detail

macro alias(assignment) #

Convenience macro for aliasing a constant identifier to a Metric::LabeledMetric type. Unfortunately, the Metric.[] macro breaks type inference when used to initialize a class or instance variable. This can be worked around by using this macro to generate a friendly alias that allows the compiler to do type inference. The syntax is exactly the same as the ordinary alias keyword, except that the aliased type must be a Metric::LabeledMetric specified with the notation documented in Metric.[]. See Crystal issue #4039 for more information.

require "crometheus/counter"

class TollBooth
  Crometheus.alias CarCounter = Crometheus::Counter[:make, :model]

  def initialize
    @money = Crometheus::Counter.new(:money, "Fees collected")
    # Non-labeled metrics can be instantiated normally
    @counts = CarCounter.new(:cars, "Number of cars driven")
  end

  def count_car(make, model)
    @money.inc(5)
    @counts[make: make, model: model].inc
  end
end

[View source]