Liking cljdoc? Tell your friends :D

wagoe.observability.metrics.shell.adapters.prometheus

Pure-Clojure Prometheus metrics adapter.

An in-memory metric registry that renders the Prometheus text exposition format (https://prometheus.io/docs/instrumenting/exposition_formats/). It implements all four metrics protocols (IMetricsRegistry, IMetricsEmitter, IMetricsExporter, IMetricsConfig) in a single component backed by one Clojure atom, so it is safe for concurrent use via swap!.

No external Prometheus client dependency is used — the exposition text is produced by this namespace directly.

Sanitization + collisions (BOU-207): metric/label names are sanitized to valid Prometheus identifiers. Post-sanitization COLLISIONS are handled so the output stays valid:

  • Metric names: if a later registration sanitizes to the same name as an already-registered different key (e.g. :http.requests then :http-requests, both -> http_requests), the later one is logged and IGNORED — the first registration wins (no duplicate # TYPE line).
  • Label keys within a series: keys that sanitize to the same label name are de-duplicated deterministically at render (the lexicographically-first [name value] pair wins), so no duplicate label appears in a series.

Series identity

Each metric value is keyed by (metric-name, label-set), where the label-set is the merge of the registry default tags, the metric's registration tags, and any per-call tags. Distinct label-sets are therefore distinct series.

Metric storage

  • counter : {label-set -> numeric total}
  • gauge : {label-set -> numeric value (last write wins)}
  • histogram: {label-set -> {:counts {bucket -> n} :inf n :sum s :count c}} (per-bucket non-cumulative counts; cumulative counts are computed at export time)
  • summary : {label-set -> {:sum s :count c}} — quantiles are NOT tracked; only the _sum/_count pair is emitted (see note below).

Simplifications

  • Summary quantiles are not computed. A summary emits only _sum and _count, which is a valid (if minimal) Prometheus summary exposition.
  • Metric names are emitted as-is (assumed already valid Prometheus names).
Pure-Clojure Prometheus metrics adapter.

An in-memory metric registry that renders the Prometheus text exposition
format (https://prometheus.io/docs/instrumenting/exposition_formats/).
It implements all four metrics protocols
(IMetricsRegistry, IMetricsEmitter, IMetricsExporter, IMetricsConfig)
in a single component backed by one Clojure atom, so it is safe for
concurrent use via `swap!`.

No external Prometheus client dependency is used — the exposition text is
produced by this namespace directly.

Sanitization + collisions (BOU-207): metric/label names are sanitized to valid
Prometheus identifiers. Post-sanitization COLLISIONS are handled so the output
stays valid:
- Metric names: if a later registration sanitizes to the same name as an
  already-registered different key (e.g. :http.requests then :http-requests,
  both -> http_requests), the later one is logged and IGNORED — the first
  registration wins (no duplicate `# TYPE` line).
- Label keys within a series: keys that sanitize to the same label name are
  de-duplicated deterministically at render (the lexicographically-first
  [name value] pair wins), so no duplicate label appears in a series.

Series identity
---------------
Each metric value is keyed by (metric-name, label-set), where the label-set
is the merge of the registry default tags, the metric's registration tags,
and any per-call tags. Distinct label-sets are therefore distinct series.

Metric storage
--------------
- counter : {label-set -> numeric total}
- gauge   : {label-set -> numeric value (last write wins)}
- histogram: {label-set -> {:counts {bucket -> n} :inf n :sum s :count c}}
            (per-bucket non-cumulative counts; cumulative counts are computed
             at export time)
- summary : {label-set -> {:sum s :count c}}  — quantiles are NOT tracked;
            only the `_sum`/`_count` pair is emitted (see note below).

Simplifications
---------------
- Summary quantiles are not computed. A summary emits only `_sum` and
  `_count`, which is a valid (if minimal) Prometheus summary exposition.
- Metric names are emitted as-is (assumed already valid Prometheus names).
raw docstring

create-metrics-componentclj

(create-metrics-component)
(create-metrics-component config)

Create a Prometheus metrics component implementing all four metrics protocols, backed by a single atom.

Args: config - Prometheus provider config map (see wagoe.observability.metrics.schema/PrometheusMetricsConfig). Recognised keys: :histogram-buckets, :include-help-text, :registry-name, and :tagging {:default-tags {...}}.

Returns: Component implementing IMetricsRegistry, IMetricsEmitter, IMetricsExporter, and IMetricsConfig.

Create a Prometheus metrics component implementing all four metrics
protocols, backed by a single atom.

Args:
  config - Prometheus provider config map (see
           wagoe.observability.metrics.schema/PrometheusMetricsConfig).
           Recognised keys: :histogram-buckets, :include-help-text,
           :registry-name, and :tagging {:default-tags {...}}.

Returns:
  Component implementing IMetricsRegistry, IMetricsEmitter,
  IMetricsExporter, and IMetricsConfig.
sourceraw docstring

create-metrics-componentsclj

(create-metrics-components)
(create-metrics-components config)

Create a complete set of Prometheus metrics components that all share a single underlying component/atom, so registration, emission, export, and config operate on the same state.

Returns: {:registry IMetricsRegistry :emitter IMetricsEmitter :exporter IMetricsExporter :config IMetricsConfig}

Create a complete set of Prometheus metrics components that all share a
single underlying component/atom, so registration, emission, export, and
config operate on the same state.

Returns:
  {:registry  IMetricsRegistry
   :emitter   IMetricsEmitter
   :exporter  IMetricsExporter
   :config    IMetricsConfig}
sourceraw docstring

create-metrics-configclj

(create-metrics-config)
(create-metrics-config config)

Create a Prometheus metrics config (a full component; all protocols share one atom). See create-metrics-component.

Create a Prometheus metrics config (a full component; all protocols share
one atom). See `create-metrics-component`.
sourceraw docstring

create-metrics-emitterclj

(create-metrics-emitter)
(create-metrics-emitter config)

Create a Prometheus metrics emitter (a full component; all protocols share one atom). See create-metrics-component.

Create a Prometheus metrics emitter (a full component; all protocols share
one atom). See `create-metrics-component`.
sourceraw docstring

create-metrics-exporterclj

(create-metrics-exporter)
(create-metrics-exporter config)

Create a Prometheus metrics exporter (a full component; all protocols share one atom). See create-metrics-component.

Create a Prometheus metrics exporter (a full component; all protocols share
one atom). See `create-metrics-component`.
sourceraw docstring

create-metrics-registryclj

(create-metrics-registry)
(create-metrics-registry config)

Create a Prometheus metrics registry (a full component; all protocols share one atom). See create-metrics-component.

Create a Prometheus metrics registry (a full component; all protocols share
one atom). See `create-metrics-component`.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close