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 Summary
Nested ClassesField Summary
FieldsMethod Summary
Modifier 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) voidcheckQuotasWithParents(long timeMs) getQuotaViolations(boolean checkParents) getQuotaViolations(long timeMs, boolean checkParents) 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.voidCalled byMetrics.removeSensor(String)when the sensor is removed.voidrecord()Record an occurrence, this is just short-hand forrecord(1.0)voidrecord(double value) Record a value with this sensorvoidrecord(double value, boolean checkQuotas) Record a value with this sensor, specifying whether quota check should be performedvoidrecord(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.booleanstats()Get the current measurements of this sensor's metrics and the parent sensors.
Field Details
EMPTY_REMOVE_CALLBACK
Method Details
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 forrecord(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, boolean checkQuotas) Record a value with this sensor, specifying whether quota check should be performed- Parameters:
value- the value to recordcheckQuotas- whether to perform quota check or not- Throws:
QuotaViolationException- if recording this value moves a metric beyond its configured maximum or minimum bound and quota check is enabled
record
public 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 recordingtimeMs- 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 thanrecord(double)since it will reuse the time stamp.- Parameters:
value- The value we are recordingtimeMs- The current POSIX time in millisecondscheckQuotas- 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 quotacheckQuotas
public void checkQuotas(long timeMs) checkQuotasWithParents
public void checkQuotasWithParents(long timeMs) getQuotaViolations
getQuotaViolations
add
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
Register a compound statistic with this sensor which yields multiple measurable quantities (like a histogram)- Parameters:
stat- The stat to registerconfig- 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
Register a metric with this sensor- Parameters:
metricName- The name of the metricstat- The statistic to keep- Returns:
- true if metric is added to sensor, false if sensor is expired
add
Register a metric with this sensor- Parameters:
metricName- The name of the metricstat- The statistic to keepconfig- 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 otherwiseonRemoval
public void onRemoval()Called byMetrics.removeSensor(String)when the sensor is removed.toDebugString
Get the current measurements of this sensor's metrics and the parent sensors. This method is slow as taking a measurement requires a lock on the sensor and all its metrics.- Returns:
- a list of measurements for each metric in this sensor and its parents
stats