moonbitstack/moonp8s/metric does not have a README file

    Collector

    pub(open) trait Collector {
    fn collect(Self) -> Array[MetricFamily]
    }

    A custom source of metric families. Implement this to contribute series whose shape the built-in metric types do not cover; the registry applies its prefix and constant labels to whatever collect returns.

    LabelSet

    pub(open) trait LabelSet {
    fn pairs(Self) -> Array[(String, String)]
    }

    A record that can name its own label pairs. Implementing this for a struct and using TypedFamily gives a family keyed by a typed label set instead of an array of strings.

    Metric

    pub(open) trait Metric {
    fn kind(Self) -> Kind
    fn points(Self) -> Array[Point]
    }

    Anything a registry can collect: a metric, a family of metrics, or a custom collector's contribution. Implement this to plug a new metric shape into a registry without changing the registry.

    Refused

    pub(all) suberror Refused {
    Refused(String)
    }

    The one error this library raises: a request it will not honour, with the reason in the message. Messages carry the offending value and, where a position is meaningful, an at offset counted from zero.

    Refused::message

    fn Refused::message(self : Refused) -> String

    The reason a request was refused.

    Counter

    pub struct Counter {
    // private fields
    }

    A monotonically increasing count. inc refuses a negative step because a counter that goes down is a gauge.
    impl Metric for Counter

    Counter::get

    fn Counter::get(self : Counter) -> Double

    The current count.

    Counter::inc

    fn Counter::inc(self : Counter, by? : Double, exemplar? : Exemplar) -> Unit raise Refused

    Increase the counter by by, keeping exemplar as the latest exemplar.

    Counter::kind

    fn Counter::kind(_self : Counter) -> Kind

    Counter::new

    fn Counter::new(created? : Double) -> Counter

    A counter at zero. created records when the series came into existence, for the _created series OpenMetrics exposes.

    Counter::points

    fn Counter::points(self : Counter) -> Array[Point]

    Counter::reset

    fn Counter::reset(self : Counter, created? : Double) -> Unit

    Restart the counter at zero, optionally dating the reset as a new creation time. Use this when a logical process restarts without restarting the program.

    A reset is a new series, so the creation time is the reset's: passing none clears it rather than leaving the old one in place, which would claim the restarted counter started when the old one did.

    Counter::shard

    fn Counter::shard(self : Counter) -> LocalCounter

    A shard of this counter. Many shards may feed one counter; each flushes its own accumulations.

    Entry

    type Entry

    Exemplar

    pub(all) struct Exemplar {
    labels : Array[(String, String)]
    value : Double
    timestamp : Double?
    }

    An exemplar ties a sample to the request that produced it: the request's labels, the observed value, and optionally when it was observed (Unix seconds).

    Exemplar::new

    fn Exemplar::new(labels : Array[(String, String)], value : Double, timestamp? : Double) -> Exemplar raise Refused

    Build an exemplar, refusing a label set over the OpenMetrics limit.

    Family

    pub struct Family[M] {
    // private fields
    }

    A family of metrics sharing one name and one fixed list of label names. The label names are fixed at construction; labels gets or creates the child for one combination of values.
    impl Metric for Family[M]

    Family::clear

    fn[M] Family::clear(self : Family[M]) -> Unit

    Drop every child.

    Family::kind

    fn[M : Metric] Family::kind(self : Family[M]) -> Kind

    Family::labels

    fn[M] Family::labels(self : Family[M], values : Array[String]) -> M raise Refused

    The child for values, created if this is the first time it is seen. A value count that does not match the family's label names is refused.

    Family::new

    fn[M : Metric] Family::new(names : Array[String], make : () -> M raise Refused) -> Family[M] raise Refused

    A family over names, creating a child with make on first sight.

    Family::points

    fn[M : Metric] Family::points(self : Family[M]) -> Array[Point]

    Family::remove

    fn[M] Family::remove(self : Family[M], values : Array[String]) -> Unit

    Drop the child for values if it exists.

    Family::size

    fn[M] Family::size(self : Family[M]) -> Int

    The number of children seen so far.

    FamilyEntry

    type FamilyEntry[M]

    Gauge

    pub struct Gauge {
    // private fields
    }

    An instantaneous value that may go up or down. set takes the timestamp to record, because this library never reads a clock; pass timestamp~ when the sample is worth dating.
    impl Metric for Gauge

    Gauge::dec

    fn Gauge::dec(self : Gauge, by? : Double) -> Unit

    Decrease the gauge by by.

    Gauge::get

    fn Gauge::get(self : Gauge) -> Double

    The current value.

    Gauge::inc

    fn Gauge::inc(self : Gauge, by? : Double) -> Unit

    Increase the gauge by by.

    Gauge::kind

    fn Gauge::kind(_self : Gauge) -> Kind

    Gauge::new

    fn Gauge::new(initial? : Double) -> Gauge

    A gauge at initial (zero unless given).

    Gauge::points

    fn Gauge::points(self : Gauge) -> Array[Point]

    Gauge::set

    fn Gauge::set(self : Gauge, v : Double, timestamp? : Double) -> Unit

    Set the gauge to v, optionally dating the sample.

    Gauge::set_function

    fn Gauge::set_function(self : Gauge, f : () -> Double) -> Unit

    Take the value from f instead of a stored number. While a function is set, set, inc, and dec do nothing, matching the Python client.

    GaugeHistogram

    pub struct GaugeHistogram {
    // private fields
    }

    A gauge histogram: the same buckets as a histogram, but the sum and count are a gauge's, and the wire format spells them _gsum and _gcount.

    GaugeHistogram::kind

    fn GaugeHistogram::kind(_self : GaugeHistogram) -> Kind

    GaugeHistogram::new

    fn GaugeHistogram::new(buckets? : Array[Double], created? : Double) -> GaugeHistogram raise Refused

    A gauge histogram over buckets (the shared defaults unless given).

    GaugeHistogram::observe

    fn GaugeHistogram::observe(self : GaugeHistogram, v : Double, exemplar? : Exemplar) -> Unit

    Record one observation.

    GaugeHistogram::points

    fn GaugeHistogram::points(self : GaugeHistogram) -> Array[Point]

    GaugeHistogram::snapshot

    fn GaugeHistogram::snapshot(self : GaugeHistogram) -> Point

    The snapshot of this gauge histogram.
    type Gk

    A Greenwald-Khanna sketch: it keeps a sorted summary of the observations so that a quantile can be answered to within epsilon of the rank using memory logarithmic in the number of observations. The targeted-quantile (CKMS) family generalises this sketch; a single epsilon is what a summary's quantile-and-error pairs reduce to.

    Histogram

    pub struct Histogram {
    // private fields
    }

    A histogram with cumulative buckets. Counts are kept per bucket and made cumulative on snapshot, which is what the wire format carries. With native it also keeps native buckets, or only those when no classic buckets were asked for.
    impl Metric for Histogram

    Histogram::kind

    fn Histogram::kind(_self : Histogram) -> Kind

    Histogram::new

    fn Histogram::new(buckets? : Array[Double], created? : Double, native? : Native, clock? : () -> Double) -> Histogram raise Refused

    A histogram over buckets. Without buckets it uses the shared defaults, or none at all when native is given, which is what client_golang does with a bucket factor and no bucket list. native adds native buckets with those settings; clock is the time in Unix seconds the native buckets' resets are measured by, the system clock unless given.

    Histogram::observe

    fn Histogram::observe(self : Histogram, v : Double, exemplar? : Exemplar) -> Unit

    Record one observation in the first bucket whose bound it does not exceed, or in the +Inf bucket when it exceeds every bound, and in its native bucket. NaN counts in the sum and the count but in no native bucket.

    Histogram::points

    fn Histogram::points(self : Histogram) -> Array[Point]

    Histogram::snapshot

    fn Histogram::snapshot(self : Histogram) -> Point

    The snapshot of this histogram: cumulative bucket counts, the sum, and the total count, with the retained exemplars, and the native buckets when it keeps them.

    Histogram::sum_value

    fn Histogram::sum_value(self : Histogram) -> Double

    The sum of the observations.

    Histogram::total

    fn Histogram::total(self : Histogram) -> Int64

    The number of observations.

    Info

    pub struct Info {
    // private fields
    }

    An info metric: a fixed set of labels whose value is always 1. It carries build and version metadata, which is why it never changes after creation.
    impl Metric for Info

    Info::kind

    fn Info::kind(_self : Info) -> Kind

    Info::labels

    fn Info::labels(self : Info) -> Array[(String, String)]

    The labels this info metric carries.

    Info::new

    fn Info::new(labels : Array[(String, String)]) -> Info raise Refused

    An info metric with these labels.

    Info::points

    fn Info::points(self : Info) -> Array[Point]

    Kind

    pub(all) enum Kind {
    Counter
    Gauge
    Histogram
    GaugeHistogram
    Summary
    Info
    StateSet
    Unknown
    }

    The kind of a metric, as spelled in the # TYPE line of an exposition.

    Kind::code

    fn Kind::code(self : Kind) -> String

    The wire spelling of this kind: counter, gauge, histogram, gaugehistogram, summary, info, stateset, or unknown.

    Kind::of

    fn Kind::of(name : String) -> Kind

    The kind a wire spelling names. untyped is the legacy spelling of unknown, and an unrecognised spelling is unknown rather than an error so that a newer peer's exposition still parses.

    LocalCounter

    pub struct LocalCounter {
    // private fields
    }

    A non-atomic shard of a counter. Increments land in the shard and are added to the shared counter on flush, which is the local accumulation the Rust client offers; it keeps a hot path off the shared value without requiring thread-local storage.

    LocalCounter::flush

    fn LocalCounter::flush(self : LocalCounter) -> Unit

    Add the shard's value to the shared counter and clear the shard.

    LocalCounter::get

    fn LocalCounter::get(self : LocalCounter) -> Double

    The shard's unflushed value.

    LocalCounter::inc

    fn LocalCounter::inc(self : LocalCounter, by? : Double) -> Unit raise Refused

    Increase the shard by by.

    LocalCounter::kind

    fn LocalCounter::kind(_self : LocalCounter) -> Kind

    LocalCounter::points

    fn LocalCounter::points(self : LocalCounter) -> Array[Point]

    LocalCounter::reset

    fn LocalCounter::reset(self : LocalCounter) -> Unit

    Drop the unflushed value.

    MetricFamily

    pub(all) struct MetricFamily {
    name : String
    kind : Kind
    help : String
    unit : String?
    metrics : Array[Point]
    }

    A family of series sharing one name, help text, kind, and optional unit. This is what an exposition is written from and what a parser produces.

    Native

    pub(all) struct Native {
    factor : Double
    zero_threshold : Double
    max_buckets : Int
    min_reset : Double
    max_zero_threshold : Double
    max_exemplars : Int
    exemplar_ttl : Double
    } derive(Eq,
    Debug
    )

    How a histogram keeps native buckets. Passed to Histogram::new as native, it adds them beside the classic buckets, or replaces those when no classic buckets are given.

    • factor: the largest ratio between the bounds of neighbouring buckets; the schema is the coarsest one that keeps within it. Must be above 1.
    • zero_threshold: observations whose absolute value is at most this go to the zero bucket.
    • max_buckets: once more buckets than this are populated, the histogram is reset if min_reset seconds have passed since the last reset, else the zero bucket is widened up to max_zero_threshold, else every bucket is made twice as wide. 0 is no limit.
    • min_reset: seconds between resets; 0 never resets. A widened or coarsened histogram goes back to its first resolution once this has passed.
    • max_exemplars, exemplar_ttl: how many exemplars the native buckets keep, and after how many seconds an old one is the first to go; max_exemplars 0 keeps none.

    Native::equal

    fn Native::equal(Native, Native) -> Bool

    Native::new

    fn Native::new(factor? : Double, zero_threshold? : Double, max_buckets? : Int, min_reset? : Double, max_zero_threshold? : Double, max_exemplars? : Int, exemplar_ttl? : Double) -> Native

    native with the settings named here changed.

    Native::not_equal

    fn Native::not_equal(x : Native, y : Native) -> Bool

    Native::to_repr

    Point

    pub(all) struct Point {
    labels : Array[(String, String)]
    value : Value
    timestamp : Double?
    created : Double?
    exemplars : Array[Exemplar]
    }

    One series of a family: its labels, its value, and the optional metadata OpenMetrics carries alongside it. created is when the series was created (Unix seconds); exemplars are the retained exemplars, matched to histogram buckets by the value that produced them.

    ProcessCollector

    pub struct ProcessCollector {
    // private fields
    }

    The seven process_* series the Rust client's process collector exposes: CPU time, open and maximum file descriptors, virtual and resident memory, start time, and thread count.

    ProcessCollector::collect

    ProcessCollector::new

    fn ProcessCollector::new(stats : ProcessStats, prefix? : String) -> ProcessCollector

    A process collector over stats. namespace prefixes every name, as the Rust client's namespace does.

    ProcessStats

    pub(all) struct ProcessStats {
    cpu_seconds : Double
    open_fds : Int64
    max_fds : Int64
    virtual_memory_bytes : Int64
    resident_memory_bytes : Int64
    start_time_seconds : Double
    threads : Int64
    }

    The process numbers a ProcessCollector exports. The caller reads them — this library performs no I/O — which keeps the collector portable across every target.

    Registry

    pub struct Registry {
    // private fields
    }

    The set of metrics one exposition exposes, with an optional name prefix and optional constant labels applied to everything registered. A registry refuses a metric name that is not a valid OpenMetrics name, a label name that is not a valid label name, a unit that is not a valid unit, and a name registered twice.

    Registry::add

    fn Registry::add(self : Registry, collector : &Collector) -> Unit

    Add a custom collector. Its families are exposed after the registered metrics, with this registry's prefix and labels applied.

    Registry::collect

    fn Registry::collect(self : Registry, at? : Double) -> Array[MetricFamily]

    The snapshot of everything registered: one family per registered metric or collector family, in registration order.

    at is the moment of the scrape. Every sample that does not already carry a timestamp is stamped with it, which is what a real scrape does: the exporter does not know when it will be read. A sample that was given a timestamp keeps it — a backfilled point is not the scrape's.

    Registry::counter

    fn Registry::counter(self : Registry, name : String, help : String, unit? : String) -> Counter raise Refused

    Create a counter, register it, and return it.

    Registry::gauge

    fn Registry::gauge(self : Registry, name : String, help : String, unit? : String) -> Gauge raise Refused

    Create a gauge, register it, and return it.

    Registry::histogram

    fn Registry::histogram(self : Registry, name : String, help : String, buckets? : Array[Double], unit? : String, native? : Native) -> Histogram raise Refused

    Create a histogram, register it, and return it. buckets and native are as Histogram::new takes them.

    Registry::new

    fn Registry::new(prefix? : String, labels? : Array[(String, String)]) -> Registry raise Refused

    An empty registry. prefix is prepended to every registered name, and labels is added to every series.

    Registry::register

    fn Registry::register(self : Registry, name : String, help : String, metric : &Metric, unit? : String) -> Unit raise Refused

    Register metric under name, with help and an optional unit. The unit is appended to the name on the wire.

    Registry::sub

    fn Registry::sub(self : Registry, prefix~ : String, labels? : Array[(String, String)]) -> Registry raise Refused

    A sub-registry whose names carry prefix after this registry's own prefix, and whose series carry this registry's labels plus labels.

    Sparse

    pub(all) struct Sparse {
    schema : Int
    zero_threshold : Double
    zero_count : Int64
    positive : Array[(Int, Int64)]
    negative : Array[(Int, Int64)]
    exemplars : Array[Exemplar]
    }

    The native buckets of a histogram at one moment. positive and negative hold the populated buckets as (key, count) in key order, bucket key covering (2^((key-1)/2^schema), 2^(key/2^schema)] on its side; zero_count counts the observations within zero_threshold of zero; exemplars are the ones kept for the native buckets.

    StateSet

    pub struct StateSet {
    // private fields
    }

    A set of named states, each true or false. A state set with exactly one true state is the Enum of the Python client.
    impl Metric for StateSet

    StateSet::exclusive

    fn StateSet::exclusive(states : Array[String]) -> StateSet

    A state set with exactly one state true: the first, which is the Python client's default.

    StateSet::get

    fn StateSet::get(self : StateSet, state : String) -> Bool

    Whether state is true.

    StateSet::kind

    fn StateSet::kind(_self : StateSet) -> Kind

    StateSet::new

    fn StateSet::new(states : Array[String]) -> StateSet

    A state set whose states all start false, in the order given.

    StateSet::points

    fn StateSet::points(self : StateSet) -> Array[Point]

    StateSet::set

    fn StateSet::set(self : StateSet, state : String) -> Unit

    Set one state true, leaving the others as they are.

    StateSet::set_many

    fn StateSet::set_many(self : StateSet, states : Map[String, Bool]) -> Unit

    Apply a whole map of states at once.

    StateSet::unset

    fn StateSet::unset(self : StateSet, state : String) -> Unit

    Set one state false.

    Summary

    pub struct Summary {
    // private fields
    }

    A summary: the count and sum of the observations, plus approximate quantiles when the constructor is given target quantiles and their permitted rank error.
    impl Metric for Summary

    Summary::kind

    fn Summary::kind(_self : Summary) -> Kind

    Summary::new

    fn Summary::new(quantiles? : Array[(Double, Double)], created? : Double) -> Summary raise Refused

    A summary. With quantiles (pairs of target quantile and permitted error), observations also feed a sketch so that snapshot can report those quantiles; without them the summary carries only count and sum, as the official clients do by default.

    Summary::observe

    fn Summary::observe(self : Summary, v : Double) -> Unit

    Record one observation.

    Summary::points

    fn Summary::points(self : Summary) -> Array[Point]

    Summary::snapshot

    fn Summary::snapshot(self : Summary) -> Point

    The snapshot of this summary: the configured quantiles (empty when none were configured), the sum, and the count.

    Summary::total

    fn Summary::total(self : Summary) -> Int64

    The number of observations.

    TypedChild

    type TypedChild[M]

    TypedFamily

    pub struct TypedFamily[L, M] {
    // private fields
    }

    A family keyed by a typed label set. Use this instead of Family when the label combination is better expressed as a record than as an array of strings; the record must implement LabelSet and be hashable and comparable.
    impl Metric for TypedFamily[L, M]

    TypedFamily::clear

    fn[L : Hash + Eq, M] TypedFamily::clear(self : TypedFamily[L, M]) -> Unit

    Drop every child.

    TypedFamily::get

    fn[L : Hash + Eq + LabelSet, M] TypedFamily::get(self : TypedFamily[L, M], labels : L) -> M raise Refused

    The child for labels, created if this is the first time it is seen.

    TypedFamily::kind

    fn[L, M : Metric] TypedFamily::kind(self : TypedFamily[L, M]) -> Kind

    TypedFamily::new

    fn[L : Hash + Eq, M : Metric] TypedFamily::new(make : () -> M raise Refused) -> TypedFamily[L, M] raise Refused

    A typed family, creating a child with make on first sight.

    TypedFamily::points

    fn[L, M : Metric] TypedFamily::points(self : TypedFamily[L, M]) -> Array[Point]

    TypedFamily::remove

    fn[L : Hash + Eq, M] TypedFamily::remove(self : TypedFamily[L, M], labels : L) -> Unit

    Drop the child for labels if it exists.

    TypedFamily::size

    fn[L, M] TypedFamily::size(self : TypedFamily[L, M]) -> Int

    The number of children seen so far.

    Value

    pub(all) enum Value {
    Number(Double)
    Buckets(buckets~ : Array[(Double, Int64)], sum~ : Double, count~ : Int64)
    Native(buckets~ : Array[(Double, Int64)], sparse~ : Sparse, sum~ : Double, count~ : Int64)
    Quantiles(quantiles~ : Array[(Double, Double)], sum~ : Double, count~ : Int64)
    State(states~ : Array[(String, Bool)])
    }

    The value of one series. A histogram carries its cumulative buckets, sum, and count together so that one series stays one Point; a summary carries its quantiles, sum, and count the same way; a state set carries every state with its flag.

    buckets

    let buckets : Array[Double]

    The default bucket bounds the official Prometheus clients share: 0.005 through 10, fourteen finite bounds plus the implicit +Inf bucket every histogram has.

    exemplar_label_limit

    let exemplar_label_limit : Int

    OpenMetrics caps an exemplar's combined label names and values at 128 characters; a longer set makes the exemplar unrepresentable.

    exponential

    fn exponential(start : Double, factor : Double, count : Int) -> Array[Double] raise Refused

    count bounds starting at start and multiplying by factor.

    exponential_range

    fn exponential_range(low : Double, high : Double, count : Int) -> Array[Double] raise Refused

    count bounds from low to high, each a fixed multiple of the one before, the multiple chosen so the last is high: high / low to the power 1 / (count - 1). Two bounds are the least that names a range, and a range that does not grow is refused rather than returned as a row of equal bounds.

    This is for the case where the interesting span is known and the ratio between steps is not: a request that answers in milliseconds or in seconds wants exponential_range(0.001, 60.0, 12), not a factor picked by hand.

    is_valid_label_name

    fn is_valid_label_name(name : String) -> Bool

    Whether name is a label name under the OpenMetrics character rules: [a-zA-Z_][a-zA-Z0-9_]*.

    is_valid_metric_name

    fn is_valid_metric_name(name : String) -> Bool

    Whether name is a metric name under the OpenMetrics character rules: [a-zA-Z_:][a-zA-Z0-9_:]*.

    is_valid_unit

    fn is_valid_unit(unit : String) -> Bool

    Whether unit may be appended to a metric name. A unit starts with a letter and continues with letters, digits, or underscores.

    linear

    fn linear(start : Double, width : Double, count : Int) -> Array[Double] raise Refused

    count bounds starting at start and growing by width.

    native

    let native : Native

    The settings a native histogram starts from. factor 1.1 is the trade-off client_golang's documentation recommends (eight buckets per power of two); zero_threshold is its default, 2^-128; max_buckets 100 and min_reset fifteen minutes are what its native histogram example sets, since an unlimited bucket count lets wide-spread input grow the histogram without end; max_zero_threshold 0 never widens the zero bucket, its default; ten exemplars kept for five minutes are its defaults.

    point_of

    fn point_of(value : Value) -> Point

    A point with no labels and no metadata, the shape a bare metric collects into before its registry or family adds labels.