...
Code Block | ||
---|---|---|
| ||
public interface PluginMetrics extends Closeable { /** * Name of the tag for the plugin identifier. */ String PLUGIN_ID_TAG = "plugin-id"; /** * Create a {@link MetricName} with the given name, description and tags. * The plugin class name will beis used as the metric group and the plugin identifier is added to the * tags using {@link #PLUGIN_ID_TAG} as the name. * * @param name The name of the metric * @param description A human-readable description to include in the metric * @param tags additional key/value attributes of the metric */ public MetricName metricName(String name, String description, Map<String, String> tags); /** * Add a metric to monitor an object that implements {@link MetricValueProvider}. This metric won't be associated with any * sensor. This is a way to expose existing values as metrics. * * @param metricName The name of the metric * @param metricValueProvider The metric value provider associated with this metric * @throws IllegalArgumentException if a metric with same name already exists. */ public synchronized void addMetric(MetricName metricName, MetricValueProvider<?> metricValueProvider); /** * Remove a metric if it exists and return it. Return null otherwise. * * @param metricName The name of the metric * @return the removed KafkaMetric or null if no such metric exists */ publicvoid synchronized KafkaMetric removeMetric(MetricName metricName); /** * Get or create a sensor with the given unique name. * * @param name The sensor name * @return The sensor */ @throws IllegalArgumentException if a sensor with same name already exists. public synchronized */ Sensor sensor(String name); /** * Remove a sensor (if it exists) and its associated metrics. * * @param name The name of the sensor to be removed */ public synchronized void removeSensor(String name); /** * Delete all metrics and sensors registered by this plugin */ void close(); } |
Proposed Changes
When instantiating a class via the Utils.newInstance()
helper methods, if it implements Monitorable
and a Metrics
object is available, a new PluginMetrics instance will be created and passed to the withPluginMetrics()
method. It will be always called after configure()
. Metrics registered by plugins will inherit the prefix/namespace from the current Metrics
instance, these are: kafka.producer, kafka.consumer, kafka.connect, kafka.streams and kafka.server. Metrics reporters should not implement the Monitorable interface as they are created before the Metrics instance.
...