org.apache.kafka.common
Class MetricName

java.lang.Object
  extended by org.apache.kafka.common.MetricName

public final class MetricName
extends java.lang.Object

The MetricName class encapsulates a metric's name, logical group and its related attributes

This class captures the following parameters

  name The name of the metric
  group logical group name of the metrics to which this metric belongs.
  description A human-readable description to include in the metric. This is optional.
  tags additional key/value attributes of the metric. This is optional.
 
group, tags parameters can be used to create unique metric names while reporting in JMX or any custom reporting.

Ex: standard JMX MBean can be constructed like domainName:type=group,key1=val1,key2=val2

Usage looks something like this:

// set up metrics:
 Metrics metrics = new Metrics(); // this is the global repository of metrics and sensors
 Sensor sensor = metrics.sensor("message-sizes");

 Map<String, String> metricTags = new LinkedHashMap<String, String>();
 metricTags.put("client-id", "producer-1");
 metricTags.put("topic", "topic");

 MetricName metricName = new MetricName("message-size-avg", "producer-metrics", "average message size", metricTags);
 sensor.add(metricName, new Avg());

 metricName = new MetricName("message-size-max", "producer-metrics", metricTags);
 sensor.add(metricName, new Max());

 metricName = new MetricName("message-size-min", "producer-metrics", "message minimum size", "client-id", "my-client", "topic", "my-topic");
 sensor.add(metricName, new Min());

 // as messages are sent we record the sizes
 sensor.record(messageSize);
 


Constructor Summary
MetricName(java.lang.String name, java.lang.String group)
           
MetricName(java.lang.String name, java.lang.String group, java.util.Map<java.lang.String,java.lang.String> tags)
           
MetricName(java.lang.String name, java.lang.String group, java.lang.String description)
           
MetricName(java.lang.String name, java.lang.String group, java.lang.String description, java.util.Map<java.lang.String,java.lang.String> tags)
           
MetricName(java.lang.String name, java.lang.String group, java.lang.String description, java.lang.String... keyValue)
           
 
Method Summary
 java.lang.String description()
           
 boolean equals(java.lang.Object obj)
           
 java.lang.String group()
           
 int hashCode()
           
 java.lang.String name()
           
 java.util.Map<java.lang.String,java.lang.String> tags()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MetricName

public MetricName(java.lang.String name,
                  java.lang.String group,
                  java.lang.String description,
                  java.util.Map<java.lang.String,java.lang.String> tags)
Parameters:
name - The name of the metric
group - logical group name of the metrics to which this metric belongs
description - A human-readable description to include in the metric
tags - additional key/value attributes of the metric

MetricName

public MetricName(java.lang.String name,
                  java.lang.String group,
                  java.lang.String description,
                  java.lang.String... keyValue)
Parameters:
name - The name of the metric
group - logical group name of the metrics to which this metric belongs
description - A human-readable description to include in the metric
keyValue - additional key/value attributes of the metric (must come in pairs)

MetricName

public MetricName(java.lang.String name,
                  java.lang.String group,
                  java.util.Map<java.lang.String,java.lang.String> tags)
Parameters:
name - The name of the metric
group - logical group name of the metrics to which this metric belongs
tags - key/value attributes of the metric

MetricName

public MetricName(java.lang.String name,
                  java.lang.String group,
                  java.lang.String description)
Parameters:
name - The name of the metric
group - logical group name of the metrics to which this metric belongs
description - A human-readable description to include in the metric

MetricName

public MetricName(java.lang.String name,
                  java.lang.String group)
Parameters:
name - The name of the metric
group - logical group name of the metrics to which this metric belongs
Method Detail

name

public java.lang.String name()

group

public java.lang.String group()

tags

public java.util.Map<java.lang.String,java.lang.String> tags()

description

public java.lang.String description()

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object