iapetos.core

collector-registry

(collector-registry)(collector-registry registry-name)

Create a fresh iapetos collector registry.

counter

(counter metric & [{:keys [description labels lazy?], :or {description "a counter metric."}, :as options}])

Create a new Counter collector:

  • :description: a description for the counter,
  • :labels: a seq of available labels for the counter,
  • :lazy? whether to immediately register the given metric with a registry or not.

dec

(dec collector)(dec collector amount)(dec registry metric)(dec registry metric amount)(dec registry metric labels)(dec registry metric labels amount)

Decrement the given metric by the given amount. This can be either called using a registry and metric name or directly on a collector:

(-> registry (inc :app/active-users-total))
(-> registry :app/active-users-total (inc))

The return value of this operation is either the collector or registry that was passed in.

gauge

(gauge metric & [{:keys [description labels lazy?], :or {description "a gauge metric."}, :as options}])

Create a new Gauge collector:

  • :description: a description for the gauge,
  • :labels: a seq of available labels for the gauge,
  • :lazy? whether to immediately register the given metric with a registry or not.

histogram

(histogram metric & [{:keys [description buckets labels lazy?], :or {description "a histogram metric."}, :as options}])

Create a new Histogram collector:

  • :description: a description for the histogram,
  • :buckets: a seq of double values describing the histogram buckets,
  • :labels: a seq of available labels for the histogram,
  • :lazy? whether to immediately register the given metric with a registry or not.

inc

(inc collector)(inc collector amount)(inc registry metric)(inc registry metric amount)(inc registry metric labels)(inc registry metric labels amount)

Increment the given metric by the given amount. This can be either called using a registry and metric name or directly on a collector:

(-> registry (inc :app/active-users-total))
(-> registry :app/active-users-total (inc))

The return value of this operation is either the collector or registry that was passed in.

observe

(observe collector amount)(observe registry metric amount)(observe registry metric labels amount)

Observe the given amount for the desired metric. This can be either called using a registry and metric name or directly on a collector:

(-> registry (observe :app/active-users-total 10.0))
(-> registry :app/active-users-total (observe 10.0))

The return value of this operation is either the collector or registry that was passed in.

register

(register registry & collectors)

Register the given collectors.

register-as

(register-as registry metric collector)

Register the given collector under the given metric name. This is useful for plain Prometheus collectors, i.e. those that are not provided by iapetos.

set

(set collector amount)(set registry metric amount)(set registry metric labels amount)

Set the given metric to the given value. This can be either called using a registry and metric name or directly on a collector:

(-> registry (set :app/active-users-total 10.0))
(-> registry :app/active-users-total (set 10.0))

The return value of this operation is either the collector or registry that was passed in.

set-to-current-time

(set-to-current-time collector)(set-to-current-time registry metric)(set-to-current-time registry metric labels)

Set the given metric to the current timestamp. This can be either called using a registry and metric name or directly on a collector:

(-> registry (set-to-current-time :app/last-success-unixtime))
(-> registry :app/last-success-unixtime set-to-current-time)

The return value of this operation is either the collector or registry that was passed in.

start-timer

(start-timer collector)(start-timer registry metric)(start-timer registry metric labels)

Start a timer that, when stopped, will store the duration in the given metric. This can be either called using a registry and metric name or a collector:

(-> registry (start-timer :app/duration-seconds))
(-> registry :app/duration-seconds (start-timer))

The return value will be a function that should be called once the operation to time has run.

subsystem

(subsystem registry subsystem-name)

Create a new registry bound to the given subsystem. The resulting value will not have access to any of the original registry’s collectors.

Subsystems can be nested, resulting in joining the subsystem names with underscores.

summary

(summary metric & [{:keys [description quantiles labels lazy?], :or {description "a summary metric."}, :as options}])

Create a new Summary collector:

  • :description: a description for the summary,
  • :quantiles: a map of double [quantile error] entries
  • :labels: a seq of available labels for the summary,
  • :lazy? whether to immediately register the given metric with a registry or not.

value

(value collector)(value registry metric)(value registry metric labels)

Read the current value of a metric. This can be either called using a registry and a metric name or directly on a collector:

(-> registry (value :app/duration-seconds))
(-> registry :app/duration-seconds (value))

The return value depends on the type of collector.

with-activity-counter

macro

(with-activity-counter collector & body)

Wrap the given block to increment the given collector once it is entered and decrement it once execution is done. This needs a gauge collector (since counter ones cannot be decremented).

Example: Counting the number of in-flight requests in an HTTP server.

with-counter

macro

(with-counter collector & body)

Wrap the given block to increment the given counter once it is done.

with-counters

macro

(with-counters {:keys [total success failure], :as counters} & body)

Wrap the given block to increment the given counters:

  • :total: incremented when the block is left,
  • :success: incremented when the block has executed successfully,
  • :failure: incremented when the block has thrown an exception.

with-duration

macro

(with-duration collector & body)

Wrap the given block to write its execution time to the given collector.

Works with gauge, histogram and summary collectors.

with-failure-counter

macro

(with-failure-counter collector & body)

Wrap the given block to increment the given counter if it throws.

with-failure-timestamp

macro

(with-failure-timestamp collector & body)

Wrap the given block to store the current timestamp in the given collector once execution has failed.

Needs a gauge collector.

with-success-counter

macro

(with-success-counter collector & body)

Wrap the given block to increment the given counter once it has run successfully.

with-success-timestamp

macro

(with-success-timestamp collector & body)

Wrap the given block to store the current timestamp in the given collector once execution is done successfully.

Needs a gauge collector.

with-timestamp

macro

(with-timestamp collector & body)

Wrap the given block to store the current timestamp in the given collector once execution is done.

Needs a gauge collector.

with-timestamps

macro

(with-timestamps {:keys [last-run last-success last-failure]} & body)

Wrap the given block to set a number of timestamps depending on whether execution succeeds or fails:

:last-run: the last time the block was run, :last-success: the last time the block was run successfully, :last-failure: the last time execution failed.

All keys are optional but have to point at a gauge collector if given.