Skip to main content

Sensor

Struct Sensor 

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

A sensor applies a continuous sequence of numerical values to a set of associated metrics. For example a sensor on message size would record a sequence of message sizes using the record api and would maintain a set of metrics about request sizes such as the average or max.

Implementations§

Source§

impl Sensor

Source

pub fn name(&self) -> &str

The name this sensor is registered with.

Source

pub fn should_record(&self) -> bool

Whether the sensor’s record level indicates that the metric will be recorded.

Source

pub fn record(&self)

Record an occurrence; short-hand for record_value(1.0).

Mirrors Java’s record() (Sensor.java:183).

Source

pub fn record_value(&self, value: f64)

Record a value with this sensor at the current time.

Mirrors Java’s record(double value) (Sensor.java:195).

Source

pub fn record_value_time_ms(&self, value: f64, time_ms: i64)

Record a value at a known time.

Mirrors Java’s record(double value, long timeMs) (Sensor.java:209).

Source

pub fn check_quotas(&self) -> Result<(), Error>

Check whether any metric with a configured quota has been violated, at the current time.

Mirrors Java’s checkQuotas() (Sensor.java:247-249). The group’s parameter-name intersection is empty and this no-arg form matches it, so it keeps the plain name and its sibling is suffixed (CLAUDE.md §2).

Source

pub fn check_quotas_time_ms(&self, time_ms: i64) -> Result<(), Error>

Check whether any metric with a configured quota has been violated, as of time_ms.

Mirrors Java’s checkQuotas(long timeMs) (Sensor.java:251-268). Two differences, both forced by what exists on the Rust side:

  • Java guards on config != null; a Rust MetricConfig is always present (each metric holds an Arc<MetricConfig>), so only the quota != null guard survives as Option<Quota>.
  • Java special-cases metric.measurable() instanceof TokenBucket, treating any negative value as a violation regardless of the bound’s direction. TokenBucket is not translated (there is no common::metrics::stats::TokenBucket), so no metric can take that branch and only Quota::acceptable is consulted. The branch must be restored together with TokenBucket.
Source

pub fn add_metric_name( &self, metric_name: MetricName, stat: Box<dyn MeasurableStat>, ) -> Result<bool, Error>

Register a metric with this sensor.

Mirrors Java’s add(MetricName metricName, MeasurableStat stat) (Sensor.java:316). Suffixed per the note above.

Returns Ok(true) if added, Ok(false) if the sensor is expired, Err if the metric name already exists in the registry under a different sensor (Java’s IllegalArgumentException).

Source

pub fn add_metric_name_config( &self, metric_name: MetricName, stat: Box<dyn MeasurableStat>, config: Option<Arc<MetricConfig>>, ) -> Result<bool, Error>

Register a metric with this sensor with an optional per-metric config.

Mirrors Java’s add(MetricName metricName, MeasurableStat stat, MetricConfig config) (Sensor.java:328).

Source

pub fn add(&self, stat: Box<dyn CompoundStat>) -> Result<bool, Error>

Register a compound statistic with this sensor with no config override.

Mirrors Java’s add(CompoundStat stat) (Sensor.java:279), whose parameter list is exactly the add group’s intersection {stat} — so this form keeps the plain name (CLAUDE.md §2).

Source

pub fn add_config( &self, stat: Box<dyn CompoundStat>, config: Option<Arc<MetricConfig>>, ) -> Result<bool, Error>

Register a compound statistic with this sensor which yields multiple measurable quantities (like a histogram). Mirrors Java’s add(CompoundStat stat, MetricConfig config) (Sensor.java:290).

The compound stat is recorded once per record; each NamedMeasurable child gets its own KafkaMetric reading the (constant) statConfig. The child measurables share state with the compound stat, so a record is reflected in every child’s measured value.

Source

pub fn has_metrics(&self) -> bool

Return if metrics were registered with this sensor.

Source

pub fn has_expired(&self) -> bool

Return true if the sensor is eligible for removal due to inactivity.

Auto Trait Implementations§

§

impl !Freeze for Sensor

§

impl !RefUnwindSafe for Sensor

§

impl Send for Sensor

§

impl Sync for Sensor

§

impl Unpin for Sensor

§

impl UnsafeUnpin for Sensor

§

impl !UnwindSafe for Sensor

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