@Test public void testMetricInstances() { MetricName n1 = metrics.metricInstance(SampleMetrics.METRIC1, "key1", "value1", "key2", "value2"); Map<String, String> tags = new HashMap<String, String>(); tags.put("key1", "value1"); tags.put("key2", "value2"); MetricName n2 = metrics.metricInstance(SampleMetrics.METRIC2, tags); assertEquals("metric names created in two different ways should be equal", n1, n2); try { metrics.metricInstance(SampleMetrics.METRIC1, "key1"); fail("Creating MetricName with an odd number of keyValue should fail"); } catch (IllegalArgumentException e) { } Map<String, String> parentTagsWithValues = new HashMap<>(); parentTagsWithValues.put("parent-tag", "parent-tag-value"); Map<String, String> childTagsWithValues = new HashMap<>(); childTagsWithValues.put("child-tag", "child-tag-value"); try (Metrics inherited = new Metrics(new MetricConfig().tags(parentTagsWithValues), Arrays.asList((MetricsReporter) new JmxReporter()), time, true)) { MetricName inheritedMetric = inherited.metricInstance(SampleMetrics.METRIC_WITH_INHERITED_TAGS, childTagsWithValues); Map<String, String> filledOutTags = inheritedMetric.tags(); assertEquals("parent-tag should be set properly", filledOutTags.get("parent-tag"), "parent-tag-value"); assertEquals("child-tag should be set properly", filledOutTags.get("child-tag"), "child-tag-value"); try { inherited.metricInstance(SampleMetrics.METRIC_WITH_INHERITED_TAGS, parentTagsWithValues); fail("Creating MetricName should fail if the child metrics are not defined at runtime"); } catch (IllegalArgumentException e) { } try { Map<String, String> runtimeTags = new HashMap<>(); runtimeTags.put("child-tag", "child-tag-value"); runtimeTags.put("tag-not-in-template", "unexpected-value"); inherited.metricInstance(SampleMetrics.METRIC_WITH_INHERITED_TAGS, runtimeTags); fail("Creating MetricName should fail if there is a tag at runtime that is not in the template"); } catch (IllegalArgumentException e) { } } }
public MetricName metricInstance(MetricNameTemplate template, String... keyValue) { return metricInstance(template, getTags(keyValue)); }
Metrics implements Closeable { public MetricName metricInstance(MetricNameTemplate template, String... keyValue) { return metricInstance(template, getTags(keyValue)); } }
Metrics implements Closeable { public MetricName metricInstance(MetricNameTemplate template, String... keyValue) { return metricInstance(template, getTags(keyValue)); } Metrics();  Metrics(Time time);  Metrics(MetricConfig defaultConfig, Time time);  Metrics(MetricConfig defaultConfig);  Metrics(MetricConfig defaultConfig, List<MetricsReporter> reporters, Time time);  Metrics(MetricConfig defaultConfig, List<MetricsReporter> reporters, Time time, boolean enableExpiration); }
Metrics implements Closeable { public MetricName metricInstance(MetricNameTemplate template, String... keyValue) { return metricInstance(template, getTags(keyValue)); } Metrics();  Metrics(Time time);  Metrics(MetricConfig defaultConfig, Time time);  Metrics(MetricConfig defaultConfig);  Metrics(MetricConfig defaultConfig, List<MetricsReporter> reporters, Time time);  Metrics(MetricConfig defaultConfig, List<MetricsReporter> reporters, Time time, boolean enableExpiration); MetricName metricName(String name, String group, String description, Map<String, String> tags); MetricName metricName(String name, String group, String description); MetricName metricName(String name, String group); MetricName metricName(String name, String group, String description, String... keyValue); MetricName metricName(String name, String group, Map<String, String> tags); static String toHtmlTable(String domain, List<MetricNameTemplate> allMetrics); MetricConfig config(); Sensor getSensor(String name); Sensor sensor(String name); Sensor sensor(String name, Sensor.RecordingLevel recordingLevel); Sensor sensor(String name, Sensor... parents); Sensor sensor(String name, Sensor.RecordingLevel recordingLevel, Sensor... parents); synchronized Sensor sensor(String name, MetricConfig config, Sensor... parents); synchronized Sensor sensor(String name, MetricConfig config, Sensor.RecordingLevel recordingLevel, Sensor... parents); synchronized Sensor sensor(String name, MetricConfig config, long inactiveSensorExpirationTimeSeconds, Sensor.RecordingLevel recordingLevel, Sensor... parents); synchronized Sensor sensor(String name, MetricConfig config, long inactiveSensorExpirationTimeSeconds, Sensor... parents); void removeSensor(String name); void addMetric(MetricName metricName, Measurable measurable); synchronized void addMetric(MetricName metricName, MetricConfig config, Measurable measurable); synchronized KafkaMetric removeMetric(MetricName metricName); synchronized void addReporter(MetricsReporter reporter); Map<MetricName, KafkaMetric> metrics(); List<MetricsReporter> reporters(); KafkaMetric metric(MetricName metricName); MetricName metricInstance(MetricNameTemplate template, String... keyValue); MetricName metricInstance(MetricNameTemplate template, Map<String, String> tags); @Override void close(); }
Metrics implements Closeable { public MetricName metricInstance(MetricNameTemplate template, String... keyValue) { return metricInstance(template, getTags(keyValue)); } Metrics();  Metrics(Time time);  Metrics(MetricConfig defaultConfig, Time time);  Metrics(MetricConfig defaultConfig);  Metrics(MetricConfig defaultConfig, List<MetricsReporter> reporters, Time time);  Metrics(MetricConfig defaultConfig, List<MetricsReporter> reporters, Time time, boolean enableExpiration); MetricName metricName(String name, String group, String description, Map<String, String> tags); MetricName metricName(String name, String group, String description); MetricName metricName(String name, String group); MetricName metricName(String name, String group, String description, String... keyValue); MetricName metricName(String name, String group, Map<String, String> tags); static String toHtmlTable(String domain, List<MetricNameTemplate> allMetrics); MetricConfig config(); Sensor getSensor(String name); Sensor sensor(String name); Sensor sensor(String name, Sensor.RecordingLevel recordingLevel); Sensor sensor(String name, Sensor... parents); Sensor sensor(String name, Sensor.RecordingLevel recordingLevel, Sensor... parents); synchronized Sensor sensor(String name, MetricConfig config, Sensor... parents); synchronized Sensor sensor(String name, MetricConfig config, Sensor.RecordingLevel recordingLevel, Sensor... parents); synchronized Sensor sensor(String name, MetricConfig config, long inactiveSensorExpirationTimeSeconds, Sensor.RecordingLevel recordingLevel, Sensor... parents); synchronized Sensor sensor(String name, MetricConfig config, long inactiveSensorExpirationTimeSeconds, Sensor... parents); void removeSensor(String name); void addMetric(MetricName metricName, Measurable measurable); synchronized void addMetric(MetricName metricName, MetricConfig config, Measurable measurable); synchronized KafkaMetric removeMetric(MetricName metricName); synchronized void addReporter(MetricsReporter reporter); Map<MetricName, KafkaMetric> metrics(); List<MetricsReporter> reporters(); KafkaMetric metric(MetricName metricName); MetricName metricInstance(MetricNameTemplate template, String... keyValue); MetricName metricInstance(MetricNameTemplate template, Map<String, String> tags); @Override void close();  }