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 name(&self) -> &str
pub fn name(&self) -> &str
Returns the name this sensor is registered with. This name will be unique among all registered sensors.
Sourcepub fn should_record(&self) -> bool
pub fn should_record(&self) -> bool
Returns true if the sensor’s record level indicates that the metric will be recorded, false otherwise.
Sourcepub fn record(&self) -> Result<(), Error>
pub fn record(&self) -> Result<(), Error>
Record an occurrence, this is just short-hand for record_with_value(1.0).
§Errors
Error::is_quota_violation_errorif recording moves a metric beyond its configured maximum or minimum bound
Sourcepub fn record_with_value_time_ms(
&self,
value: f64,
time_ms: i64,
) -> Result<(), Error>
pub fn record_with_value_time_ms( &self, value: f64, time_ms: i64, ) -> Result<(), Error>
Record a value at a known time. This method is slightly faster than
record_with_value since it will reuse the time stamp.
§Arguments
value- The value we are recordingtime_ms- The current POSIX time in milliseconds
§Errors
Error::is_quota_violation_errorif recording this value moves a metric beyond its configured maximum or minimum bound
Sourcepub fn record_with_value_time_ms_check_quotas(
&self,
value: f64,
time_ms: i64,
check_quotas: bool,
) -> Result<(), Error>
pub fn record_with_value_time_ms_check_quotas( &self, value: f64, time_ms: i64, check_quotas: bool, ) -> Result<(), Error>
Record a value at a known time. This method is slightly faster than
record_with_value since it will reuse the time stamp.
§Arguments
value- The value we are recordingtime_ms- The current POSIX time in millisecondscheck_quotas- Indicate if quota must be enforced or not
§Errors
Error::is_quota_violation_errorif recording this value moves a metric beyond its configured maximum or minimum bound
Sourcepub fn check_quotas(&self) -> Result<(), Error>
pub fn check_quotas(&self) -> Result<(), Error>
Check if we have violated our quota for any metric that has a configured quota
§Errors
Error::is_quota_violation_errorif a metric’s value is outside its quota
Sourcepub fn add_with_metric_name(
&self,
metric_name: MetricName,
stat: Box<dyn MeasurableStat>,
) -> Result<bool, Error>
pub fn add_with_metric_name( &self, metric_name: MetricName, stat: Box<dyn MeasurableStat>, ) -> Result<bool, Error>
Register a metric with this sensor
§Arguments
metric_name- The name of the metricstat- The statistic to keep
§Returns
true if metric is added to sensor, false if sensor is expired
§Errors
Error::is_local_illegal_argument_errorif a metric of the same name is already registered in the registry by another sensor
Sourcepub fn add_with_metric_name_config(
&self,
metric_name: MetricName,
stat: Box<dyn MeasurableStat>,
config: Option<Arc<MetricConfig>>,
) -> Result<bool, Error>
pub fn add_with_metric_name_config( &self, metric_name: MetricName, stat: Box<dyn MeasurableStat>, config: Option<Arc<MetricConfig>>, ) -> Result<bool, Error>
Register a metric with this sensor
§Arguments
metric_name- The name of the metricstat- The statistic to keepconfig- A special configuration for this metric. If None use the sensor default configuration.
§Returns
true if metric is added to sensor, false if sensor is expired
§Errors
Error::is_local_illegal_argument_errorif a metric of the same name is already registered in the registry by another sensor
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
§Arguments
stat- The stat to register
§Returns
true if stat is added to sensor, false if sensor is expired
§Errors
Error::is_local_illegal_argument_errorif a metric of the same name is already registered in the registry by another sensor
Sourcepub fn add_with_config(
&self,
stat: Box<dyn CompoundStat>,
config: Option<Arc<MetricConfig>>,
) -> Result<bool, Error>
pub fn add_with_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)
§Arguments
stat- The stat to registerconfig- The configuration for this stat. If None then the stat will use the default configuration for this sensor.
§Returns
true if stat is added to sensor, false if sensor is expired
§Errors
Error::is_local_illegal_argument_errorif a metric of the same name is already registered in the registry by another sensor
Sourcepub fn has_metrics(&self) -> bool
pub fn has_metrics(&self) -> bool
Return if metrics were registered with this sensor.
§Returns
true if metrics were registered, false otherwise
Sourcepub fn has_expired(&self) -> bool
pub fn has_expired(&self) -> bool
Returns true if the sensor is eligible for removal due to inactivity.