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

Returns the name this sensor is registered with. This name will be unique among all registered sensors.

Source

pub fn should_record(&self) -> bool

Returns true if the sensor’s record level indicates that the metric will be recorded, false otherwise.

Source

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_error if recording moves a metric beyond its configured maximum or minimum bound
Source

pub fn record_with_value(&self, value: f64) -> Result<(), Error>

Record a value with this sensor

§Arguments
  • value - The value to record
§Errors
  • Error::is_quota_violation_error if recording this value moves a metric beyond its configured maximum or minimum bound
Source

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 recording
  • time_ms - The current POSIX time in milliseconds
§Errors
  • Error::is_quota_violation_error if recording this value moves a metric beyond its configured maximum or minimum bound
Source

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 recording
  • time_ms - The current POSIX time in milliseconds
  • check_quotas - Indicate if quota must be enforced or not
§Errors
  • Error::is_quota_violation_error if recording this value moves a metric beyond its configured maximum or minimum bound
Source

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_error if a metric’s value is outside its quota
Source

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

Check if we have violated our quota for any metric that has a configured quota, as of time_ms.

§Arguments
  • time_ms - the POSIX time in milliseconds to measure the metrics at
§Errors
  • Error::is_quota_violation_error if a metric’s value is outside its quota
Source

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 metric
  • stat - The statistic to keep
§Returns

true if metric is added to sensor, false if sensor is expired

§Errors
  • Error::is_local_illegal_argument_error if a metric of the same name is already registered in the registry by another sensor
Source

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 metric
  • stat - The statistic to keep
  • config - 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_error if a metric of the same name is already registered in the registry by another sensor
Source

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_error if a metric of the same name is already registered in the registry by another sensor
Source

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 register
  • config - 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_error if a metric of the same name is already registered in the registry by another sensor
Source

pub fn has_metrics(&self) -> bool

Return if metrics were registered with this sensor.

§Returns

true if metrics were registered, false otherwise

Source

pub fn has_expired(&self) -> bool

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

Trait Implementations§

Source§

impl Debug for Sensor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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