Sign in

    moonbitstack/moonzero/metric does not have a README file

    CounterVec

    pub struct CounterVec {
    counts : Map[String, Int64]
    }

    A monotonic counter (← go-zero's metric.CounterVec) partitioned by a label string. Each inc/add accrues against one label (e.g. "GET /ping 200"), so a single vector holds the per-method/route/status request tallies Prometheus scrapes. Counters only ever go up.

    CounterVec::add

    fn CounterVec::add(self : CounterVec, label : String, delta : Int64) -> Unit

    Add delta to label's count (creating the series on first sight).

    CounterVec::inc

    fn CounterVec::inc(self : CounterVec, label : String) -> Unit

    Increment label's count by one.

    CounterVec::labels

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

    The set of labels that have been observed.

    CounterVec::new

    fn CounterVec::new() -> CounterVec

    A fresh counter vector with no labels seen yet.

    CounterVec::to_exposition

    fn CounterVec::to_exposition(self : CounterVec, name~ : String, help~ : String, label? : String) -> String

    Render this counter vector as Prometheus text exposition: a # HELP line, a # TYPE <name> counter line, then one <name>{<label>="<value>"} <count> series per observed label (sorted for a stable scrape). label names the single dimension the vector partitions on.

    CounterVec::total

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

    The sum of every label's count — the total number of observations.

    CounterVec::value

    fn CounterVec::value(self : CounterVec, label : String) -> Int64

    The current count for label, 0 if never touched.

    Histogram

    pub struct Histogram {
    bounds : Array[Double]
    bucket : Array[Int64]
    sum : Double
    count : Int64
    }

    A cumulative histogram (← go-zero's metric.HistogramVec, Prometheus semantics): a sorted list of le (less-than-or-equal) upper bounds and, for each, the count of observations that fell at or below it, plus the running sum and total count. An observation above every bound still lands in the implicit +Inf bucket that count represents.

    Histogram::bounds

    fn Histogram::bounds(self : Histogram) -> Array[Double]

    The upper bounds this histogram partitions on.

    Histogram::bucket_count

    fn Histogram::bucket_count(self : Histogram, i : Int) -> Int64

    The cumulative count in the bucket bounded by bounds[i] — how many observations were <= that bound.

    Histogram::mean

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

    The mean of the observations, or 0 when none have been recorded.

    Histogram::new

    fn Histogram::new(bounds? : Array[Double]) -> Histogram

    A histogram over bounds (defaulting to default_latency_buckets). The bounds are taken as given; supply them in ascending order, as Prometheus requires.

    Histogram::observe

    fn Histogram::observe(self : Histogram, value : Double) -> Unit

    Record one observation: it lands in every bucket whose le bound it does not exceed (cumulative), and updates the sum and count.

    Histogram::sum_value

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

    The sum of all observed values (Prometheus _sum).

    Histogram::to_exposition

    fn Histogram::to_exposition(self : Histogram, name~ : String, help~ : String) -> String

    Render this histogram as Prometheus text exposition: a # HELP line, a # TYPE <name> histogram line, the cumulative <name>_bucket{le="<bound>"} series capped by the le="+Inf" bucket (every observation, including those above the last bound), then <name>_sum and <name>_count.

    Histogram::total

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

    The total number of observations (the +Inf bucket count).

    ServerMetrics

    pub struct ServerMetrics {
    requests : CounterVec
    latency : Histogram
    }

    The request metrics an HTTP service exposes (← go-zero's server metrics): a request counter partitioned by method/route/status and a latency histogram. Held by the caller so it can be read out for a /metrics scrape after serving.

    ServerMetrics::latency

    fn ServerMetrics::latency(self : ServerMetrics) -> Histogram

    The request-latency histogram, in milliseconds.

    ServerMetrics::new

    Fresh server metrics: an empty counter and a default-bucket latency histogram.

    ServerMetrics::requests

    fn ServerMetrics::requests(self : ServerMetrics) -> CounterVec

    The request counter, labelled "<METHOD> <path> <status>".

    ServerMetrics::to_exposition

    fn ServerMetrics::to_exposition(self : ServerMetrics) -> String

    Render the whole server metric set as one exposition document a Prometheus server can scrape: the latency histogram followed by the request counter, under go-zero's canonical metric names. go-zero splits the counter into path/method/code labels; moonzero keeps the request signature as one request label.

    default_latency_buckets

    let default_latency_buckets : Array[Double]

    The default latency buckets go-zero ships (milliseconds): a request spends most of its time under a second, so the bounds cluster there.

    exposition_content_type

    let exposition_content_type : String

    The content type a /metrics scrape carries so a Prometheus server parses the body as the text exposition format (version=0.0.4).

    Source Files