ostium.client

index ยท ostium

Overview

Buffering ostium client. Metric calls only touch Lua tables keyed by canonical series id; a single flusher coroutine owns the socket, sending queued block commands every tick and the merged metric buffer every flush interval. Single ownership satisfies LEV's one-waiter-per-fd constraint and serializes all writes.

Zero-cost when unconfigured: with no socket in the config every method returns immediately. While the daemon is unreachable the client keeps merging locally (bounded by max_series) and reconnects lazily with a cooldown, costing one warn log per outage.

Delivery caveats: a flush that fails after partial delivery retains the whole buffer and can double-count on retry; a final buffer with the daemon down at stop() is lost. Both are acceptable for monitoring data.

Functions

NameSignature
mx:countermx:counter(name, labels, delta) -> ok, err
mx:gaugemx:gauge(name, labels, value) -> ok, err
mx:timingmx:timing(name, labels, seconds) -> ok, err
mx:blockmx:block(ip, opts) -> ok, err
mx:startmx:start() -> ok
mx:stopmx:stop() -> ok
mx:watch_certsmx:watch_certs(ssl_cfg) -> ok
newnew(cfg, logger) -> client, err

mx:counter(name, labels, delta) -> ok, err

Add a counter delta to the current window

mx:gauge(name, labels, value) -> ok, err

Set a gauge to an absolute value

mx:timing(name, labels, seconds) -> ok, err

Record one timing observation in seconds

mx:block(ip, opts) -> ok, err

Queue a block command for an IP

opts.ttl is the per-entry ipset timeout in seconds (0 or absent uses the set default); opts.reason is free text for the block history. The command is sent on the next flusher tick; the queue is bounded (max_commands) with drop-oldest overflow.

mx:start() -> ok

Spawn the flusher coroutine

Call from inside the LEV loop, typically from the on_start hook of serve_all. A no-op when unconfigured or already running.

mx:stop() -> ok

Stop the flusher after a final flush

Wakes the flusher, waits for it to drain the command queue, flush the metric buffer and close the socket. Safe to call twice.

mx:watch_certs(ssl_cfg) -> ok

Watch TLS certificates and publish their expiry as gauges

Takes the http server ssl config section (default identity plus optional hosts map). Reads each certificate, publishes gauge tls_cert_not_after{host} (the default identity under host "default") and re-checks daily, since certs rotate under ACME. Call from inside the LEV loop after start().

new(cfg, logger) -> client, err

Create a buffering ostium client

cfg.socket is the ostium unix socket path; nil disables the client entirely (every method becomes a cheap no-op). cfg.app is the source identity on every wire line. Optional keys with defaults: flush_interval 10, tick 1, reconnect_cooldown 5, max_series 4096, max_commands 1024. Sub-second tick and cooldown values are allowed, which tests rely on.