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
impl Sensor
Sourcepub fn should_record(&self) -> bool
pub fn should_record(&self) -> bool
Whether the sensor’s record level indicates that the metric will be recorded.
Sourcepub fn record(&self)
pub fn record(&self)
Record an occurrence; short-hand for record_value(1.0).
Mirrors Java’s record() (Sensor.java:183).
Sourcepub fn record_value(&self, value: f64)
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).
Sourcepub fn record_value_time_ms(&self, value: f64, time_ms: i64)
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).
Sourcepub fn check_quotas(&self) -> Result<(), Error>
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).
Sourcepub fn check_quotas_time_ms(&self, time_ms: i64) -> Result<(), Error>
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 RustMetricConfigis always present (each metric holds anArc<MetricConfig>), so only thequota != nullguard survives asOption<Quota>. - Java special-cases
metric.measurable() instanceof TokenBucket, treating any negative value as a violation regardless of the bound’s direction.TokenBucketis not translated (there is nocommon::metrics::stats::TokenBucket), so no metric can take that branch and onlyQuota::acceptableis consulted. The branch must be restored together withTokenBucket.
Sourcepub fn add_metric_name(
&self,
metric_name: MetricName,
stat: Box<dyn MeasurableStat>,
) -> Result<bool, Error>
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).
Sourcepub fn add_metric_name_config(
&self,
metric_name: MetricName,
stat: Box<dyn MeasurableStat>,
config: Option<Arc<MetricConfig>>,
) -> Result<bool, Error>
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).
Sourcepub fn add(&self, stat: Box<dyn CompoundStat>) -> Result<bool, Error>
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).
Sourcepub fn add_config(
&self,
stat: Box<dyn CompoundStat>,
config: Option<Arc<MetricConfig>>,
) -> Result<bool, Error>
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.
Sourcepub fn has_metrics(&self) -> bool
pub fn has_metrics(&self) -> bool
Return if metrics were registered with this sensor.
Sourcepub fn has_expired(&self) -> bool
pub fn has_expired(&self) -> bool
Return true if the sensor is eligible for removal due to inactivity.