Skip to main content

Metrics

Struct Metrics 

Source
pub struct Metrics { /* private fields */ }
Expand description

A registry of sensors and metrics.

A metrics registry is a global repository of metrics and sensors. Sensors apply a sequence of values to associated metrics. This is the consumer- relevant subset of Java’s Metrics; JMX, the sensor-expiry scheduler thread, and quota machinery are omitted (the expiry mechanism is exposed via Metrics::expire_sensors so the consumer/tests can drive it explicitly).

Implementations§

Source§

impl Metrics

Source

pub fn new() -> Self

Create a metrics repository with a default config, no reporters, and the system clock. Mirrors Java’s Metrics() (Metrics.java:85).

Source

pub fn with_default_config(default_config: Arc<MetricConfig>) -> Self

Create a metrics repository with the supplied default config. Mirrors Java’s Metrics(MetricConfig defaultConfig) (:111).

Source

pub fn metric_name_description_tags( &self, name: impl Into<String>, group: impl Into<String>, description: impl Into<String>, tags: BTreeMap<String, String>, ) -> MetricName

Create a MetricName with the given name, group, description and tags, plus default tags specified in the metric configuration. Tags in tags take precedence over default tags with the same key.

Mirrors Java’s metricName(String name, String group, String description, Map<String, String> tags) (:194).

Source

pub fn metric_name_description( &self, name: impl Into<String>, group: impl Into<String>, description: impl Into<String>, ) -> MetricName

Create a MetricName with the given name, group and description, plus the default tags specified in the metric configuration.

Mirrors Java’s metricName(String name, String group, String description) (:208).

Source

pub fn metric_name_tags( &self, name: impl Into<String>, group: impl Into<String>, tags: BTreeMap<String, String>, ) -> MetricName

Create a MetricName with the given name, group and tags, plus the default tags specified in the metric configuration. Tags in tags take precedence over default tags with the same key.

Mirrors Java’s metricName(String name, String group, Map<String, String> tags) (:243).

Source

pub fn metric_name( &self, name: impl Into<String>, group: impl Into<String>, ) -> MetricName

Create a MetricName with name and group (empty description, default tags).

Mirrors Java’s metricName(String name, String group) (:218), whose parameters are the group’s intersection — hence the plain name.

Source

pub fn metric_name_description_key_value( &self, name: impl Into<String>, group: impl Into<String>, description: impl Into<String>, key_value: &[&str], ) -> Result<MetricName, Error>

Create a MetricName from key, value tag pairs, plus default tags. Returns an error if the pairs are not in twos (Java IllegalArgumentException).

Mirrors Java’s metricName(String name, String group, String description, String... keyValue) (:231).

Source

pub fn config(&self) -> &Arc<MetricConfig>

The default config of this registry.

Source

pub fn get_sensor(&self, name: &str) -> Option<Arc<Sensor>>

Get the sensor with the given name if it exists.

Source

pub fn sensor(&self, name: &str) -> Result<Arc<Sensor>, Error>

Get or create a sensor with the given unique name and no parents at INFO recording level. Mirrors Java’s sensor(String name) (:325).

Source

pub fn sensor_recording_level( &self, name: &str, recording_level: RecordingLevel, ) -> Result<Arc<Sensor>, Error>

Get or create a sensor with the given name, recording level, and no parents. Mirrors Java’s sensor(String name, Sensor.RecordingLevel recordingLevel) (:336).

Source

pub fn sensor_parents( &self, name: &str, parents: &[Arc<Sensor>], ) -> Result<Arc<Sensor>, Error>

Get or create a sensor with parents at INFO recording level. Mirrors Java’s sensor(String name, Sensor... parents) (:348).

Source

pub fn sensor_recording_level_parents( &self, name: &str, recording_level: RecordingLevel, parents: &[Arc<Sensor>], ) -> Result<Arc<Sensor>, Error>

Get or create a sensor with the given name, recording level and parents. Mirrors Java’s sensor(String name, Sensor.RecordingLevel recordingLevel, Sensor... parents) (:360).

Source

pub fn sensor_config_parents( &self, name: &str, config: Option<Arc<MetricConfig>>, parents: &[Arc<Sensor>], ) -> Result<Arc<Sensor>, Error>

Get or create a sensor with a config and parents, at INFO recording level. Mirrors Java’s sensor(String name, MetricConfig config, Sensor... parents) (:372).

Source

pub fn sensor_config_recording_level_parents( &self, name: &str, config: Option<Arc<MetricConfig>>, recording_level: RecordingLevel, parents: &[Arc<Sensor>], ) -> Result<Arc<Sensor>, Error>

