Class Sensor


  • public final class Sensor
    extends Object
    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(double) api and would maintain a set of metrics about request sizes such as the average or max.
    • Method Detail

      • name

        public String name()
        The name this sensor is registered with. This name will be unique among all registered sensors.
      • shouldRecord

        public boolean shouldRecord()
        Returns:
        true if the sensor's record level indicates that the metric will be recorded, false otherwise
      • record

        public void record()
        Record an occurrence, this is just short-hand for record(1.0)
      • record

        public void record​(double value)
        Record a value with this sensor
        Parameters:
        value - The value to record
        Throws:
        QuotaViolationException - if recording this value moves a metric beyond its configured maximum or minimum bound
      • record

        public void record​(double value,
                           long timeMs)
        Record a value at a known time. This method is slightly faster than record(double) since it will reuse the time stamp.
        Parameters:
        value - The value we are recording
        timeMs - The current POSIX time in milliseconds
        Throws:
        QuotaViolationException - if recording this value moves a metric beyond its configured maximum or minimum bound
      • record

        public void record​(double value,
                           long timeMs,
                           boolean checkQuotas)
        Record a value at a known time. This method is slightly faster than record(double) since it will reuse the time stamp.
        Parameters:
        value - The value we are recording
        timeMs - The current POSIX time in milliseconds
        checkQuotas - Indicate if quota must be enforced or not
        Throws:
        QuotaViolationException - if recording this value moves a metric beyond its configured maximum or minimum bound
      • checkQuotas

        public void checkQuotas()
        Check if we have violated our quota for any metric that has a configured quota
      • checkQuotas

        public void checkQuotas​(long timeMs)
      • add

        public boolean add​(CompoundStat stat)
        Register a compound statistic with this sensor with no config override
        Parameters:
        stat - The stat to register
        Returns:
        true if stat is added to sensor, false if sensor is expired
      • add

        public boolean add​(CompoundStat stat,
                           MetricConfig config)
        Register a compound statistic with this sensor which yields multiple measurable quantities (like a histogram)
        Parameters:
        stat - The stat to register
        config - The configuration for this stat. If null then the stat will use the default configuration for this sensor.
        Returns:
        true if stat is added to sensor, false if sensor is expired
      • add

        public boolean add​(MetricName metricName,
                           MeasurableStat stat)
        Register a metric with this sensor
        Parameters:
        metricName - The name of the metric
        stat - The statistic to keep
        Returns:
        true if metric is added to sensor, false if sensor is expired
      • add

        public boolean add​(MetricName metricName,
                           MeasurableStat stat,
                           MetricConfig config)
        Register a metric with this sensor
        Parameters:
        metricName - The name of the metric
        stat - The statistic to keep
        config - A special configuration for this metric. If null use the sensor default configuration.
        Returns:
        true if metric is added to sensor, false if sensor is expired
      • hasMetrics

        public boolean hasMetrics()
        Return if metrics were registered with this sensor.
        Returns:
        true if metrics were registered, false otherwise
      • hasExpired

        public boolean hasExpired()
        Return true if the Sensor is eligible for removal due to inactivity. false otherwise