@Test public void testThreadSafeAssignedPartitionsMetric() throws Exception { final Metric metric = metrics.metric(new MetricName("assigned-partitions", "consumer" + groupId + "-coordinator-metrics", "", Collections.<String, String>emptyMap()));
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); } }); } }
/** * Add to this group an indicator metric that always returns the specified value. * * @param nameTemplate the name template for the metric; may not be null * @param value the value; may not be null * @throws IllegalArgumentException if the name is not valid */ public <T> void addImmutableValueMetric(MetricNameTemplate nameTemplate, final T value) { MetricName metricName = metricName(nameTemplate); if (metrics().metric(metricName) == null) { metrics().addMetric(metricName, new Gauge<T>() { @Override public T value(MetricConfig config, long now) { return value; } }); } }
/** * Add to this group an indicator metric with a function that returns the current value. * * @param nameTemplate the name template for the metric; may not be null * @param supplier the function used to determine the literal value of the metric; may not be null * @throws IllegalArgumentException if the name is not valid */ public <T> void addValueMetric(MetricNameTemplate nameTemplate, final LiteralSupplier<T> supplier) { MetricName metricName = metricName(nameTemplate); if (metrics().metric(metricName) == null) { metrics().addMetric(metricName, new Gauge<T>() { @Override public T value(MetricConfig config, long now) { return supplier.metricValue(now); } }); } }