Catalog · How the catalog works
prometheus-client
Lock-free Prometheus client for Free Pascal. Striped counters, summary quantiles, and OpenMetrics support for FPC services.
- ★ 1 on GitHub
Anyone may press Interesting, signed in or not. It helps others find this project.
README
prometheus_fpc
Prometheus client for Free Pascal / Lazarus with lock-free, thread-safe metrics. Runtime-only package, FCL only (no LCL), so it works in console apps and services.
Layout
docs/GETTING_STARTED.md- 10-minute tutorial: expose metrics, scrape them with Prometheus, query them (examples/hello_metrics.lpr)docs/adr/- architecture decision recordsprometheus_fpc.lpk- the packagesrc/prom_atomic- CAS-based atomic Int64/Doublesrc/prom_exposition- text format 0.0.4 (escaping, float format, name validation)src/prom_metrics- counter, gauge (withSetToCurrentTime,TrackInProgress), histogram, summary (sum/count only), untyped, info (optional labels), timer for histogram/summarysrc/prom_clock- monotonic clocksrc/prom_registry- thread-safe registry,DefaultRegistrysrc/prom_http-MetricsBody+ content type; bring your own HTTP serversrc/prom_collectors- process and FPC heap metrics, labelled callback metrics, computed on scrapesrc/prom_server- optional/metricsHTTP server (fphttpserver), negotiates text 0.0.4 or OpenMetricssrc/prom_push- optional Pushgateway client (PromPush,PromPushAdd,PromPushDelete,TPromPusherwith basic auth and timeout) for short-lived jobs; checked against Pushgateway 1.11.4tests/- FPCUnit console tests (lazbuild tests/prom_tests.lpi)examples/metrics_demo.lpr- counter, gauge, histogram, quantile summary, StateSet, exemplars, both output formatsexamples/push_demo.lpr- a batch job pushing its metrics to a Pushgatewayexamples/fpweb_metrics.lpr,examples/indy_metrics.lpr,examples/brook_metrics.lpr-/metricsinside an fpWeb (fcl-web) app, on an Indy 10TIdHTTPServerand on a Brook 5TBrookHTTPServer(needs the native libsagui-3 library)contrib/mormot/- optional mORMot 2 integration, a separate packageprometheus_fpc_mormot.lpk: mount/metricson a mORMot HTTP server (PromMountMetrics), publishTSynMonitorstatistics as metrics, heap metrics for mORMot's memory manager. Tested on Windows x64 against mORMot 2.4-stable; see its README
Quick start
uses prom_metrics, prom_registry, prom_exposition, prom_http;
var Req: TPromCounter; Dur: TPromSummary; Phase: TPromStateSet;
begin
Req := DefaultRegistry.Counter('app_requests_total', 'Requests', ['code']);
Dur := DefaultRegistry.Summary('app_duration_seconds', 'Duration', [], [0.5, 0.9, 0.99]);
Phase := DefaultRegistry.StateSet('app_phase', 'Phase', [], ['starting', 'running']);
Phase.SetOnly('running'); // atomic
Req.Labels(['500']).IncWithExemplar(1, ['trace_id', 'abc123']); // OpenMetrics only
Dur.Observe(0.25); // lock-free
Write(MetricsBody); // text 0.0.4
Write(DefaultRegistry.Collect(pfOpenMetrics)); // OpenMetrics 1.0
end.Cache Labels(...) results in hot paths. That pointer stays valid until the family is freed, so removed series are
kept in memory. If label sets come and go (per-connection, per-job), use Acquire / Release instead and
Remove frees the series once nobody holds it:
Ch := TPromCounterChild(Jobs.Acquire([JobId]));
try Ch.Inc; finally Jobs.Release(Ch); end;
Jobs.Remove([JobId]); // freed now, or at the last Release + next Remove/Clear/new series/ReclaimQuantiles are windowed (10 min) estimates with 1% relative error.
Roadmap
Labelled children(done:Labels(...), RW-locked lookup, cached children,Remove/Clear,MaxChildrencap)Shortest round-trip float formatting(done)Process and FPC heap collectors(done; tested on Windows x64 and Linux x86_64)Optional bundled HTTP server unit(done:prom_server, with Accept negotiation)OpenMetrics 1.0 text output(done, complete:_created, exemplars,# UNIT, StateSet, GaugeHistogram, name-clash check)Summary quantiles(done: windowed relative-error sketch, lock-freeObserve)Striped counters(done, opt-in:Counter(name, help, labels, Stripes); about 50x faster with 8 contending threads)32-bit/ARM testing(out of scope: the package targets 64-bit CPUs only; tested on Windows x64 and Linux x86_64)
Provenance
Designed and directed by Sergei Pechenko: the requirements, design decisions (recorded as
ADRs in docs/adr/), reviews and acceptance. Most of the code, tests and docs were
written by Claude (Anthropic) from his prompts and decisions, and checked by the test suite
(Windows x64, Linux x86_64) and a heaptrc leak/use-after-free check. Because the code is largely
AI-generated, no warranty of originality is given beyond the license's disclaimer.
License
BSD 3-Clause; see LICENSE.

