Package org.apache.kafka.common.metrics
Class Sensor
java.lang.Object
org.apache.kafka.common.metrics.Sensor
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.- 
Nested Class SummaryNested Classes
- 
Method SummaryModifier and TypeMethodDescriptionbooleanadd(MetricName metricName, MeasurableStat stat) Register a metric with this sensorbooleanadd(MetricName metricName, MeasurableStat stat, MetricConfig config) Register a metric with this sensorbooleanadd(CompoundStat stat) Register a compound statistic with this sensor with no config overridebooleanadd(CompoundStat stat, MetricConfig config) Register a compound statistic with this sensor which yields multiple measurable quantities (like a histogram)voidCheck if we have violated our quota for any metric that has a configured quotavoidcheckQuotas(long timeMs) booleanReturn true if the Sensor is eligible for removal due to inactivity.booleanReturn if metrics were registered with this sensor.name()The name this sensor is registered with.voidrecord()Record an occurrence, this is just short-hand forrecord(1.0)voidrecord(double value) Record a value with this sensorvoidrecord(double value, long timeMs) Record a value at a known time.voidrecord(double value, long timeMs, boolean checkQuotas) Record a value at a known time.boolean
- 
Method Details- 
nameThe name this sensor is registered with. This name will be unique among all registered sensors.
- 
shouldRecordpublic boolean shouldRecord()- Returns:
- true if the sensor's record level indicates that the metric will be recorded, false otherwise
 
- 
recordpublic void record()Record an occurrence, this is just short-hand forrecord(1.0)
- 
recordpublic 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
 
- 
recordpublic void record(double value, long timeMs) Record a value at a known time. This method is slightly faster thanrecord(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
 
- 
recordpublic void record(double value, long timeMs, boolean checkQuotas) Record a value at a known time. This method is slightly faster thanrecord(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
 
- 
checkQuotaspublic void checkQuotas()Check if we have violated our quota for any metric that has a configured quota
- 
checkQuotaspublic void checkQuotas(long timeMs) 
- 
addRegister 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
 
- 
addRegister 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
 
- 
addRegister 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
 
- 
addRegister 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
 
- 
hasMetricspublic boolean hasMetrics()Return if metrics were registered with this sensor.- Returns:
- true if metrics were registered, false otherwise
 
- 
hasExpiredpublic boolean hasExpired()Return true if the Sensor is eligible for removal due to inactivity. false otherwise
 
-