public final class MetricName extends Object
MetricName
class encapsulates a metric's name, logical group and its related attributes. It should be constructed using metrics.MetricName(...).
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:
Map<String, String> metricTags = new LinkedHashMap<String, String>();
metricTags.put("client-id", "producer-1");
metricTags.put("topic", "topic");
MetricConfig metricConfig = new MetricConfig().tags(metricTags);
Metrics metrics = new Metrics(metricConfig); // this is the global repository of metrics and sensors
Sensor sensor = metrics.sensor("message-sizes");
MetricName metricName = metrics.metricName("message-size-avg", "producer-metrics", "average message size");
sensor.add(metricName, new Avg());
metricName = metrics.metricName("message-size-max", "producer-metrics");
sensor.add(metricName, new Max());
metricName = metrics.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 and Description |
---|
MetricName(String name,
String group)
Deprecated.
This method will be removed in a future release.
Please create MetricName by method
Metrics.metricName(String, String) |
MetricName(String name,
String group,
Map<String,String> tags)
Deprecated.
This method will be removed in a future release.
Please create MetricName by method
Metrics.metricName(String, String, Map) |
MetricName(String name,
String group,
String description)
Deprecated.
This method will be removed in a future release.
Please create MetricName by method
Metrics.metricName(String, String, String) |
MetricName(String name,
String group,
String description,
Map<String,String> tags)
Please create MetricName by method
Metrics.metricName(String, String, String, Map) |
MetricName(String name,
String group,
String description,
String... keyValue)
Deprecated.
This method will be removed in a future release.
Please create MetricName by method
Metrics.metricName(String, String, String, String...) |
public MetricName(String name, String group, String description, Map<String,String> tags)
Metrics.metricName(String, String, String, Map)
name
- The name of the metricgroup
- logical group name of the metrics to which this metric belongsdescription
- A human-readable description to include in the metrictags
- additional key/value attributes of the metric@Deprecated public MetricName(String name, String group, String description, String... keyValue)
Metrics.metricName(String, String, String, String...)
name
- The name of the metricgroup
- logical group name of the metrics to which this metric belongsdescription
- A human-readable description to include in the metrickeyValue
- additional key/value attributes of the metric (must come in pairs)@Deprecated public MetricName(String name, String group, Map<String,String> tags)
Metrics.metricName(String, String, Map)
name
- The name of the metricgroup
- logical group name of the metrics to which this metric belongstags
- key/value attributes of the metric@Deprecated public MetricName(String name, String group, String description)
Metrics.metricName(String, String, String)
name
- The name of the metricgroup
- logical group name of the metrics to which this metric belongsdescription
- A human-readable description to include in the metric@Deprecated public MetricName(String name, String group)
Metrics.metricName(String, String)
name
- The name of the metricgroup
- logical group name of the metrics to which this metric belongs