Metrics¶
Metrics
is a registry of sensors and performance metrics (of Kafka brokers and clients).
Creating Instance¶
Metrics
takes the following to be created:
- MetricConfig
-
MetricsReporter
s -
Time
-
enableExpiration
flag -
MetricsContext
Metrics
is created when:
Server
utility is used to buildMetricsKafkaAdminClient
utility is used tocreateInternal
KafkaConsumer
utility is used to buildMetricsKafkaProducer
is createdKafkaStreams
(Kafka Streams) utility is used togetMetrics
- Kafka Connect clients
addReporter¶
void addReporter(
MetricsReporter reporter)
addReporter
...FIXME
addReporter
is used when:
DynamicMetricsReporters
is requested tocreateReporters
sensors¶
Metrics
defines sensors
collection of metric Sensor
s by name (ConcurrentMap<String, Sensor>
).
sensors
is empty when Metrics
is created.
A new Sensor
is added in sensor.
sensor¶
Sensor sensor(
String name,
MetricConfig config,
long inactiveSensorExpirationTimeSeconds,
Sensor.RecordingLevel recordingLevel,
Sensor... parents)
Sensor sensor(...) // (1)
- There are others
sensor
looks up the sensor (by name) and returns it immediately if available.
Otherwise, sensor
creates a new Sensor
and adds it to the sensors registry.
In the end, sensor
prints out the following TRACE message to the logs:
Added sensor with name [name]
getSensor¶
Sensor getSensor(
String name)
getSensor
looks up the given name
in the sensors registry.
Logging¶
Enable ALL
logging level for org.apache.kafka.common.metrics.Metrics
logger to see what happens inside.
Add the following line to config/log4j.properties
:
log4j.logger.org.apache.kafka.common.metrics.Metrics=ALL
Refer to Logging.