API reference
Prometheus text exposition format for Zig: write metrics to any writer, no HTTP.
One value, Writer, over a std.Io.Writer. Its methods are the primitives
(help, kind, name, value, line) and the compositions built on them
(writeMetric, writeFamily, writeHistogram, and the series form a
multi-series histogram family loops).
struct
Writer
src
pub const Writer = @import("writer.zig").Writer
Fields
out: *Io.Writer
Functions
pub fn help(self: Writer, comptime metric_name: []const u8, text: []const u8) Io.Writer.Error!void
src
# HELP name text, with the text escaped. An empty text writes the line
without a trailing space.
pub fn kind(self: Writer, comptime metric_name: []const u8, type_kind: Kind) Io.Writer.Error!void
src
# TYPE name kind.
name{label="value",...} with no trailing space. A struct gives its
fields in order; a tuple of structs gives their fields in sequence, which
is how a caller adds a label of its own to one it already has.
value and the newline that ends the record. An integer type is written
as decimal; a float follows the expfmt rule in value.zig.
Bytes the caller already formatted. Written as given: no newline, no escaping.
pub fn writeMetric(
self: Writer,
comptime name_text: []const u8,
label_values: anytype,
value_text: anytype,
) Io.Writer.Error!void
src
One sample line: the name, the labels, the value, and the newline.
pub fn writeFamily(self: Writer, comptime m: Metric) Io.Writer.Error!FamilyWriter(m)
src
# HELP, # TYPE, and the handle its samples go through.
pub fn writeHistogram(
self: Writer,
comptime m: Metric,
label_values: anytype,
limits: []const f64,
counts: []const u64,
sum: anytype,
count: u64,
) Io.Writer.Error!void
src
A whole classic histogram for one label set: the header and one series.
A family with more than one series cannot use this twice, because each
call writes # HELP and # TYPE again and the parser rejects the
second. Write writeFamily once and loop
FamilyWriter.writeHistogramSeries instead.
type fn
FamilyWriter
src
pub const FamilyWriter = @import("writer.zig").FamilyWriter
A family's samples, from the value writeFamily handed back. It carries the
family's name, which is why the series form hangs off it: a bare Writer
has nowhere to get one.
Fields
writer: Writer
Functions
pub fn writeHistogramSeries(
self: Self,
label_values: anytype,
limits: []const f64,
counts: []const u64,
sum: anytype,
count: u64,
) Io.Writer.Error!void
src
One histogram series: the bucket lines, _sum, and _count, with no
header. A family with more than one series writes help and kind
once through writeFamily and then calls this per series.
sum is anytype so a caller whose sum is a u64 keeps every
digit; a f64 cannot hold one above 2^53.