nmbrs-metrics
Metrics collection and reporting for nmbrs. It provides the component tree that holds instruments (counters, gauges, HDR histograms, timers), a cadence reporter that coalesces snapshots into time windows, reporters for several output formats, and a read-side query API. It is written for the nmbrs runtime and its UIs; it can be used on its own, but its design follows nmbrs's session, phase and activity model.
Where it sits in nmbrs
nmbrs-metrics is the foundational metrics and data-access library of the
workspace. It is used by
nmbrs-runtime,
nmbrs-rate,
nmbrs-tui,
nmbrs-web and the
nmbrs CLI. The MetricsQL engine,
nmbrs-metricsql, evaluates
queries over the access API defined here (queryapi).
End users normally install the nmbrs
CLI rather than depending on this crate directly.
What it provides
- Component tree (
component): hierarchical components, each with dimensional labels (session=…,phase=…,activity=…), props, an instrument set, and a control registry. A component's effective labels are its own labels plus those of its parent chain. Components are looked up withselector::Selector(component::find,find_one,count).cellsresolves one child component per dimensional coordinate. - Instruments (
instruments):Counter,ValueGauge,HistogramandTimer. Histograms and timers are HDR-backed. They are recorded on the hot path and read as delta windows. - Snapshots (
snapshot::MetricSet): OpenMetrics-shaped captures of the tree at one point in time. - Cadences and the cadence reporter (
cadence,cadence_reporter):CadencesandCadenceTreeplan the declared windows (for example 1s, 10s, 1m) plus any intermediate layers;CadenceReporterfolds snapshots into those windows, keeps per-cadence history, and delivers sealed windows to async subscribers.schedulerdrives capture on a base interval. - MetricsQuery (
metrics_query::MetricsQuery): the single read API over the cadence store and live tree. Modes includenow,cadence_window,session_lifetime,increase_overanddistribution_over, each filtered by aSelection. - Query API (
queryapi): the data-access service boundary. It defines theVector/Series/Sampleresult shapes, labelMatchers, and theMetricAccesstrait (select_range,select_instant). Services are located at runtime: a live in-process service viainstall_live_access/live_access, and file backends registered asAccessProviders and found by scheme withprovider.catalogexposes metric-family enumeration (MetricCatalog);hybrid::HybridStorecombines tiers (for example in-memory and sqlite) into oneMetricAccess. The query API has no query language; aggregation lives innmbrs-metricsql. - Reporters (
reporters): console, CSV, a JSONL metrics log, per-instance JSONL files, an in-memory summary report, OpenMetrics / Prometheus text rendering (render_prometheus_text) and parsing (parse_prometheus_text), plus feature-gated SQLite and VictoriaMetrics push reporters. - Controls (
controls):Control<T>, a named, typed value attached to a component.Control::setis async and completes only after every registeredControlApplierhas acknowledged the change. A control can optionally be published as a gauge (ControlBuilder::reify_as_gauge). - Summaries (
summaries): retained views fed from outside the hot path, such asHdrSummary,LiveWindowHistogram,BinomialSummary(sparklines),Ewma,F64StatsandPeakTracker. - Polydat metric nodes (
polydat_nodes): registers themetricandmetric_windownodes with polydat so workloads can read live metrics (cycles,errors,rate,p50,p99,mean). The runner installs the query withpolydat_nodes::set_global_query. - Supporting modules:
validation(OpenMetrics name, label, unit and bucket checks),thread_pools(named OS thread pools with scheduling policy; realtime priority and affinity apply on Linux), anddiag(pluggable warning/info sink).
Example
Build a component tree, register a counter, and render the current values as Prometheus text:
use HashMap;
use Arc;
use ;
use Counter;
use Labels;
use render_prometheus_text;
use Selector;
let root = root;
let ops = new;
root.write
.unwrap
.register_instrument
.unwrap;
ops.inc_by;
// Effective labels include the chain back to the root.
assert_eq!;
// An empty selector matches the root on a fresh tree.
assert_eq!;
let text = render_prometheus_text;
println!;
Cargo features
All features are off by default.
| Feature | Enables |
|---|---|
sqlite |
reporters::sqlite::SqliteReporter (writes the normalized session metrics database) and queryapi::sqlite (the sqlite read backend, registered as the sqlite access provider). Pulls in rusqlite with the bundled SQLite. |
victoriametrics |
reporters::victoriametrics::VictoriaMetricsReporter, which pushes Prometheus text to a VictoriaMetrics /api/v1/import/prometheus endpoint. Pulls in reqwest (blocking). |
all-reporters |
sqlite and victoriametrics. |
Links
- Repository: https://github.com/nosqlbench/nmbrs
- Crate source: https://github.com/nosqlbench/nmbrs/tree/main/nmbrs-metrics
- API docs: https://docs.rs/nmbrs-metrics
- Metrics contract (SRD 39): https://github.com/nosqlbench/nmbrs/blob/main/docs/SRD/39_metrics_contract.md
License
Apache-2.0