Get or create a sensor with a config, recording level and parents. Mirrors Java’s sensor(String name, MetricConfig config, Sensor.RecordingLevel recordingLevel, Sensor... parents) (:386).

Source

pub fn sensor_config_inactive_sensor_expiration_time_seconds_parents( &self, name: &str, config: Option<Arc<MetricConfig>>, inactive_sensor_expiration_time_seconds: i64, parents: &[Arc<Sensor>], ) -> Result<Arc<Sensor>, Error>

Get or create a sensor with a config, expiration and parents, at INFO recording level. Mirrors Java’s sensor(String name, MetricConfig config, long inactiveSensorExpirationTimeSeconds, Sensor... parents) (:427).

Source

pub fn sensor_options( &self, options: SensorOptions<'_>, ) -> Result<Arc<Sensor>, Error>

Get or create a sensor with a config, expiration, recording level and parents.

Mirrors Java’s sensor(String name, MetricConfig config, long inactiveSensorExpirationTimeSeconds, Sensor.RecordingLevel recordingLevel, Sensor... parents) (:401). Every parameter, name included, is carried by SensorOptions — see the note above this overload group.

Source

pub fn remove_sensor(&self, name: &str)

Remove a sensor (if it exists), its associated metrics, and its children.

Source

pub fn add_metric_measurable( &self, metric_name: MetricName, measurable: Box<dyn Measurable>, ) -> Result<(), Error>

Add a metric to monitor a measurable. This metric won’t be associated with any sensor. Mirrors Java’s addMetric(MetricName metricName, Measurable measurable) (:470).

Source

pub fn add_gauge( &self, metric_name: MetricName, gauge: Box<dyn Gauge>, ) -> Result<(), Error>

Add a metric backed by a gauge. This metric won’t be associated with any sensor.

Rust-only convenience — Java has no addGauge; callers there pass a Gauge through addMetric(MetricName, MetricValueProvider).

Source

pub fn add_metric_config_provider( &self, metric_name: MetricName, config: Option<Arc<MetricConfig>>, provider: MetricValueProvider, ) -> Result<(), Error>

Add a metric backed by a value provider with an optional config.

Mirrors Java’s addMetric(MetricName metricName, MetricConfig config, MetricValueProvider<?> metricValueProvider) (:498); config: None covers the (MetricName, MetricValueProvider) form (:518), which Java implements by passing null.

Source

pub fn add_metric_if_absent( &self, metric_name: MetricName, config: Option<Arc<MetricConfig>>, provider: MetricValueProvider, ) -> Arc<KafkaMetric>

Register a metric backed by a value provider only if it is not already present. Returns the existing metric if one is already registered under the same name, otherwise the newly registered metric. Translates Java’s Metrics.addMetricIfAbsent(MetricName, MetricConfig, MetricValueProvider) — idempotent registration (the consumer’s preferred-read-replica gauge re-registers across assignment updates without error).

Source

pub fn remove_metric( &self, metric_name: &MetricName, ) -> Option<Arc<KafkaMetric>>

Remove a metric if it exists and return it. metric_removal is invoked on each reporter when a metric is removed.

Source

pub fn add_reporter(&self, reporter: Arc<dyn MetricsReporter>)

Add a metrics reporter, initializing it with all existing metrics.

Source

pub fn metrics(&self) -> HashMap<MetricName, Arc<KafkaMetric>>

Get all the metrics currently maintained, indexed by metric name.

Source

pub fn metric(&self, metric_name: &MetricName) -> Option<Arc<KafkaMetric>>

Get a single metric by name.

Source

pub fn metric_instance_key_value( &self, template: &MetricNameTemplate, key_value: &[&str], ) -> Result<MetricName, Error>

Create a MetricName from a template and tag pairs. Mirrors Java’s metricInstance(MetricNameTemplate template, String... keyValue) (:651).

Source

pub fn metric_instance_tags( &self, template: &MetricNameTemplate, tags: BTreeMap<String, String>, ) -> Result<MetricName, Error>

Create a MetricName from a template and a tags map. Mirrors Java’s metricInstance(MetricNameTemplate template, Map<String, String> tags) (:655).

Source

pub fn expire_sensors(&self)

Iterate over every sensor and remove the ones that have expired.

This is the explicit equivalent of Java’s ExpireSensorTask / metricsScheduler; the consumer (or tests) drives it instead of a background thread.

Source

pub fn close(&self)

Close this metrics repository, closing all reporters.

Trait Implementations§

Source§

impl Default for Metrics

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V