std/metrics
On this page
Index
- type
Series - type
QSample - type
QStream - type
QState - type
Sample - type
Kind - type
Family - type
Registry- method
Registry.counter - method
Registry.gauge - method
Registry.histogram - method
Registry.summary - method
Registry.gauge_func - method
Registry.counter_func - method
Registry.collector - method
Registry.text - method
Registry.handler - method
Registry.handler_at - method
Registry.middleware
- method
- type
Counter- method
Counter.inc - method
Counter.add - method
Counter.child - method
Counter.remove - method
Counter.reset
- method
- type
Gauge- method
Gauge.set - method
Gauge.add - method
Gauge.child - method
Gauge.remove - method
Gauge.reset
- method
- type
Histogram- method
Histogram.observe - method
Histogram.child - method
Histogram.remove - method
Histogram.reset
- method
- type
Summary- method
Summary.child - method
Summary.observe - method
Summary.remove - method
Summary.reset
- method
- type
CounterChild- method
CounterChild.inc - method
CounterChild.add
- method
- type
GaugeChild- method
GaugeChild.set - method
GaugeChild.add
- method
- type
HistogramChild- method
HistogramChild.observe
- method
- type
SummaryChild- method
SummaryChild.observe
- method
- fn
registry - fn
latency_buckets
Types
Series
struct Series {
values: List[Str]
cells: List[Atomic[Int]]
q: List[Mutex[QState]]
}One series of an instrument: its label values and its cells (atomic integers in one list, so reading a series out of the registry shares one object, not one per field): cell 0 a counter’s or gauge’s float (its bits), 1 the observation count, 2 the sum (bits), 3 and on a histogram’s bucket counts, one bucket each. Internal: use the instruments.
QSample
struct QSample {
v: Float
w: Float
d: Float
}A CKMS targeted quantile stream (beorn7/perks, which Prometheus' client uses): samples (value, width, delta), the unsorted buffer, and the count. Internal.
QStream
struct QStream {
l: List[QSample]
b: List[Float]
n: Float
}QState
struct QState {
streams: List[QStream]
head: Int
exp_ms: Int
hot: List[Atomic[Int]]
hot_n: Atomic[Int]
}A summary series’ age buckets (client_golang’s streams): every observation goes into each; the head one answers; at a scrape with a time, the head is reset and the next becomes head once its time ran out. Internal.
Sample
struct Sample {
values: List[Str]
value: Float
}A value read at scrape time from a collector: its label values and value (decision 0411).
Kind
enum Kind { Counter, Gauge }The kind of a collector’s series.
Family
struct Family {
name: Str
help: Str
kind: Int
labels: List[Str]
bounds: List[Float]
series: Mutex[Map[Str, Series]]
dropped: Atomic[Int]
reads: List[fn() -> List[Sample]]
objectives: List[(Float, Float)]
max_age_ms: Int
age_buckets: Int
}One instrument: kind 0 counter, 1 gauge, 2 histogram, 3 summary; reads: a scrape time reader (gauge_func, counter_func, collector); objectives, max_age_ms and age_buckets: a summary’s. Internal.
Registry
struct Registry {
families: Mutex[List[Family]]
dropped: Atomic[Int]
}A set of instruments. Cloning shares it. Its fields are internal.
Registry.counter
fn (r: Registry) counter(name: Str, help: Str, labels: List[Str] = []) -> CounterMakes a counter named name (a Prometheus name: letters, digits, _
and :, not starting with a digit) with the label names labels. A
second instrument with the same name, an invalid name or label, or
buckets that do not increase is a fault: they are programmer errors,
found at start.
Registry.gauge
fn (r: Registry) gauge(name: Str, help: Str, labels: List[Str] = []) -> GaugeRegistry.histogram
fn (r: Registry) histogram(name: Str, help: Str, labels: List[Str] = [], buckets: List[Float] = latency_buckets()) -> HistogramRegistry.summary
fn (r: Registry) summary(name: Str, help: Str, labels: List[Str] = [], objectives: List[(Float, Float)] = [], max_age: Duration = 10m, age_buckets: Int = 5) -> SummaryA summary (Prometheus client_golang’s Summary, decision 0411): each
objective (quantile, allowed error) is reported as a quantile series
(CKMS targeted quantiles, beorn7/perks), with _sum and _count. The
quantiles cover the last max_age in age_buckets steps, aged when a
scrape passes the time (text(now), handler_at(clock)): a summary
never scraped with a time keeps every observation.
Registry.gauge_func
fn (r: Registry) gauge_func(name: Str, help: Str, f: fn() -> Float)A gauge (counter) whose value f returns at each scrape (GaugeFunc, CounterFunc).
Registry.counter_func
fn (r: Registry) counter_func(name: Str, help: Str, f: fn() -> Float)Registry.collector
fn (r: Registry) collector(name: Str, help: Str, kind: Kind, labels: List[Str], f: fn() -> List[Sample])An instrument whose series f returns at each scrape (a Collector): one Sample per series, its values one per label.
Registry.text
fn (r: Registry) text(now: Time? = None) -> StrThe text exposition: # HELP and # TYPE lines and the series,
instruments in the order they were made, series sorted by label
values, histograms as cumulative _bucket{le=...}, _sum and
_count, and xo_metrics_dropped_total.
Registry.handler
fn (r: Registry) handler() -> fn(http.Request) -> http.ResponseA handler answering text() as text/plain; version=0.0.4:
router.handle("GET /metrics", reg.handler()).
Registry.handler_at
fn (r: Registry) handler_at(clock: Clock) -> fn(http.Request) -> http.Response uses clockhandler, each scrape passing the clock’s time to text (summaries age).
Registry.middleware
fn (r: Registry) middleware(clock: Clock, label: fn(http.Request) -> Str) -> fn(http.Request, http.Next) -> http.Response uses clockA middleware (router.wrap(reg.middleware(clock, label))) that counts
every request in http_requests_total{method,route,status}, times it
in http_request_seconds{route} (the default buckets) and tracks
http_in_flight. label names the route of a request for the route
label: pass a function that returns a bounded set (the matched pattern,
or the path with ids cut), never the raw path of an API with ids.
Counter
struct Counter {
f: Family
}A value that only goes up.
Counter.inc
fn (c: Counter) inc(values: List[Str] = [])Adds 1 to (or n >= 0 to) the series of the label values (one per
label name, in order; a wrong count is a fault). Safe from any task.
A registry holds at most max_series (10,000) series per instrument:
a new series past it is dropped and counted in
xo_metrics_dropped_total.
Counter.add
fn (c: Counter) add(n: Float, values: List[Str] = [])Counter.child
fn (c: Counter) child(values: List[Str] = []) -> CounterChildThe child of the series of the label values (one per label name; a
wrong count is a fault): the series is made if it is new. Past
max_series the child counts into a series nothing exposes, and the drop
is counted in xo_metrics_dropped_total as inc counts it.
Counter.remove
fn (c: Counter) remove(values: List[Str]) -> BoolRemoves the series of the label values (DeleteLabelValues): whether there was one.
Counter.reset
fn (c: Counter) reset()Removes every series (Reset).
Gauge
struct Gauge {
f: Family
}A value that goes up and down.
Gauge.set
fn (g: Gauge) set(v: Float, values: List[Str] = [])Gauge.add
fn (g: Gauge) add(v: Float, values: List[Str] = [])Gauge.child
fn (g: Gauge) child(values: List[Str] = []) -> GaugeChildGauge.remove
fn (g: Gauge) remove(values: List[Str]) -> BoolGauge.reset
fn (g: Gauge) reset()Histogram
struct Histogram {
f: Family
}Observations counted in buckets, with their count and sum.
Histogram.observe
fn (h: Histogram) observe(v: Float, values: List[Str] = [])Histogram.child
fn (h: Histogram) child(values: List[Str] = []) -> HistogramChildHistogram.remove
fn (h: Histogram) remove(values: List[Str]) -> BoolHistogram.reset
fn (h: Histogram) reset()Summary
struct Summary {
f: Family
}Observations summarized as quantiles (within each objective’s error), with their count and sum.
Summary.child
fn (s: Summary) child(values: List[Str] = []) -> SummaryChildSummary.observe
fn (s: Summary) observe(v: Float, values: List[Str] = [])Summary.remove
fn (s: Summary) remove(values: List[Str]) -> BoolSummary.reset
fn (s: Summary) reset()CounterChild
struct CounterChild {
s: Series
}A held series (decision 0501, client_golang’s WithLabelValues): made
once with child(values) and used in a hot loop with no label list,
key or lookup. A child shares the series’ cells; cloning one shares them
again; it is safe from any task. remove and reset detach the series
from the exposition: a child made before keeps counting into the
detached series (take a new one after a remove), as in client_golang.
CounterChild.inc
fn (c: CounterChild) inc()Adds 1 to (or n >= 0 to) the child’s series.
CounterChild.add
fn (c: CounterChild) add(n: Float)GaugeChild
struct GaugeChild {
s: Series
}GaugeChild.set
fn (g: GaugeChild) set(v: Float)GaugeChild.add
fn (g: GaugeChild) add(v: Float)HistogramChild
struct HistogramChild {
s: Series
bounds: List[Float]
}HistogramChild.observe
fn (h: HistogramChild) observe(v: Float)SummaryChild
struct SummaryChild {
s: Series
objectives: List[(Float, Float)]
}SummaryChild.observe
fn (s: SummaryChild) observe(v: Float)Functions
registry
fn registry() -> RegistryA new empty registry. Xo has no program wide state: main makes one and passes it to what registers or reads instruments.
latency_buckets
fn latency_buckets() -> List[Float]The buckets of request latencies in seconds: 0.005 to 10.
↑ index