Crate dipstick

source ·
Expand description

A quick, modular metrics toolkit for Rust applications.

Macros

Create Labels from a list of key-value pairs Adapted from the hashmap!() macro in the maplit crate.
Metrics can be used from anywhere (public), does not need to declare metrics in this block.
A convenience macro to wrap a block or an expression with a start / stop timer. Elapsed time is sent to the supplied statsd client after the computation has been performed. Expression result (if any) is transparently returned.

Structs

Handle metric labels for the whole application (globals). App scope labels have the lowest lookup priority and serve as a fallback to other scopes.
Central aggregation structure. Maintains a list of metrics for enumeration when used as source.
Attributes common to metric components. Not all attributes used by all components.
A guard canceling the inner handle when dropped.
A handle to cancel a scheduled task if required.
A counter of absolute observed values (non-negative amounts). Used to count things that cannot be undone:
A gauge that sends values to the metrics backend
Graphite Input holds a socket to a graphite server. The socket is shared between scopes opened from the Input.
Key of a graphite metric.
Graphite Input
A metric is actually a function that knows to write a metric value to a metric output.
Wrap new scopes with an asynchronous metric write & flush dispatcher.
A metric scope wrapper that sends writes & flushes over a Rust sync channel. Commands are executed by a background thread.
Base structure to carry metric labels from the application to the metric backend(s). Can carry both one-off labels and exported context labels (if async metrics are enabled). Used in applications through the labels!() macro.
A counter of fluctuating resources accepting positive and negative values. Can be used as a stateful Gauge or as a Counter of possibly decreasing amounts.
An sequence of print commands, embodying an output strategy for a single metric.
Buffered metrics log output.
A scope for metrics log output.
A monotonic counter metric. Since value is only ever increased by one, no value parameter is provided, preventing programming errors.
A metrics identifier
The name of a metric, including the concatenated possible namespaces in which it was defined.
Opens multiple scopes at a time from just as many outputs.
Dispatch metric values to a list of scopes.
A double-ended vec of strings constituting a metric name or a future part thereof.
When to observe a recurring task.
A handle to cancel a flush observer.
Prometheus Input holds a socket to a Prometheus server. The socket is shared between scopes opened from the Input.
Prometheus Input
A dynamic proxy for app and lib metrics. Decouples metrics definition from backend configuration. Allows defining metrics before a concrete type is configured. Allows replacing metrics backend on the fly at runtime.
A simple metric output format of “MetricName {Value}”
A BTreeMap wrapper to receive metrics or stats values. Every received value for a metric replaces the previous one (if any).
Statsd Input holds a datagram (UDP) socket to a statsd server. The socket is shared between scopes opened from the Input.
Key of a statsd metric.
Statsd Input
Buffered metrics text Input.
A scope for text metrics.
Handle metric labels for the current thread. App scope labels have the lowest lookup priority and serve as a fallback to other scopes.
A handle to the start time of a counter. Wrapped so it may be changed safely later.
A timer that sends values to the metrics backend Timers can record time intervals in multiple ways :
Discard metrics Input.

Enums

A metrics buffering strategy. All strategies other than Unbuffered are applied as a best-effort, meaning that the buffer may be flushed at any moment before reaching the limit, for any or no reason in particular.
Used to differentiate between metric kinds in the backend.
Print commands are steps in the execution of output templates.
Print commands are steps in the execution of output templates.
The actual distribution (random, fixed-cycled, etc) depends on selected sampling method.
Possibly aggregated scores.

Traits

Determine scope buffering strategy, if supported by output. Changing this only affects scopes opened afterwards. Buffering is done on best effort, meaning flush will occur if buffer capacity is exceeded.
Wrap an input with a metric definition cache. This can provide performance benefits for metrics that are dynamically defined at runtime on each access. Caching is useless if all metrics are statically declared or instantiated programmatically in advance and referenced by a long living variable.
A deferred, repeatable, background action that can be cancelled.
Both InputScope and OutputScope share the ability to flush the recorded data.
Format output config support.
A function trait that opens a new metric capture scope.
A function trait that opens a new metric capture scope.
InputScope Define metrics, write values and flush them.
Support trait for enabling a few common operation on lazy static values.
Forges metric-specific printers
Schedule a recurring task
Register and notify scope-flush listeners
Name operations support.
Wrap this output behind an asynchronous metrics dispatch queue. This is not strictly required for multi threading since the provided scopes are already Send + Sync but might be desired to lower the latency
Apply statistical sampling to collected metrics data.
Enable background periodical publication of metrics
This trait should not be exposed outside the crate.
Used for immutable dereferencing operations, like *v.

Functions

Takes a shared reference to a lazy static and initializes it if it has not been already.
A predefined export strategy reporting all aggregated stats for all metric types. Resulting stats are named by appending a short suffix to each metric’s name.
A predefined export strategy reporting the average value for every non-marker metric. Marker metrics export their hit count instead. Since there is only one stat per metric, there is no risk of collision and so exported stats copy their metric’s name.
A predefined single-stat-per-metric export strategy:

Type Definitions

Base type for recorded metric values.