/** * Add a metric to monitor an object that implements MetricValueProvider. This metric won't be associated with any * sensor. This is a way to expose existing values as metrics. User is expected to add any additional * synchronization to update and access metric values, if required. * * @param metricName The name of the metric * @param metricValueProvider The metric value provider associated with this metric */ public void addMetric(MetricName metricName, MetricValueProvider<?> metricValueProvider) { addMetric(metricName, null, metricValueProvider); }
/** * Add a metric to monitor an object that implements measurable. This metric won't be associated with any sensor. * This is a way to expose existing values as metrics. * * This method is kept for binary compatibility purposes, it has the same behaviour as * {@link #addMetric(MetricName, MetricValueProvider)}. * * @param metricName The name of the metric * @param measurable The measurable that will be measured by this metric */ public void addMetric(MetricName metricName, Measurable measurable) { addMetric(metricName, null, measurable); }
public void addMetric(MetricName m, Measurable measurable) { this.metrics.addMetric(m, measurable); }
/** * Add a metric to monitor an object that implements Measurable. This metric won't be associated with any sensor. * This is a way to expose existing values as metrics. * * This method is kept for binary compatibility purposes, it has the same behaviour as * {@link #addMetric(MetricName, MetricConfig, MetricValueProvider)}. * * @param metricName The name of the metric * @param config The configuration to use when measuring this measurable * @param measurable The measurable that will be measured by this metric */ public void addMetric(MetricName metricName, MetricConfig config, Measurable measurable) { addMetric(metricName, config, (MetricValueProvider<?>) measurable); }
addMetric(metricName("count", "kafka-metrics-count", "total number of registered metrics"), new Measurable() { @Override
private void registerMetrics(Metrics metrics, String metricGrpName) { MetricName metricName = metrics.metricName("waiting-threads", metricGrpName, "The number of user threads blocked waiting for buffer memory to enqueue their records"); Measurable waitingThreads = new Measurable() { public double measure(MetricConfig config, long now) { return free.queued(); } }; metrics.addMetric(metricName, waitingThreads); metricName = metrics.metricName("buffer-total-bytes", metricGrpName, "The maximum amount of buffer memory the client can use (whether or not it is currently used)."); Measurable totalBytes = new Measurable() { public double measure(MetricConfig config, long now) { return free.totalMemory(); } }; metrics.addMetric(metricName, totalBytes); metricName = metrics.metricName("buffer-available-bytes", metricGrpName, "The total amount of buffer memory that is not being used (either unallocated or in the free list)."); Measurable availableBytes = new Measurable() { public double measure(MetricConfig config, long now) { return free.availableMemory(); } }; metrics.addMetric(metricName, availableBytes); Sensor bufferExhaustedRecordSensor = metrics.sensor("buffer-exhausted-records"); MetricName rateMetricName = metrics.metricName("buffer-exhausted-rate", metricGrpName, "The average per-second number of record sends that are dropped due to buffer exhaustion"); MetricName totalMetricName = metrics.metricName("buffer-exhausted-total", metricGrpName, "The total number of record sends that are dropped due to buffer exhaustion"); bufferExhaustedRecordSensor.add(new Meter(rateMetricName, totalMetricName)); }
reporters.add(new JmxReporter(JMX_PREFIX)); Metrics metrics = new Metrics(new MetricConfig(), reporters, new SystemTime()); metrics.addMetric(metrics.metricName("offline-runnable-count", METRIC_GROUP_NAME, "The number of Service/App that are not fully running"), new Measurable() { @Override
@Test public void testRemoveMetric() { int size = metrics.metrics().size(); metrics.addMetric(metrics.metricName("test1", "grp1"), new Count()); metrics.addMetric(metrics.metricName("test2", "grp1"), new Count()); assertNotNull(metrics.removeMetric(metrics.metricName("test1", "grp1"))); assertNull(metrics.metrics().get(metrics.metricName("test1", "grp1"))); assertNotNull(metrics.metrics().get(metrics.metricName("test2", "grp1"))); assertNotNull(metrics.removeMetric(metrics.metricName("test2", "grp1"))); assertNull(metrics.metrics().get(metrics.metricName("test2", "grp1"))); assertEquals(size, metrics.metrics().size()); }
private ConsumerCoordinatorMetrics(Metrics metrics, String metricGrpPrefix) { this.metricGrpName = metricGrpPrefix + "-coordinator-metrics"; this.commitLatency = metrics.sensor("commit-latency"); this.commitLatency.add(metrics.metricName("commit-latency-avg", this.metricGrpName, "The average time taken for a commit request"), new Avg()); this.commitLatency.add(metrics.metricName("commit-latency-max", this.metricGrpName, "The max time taken for a commit request"), new Max()); this.commitLatency.add(createMeter(metrics, metricGrpName, "commit", "commit calls")); Measurable numParts = new Measurable() { public double measure(MetricConfig config, long now) { // Get the number of assigned partitions in a thread safe manner return subscriptions.numAssignedPartitions(); } }; metrics.addMetric(metrics.metricName("assigned-partitions", this.metricGrpName, "The number of partitions currently assigned to this consumer"), numParts); } }
this.metrics.addMetric(metricName, (config, now) -> channels.size());
private void verifyStats(Function<KafkaMetric, Double> metricValueFunc) { ConstantMeasurable measurable = new ConstantMeasurable(); metrics.addMetric(metrics.metricName("direct.measurable", "grp1", "The fraction of time an appender waits for space allocation."), measurable); Sensor s = metrics.sensor("test.sensor"); s.add(metrics.metricName("test.avg", "grp1"), new Avg());
metrics.addMetric(metrics.metricName("last-heartbeat-seconds-ago", this.metricGrpName, "The number of seconds since the last coordinator heartbeat was sent"),
new Percentile(new MetricName("produce-delay-ms-9999th", METRIC_GROUP_NAME, "The 99.99th percentile delay in ms for produce request", tags), 99.99))); metrics.addMetric(new MetricName("produce-availability-avg", METRIC_GROUP_NAME, "The average produce availability", tags), new Measurable() { @Override
new Percentile(new MetricName("records-delay-ms-9999th", METRIC_GROUP_NAME, "The 99.99th percentile latency of records from producer to consumer", tags), 99.99))); metrics.addMetric(new MetricName("consume-availability-avg", METRIC_GROUP_NAME, "The average consume availability", tags), new Measurable() { @Override
/** * Add a metric to monitor an object that implements measurable. 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 measurable The measurable that will be measured by this metric */ public void addMetric(MetricName metricName, Measurable measurable) { addMetric(metricName, null, measurable); }
public WorkerCoordinatorMetrics(Metrics metrics, String metricGrpPrefix) { this.metrics = metrics; this.metricGrpName = metricGrpPrefix + "-coordinator-metrics"; Measurable numTasks = (config, now) -> assignmentSnapshot.tasks().size(); metrics.addMetric(metrics.metricName("assigned-tasks", this.metricGrpName, "The number of tasks currently assigned to this consumer"), numTasks); } }
private void addRatioMetric(final State matchingState, MetricNameTemplate template) { MetricName metricName = metricGroup.metricName(template); if (metricGroup.metrics().metric(metricName) == null) { metricGroup.metrics().addMetric(metricName, new Measurable() { @Override public double measure(MetricConfig config, long now) { return taskStateTimer.durationRatio(matchingState, now); } }); } }