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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
add
(MetricName metricName, MeasurableStat stat) Register a metric with this sensorboolean
add
(MetricName metricName, MeasurableStat stat, MetricConfig config) Register a metric with this sensorboolean
add
(CompoundStat stat) Register a compound statistic with this sensor with no config overrideboolean
add
(CompoundStat stat, MetricConfig config) Register a compound statistic with this sensor which yields multiple measurable quantities (like a histogram)void
Check if we have violated our quota for any metric that has a configured quotavoid
checkQuotas
(long timeMs) boolean
Return true if the Sensor is eligible for removal due to inactivity.boolean
Return if metrics were registered with this sensor.name()
The name this sensor is registered with.void
record()
Record an occurrence, this is just short-hand forrecord(1.0)
void
record
(double value) Record a value with this sensorvoid
record
(double value, long timeMs) Record a value at a known time.void
record
(double value, long timeMs, boolean checkQuotas) Record a value at a known time.boolean
-
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, 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 quota -
checkQuotas
public void checkQuotas(long timeMs) -
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 otherwise
-