Package org.apache.kafka.common.metrics
Class Sensor
- java.lang.Object
-
- org.apache.kafka.common.metrics.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 therecord(double)
api and would maintain a set of metrics about request sizes such as the average or max.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Sensor.RecordingLevel
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
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
checkQuotas()
Check if we have violated our quota for any metric that has a configured quotavoid
checkQuotas(long timeMs)
boolean
hasExpired()
Return true if the Sensor is eligible for removal due to inactivity.boolean
hasMetrics()
Return if metrics were registered with this sensor.String
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
shouldRecord()
-
-
-
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 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
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 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
public boolean add(MetricName metricName, MeasurableStat stat)
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
public boolean add(MetricName metricName, MeasurableStat stat, MetricConfig config)
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
-
-