public class Metadata extends Object
Name: (Required) The name of the metric.
Display name: (Optional) The display (friendly) name of the metric.
By default, it is set to the Name.
Description: (Optional) A human readable description of the metric.
Type: (Required) The type of the metric. See MetricType.
Unit: (Optional) The unit of the metric.
The unit may be any unit specified as a String or one specified in MetricUnits.
Tags: (Optional) The tags (represented by key/value pairs) of the metric which is augmented by global tags (if available).
Global tags can be set by passing the list of tags in an environment variable MP_METRICS_TAGS.
For example, the following can be used to set the global tags:
export MP_METRICS_TAGS=app=shop,tier=integration
| Modifier and Type | Field and Description |
|---|---|
static String |
GLOBAL_TAGS_VARIABLE
The environment variable used to pass in global tags.
|
| Constructor and Description |
|---|
Metadata(Map<String,String> in)
Constructs a Metadata object from a map with the following keys
name - The name of the metric
displayName - The display (friendly) name of the metric
description - The description of the metric
type - The type of the metric
unit - The units of the metric
tags - The tags of the metric - cannot be null
reusable - If true, this metric name is permitted to be used at multiple registration points. |
Metadata(String name,
MetricType type)
Constructs a Metadata object with default units
|
Metadata(String name,
MetricType type,
String unit)
Constructs a Metadata object
|
Metadata(String name,
String displayName,
String description,
MetricType type,
String unit)
Constructs a Metadata object
|
Metadata(String name,
String displayName,
String description,
MetricType type,
String unit,
String tags)
Constructs a Metadata object
|
| Modifier and Type | Method and Description |
|---|---|
void |
addTag(String kvString)
Add one single tag with the format: 'key=value'.
|
void |
addTags(String tagsString)
Add multiple tags delimited by commas.
|
String |
getDescription()
Returns the description of the metric.
|
String |
getDisplayName()
Returns the display name if set, otherwise this method returns the metric name.
|
String |
getName()
Returns the metric name.
|
HashMap<String,String> |
getTags()
Returns the underlying HashMap containing the tags.
|
String |
getTagsAsString()
Gets the list of tags as a single String in the format 'key="value",key2="value2",...'
|
String |
getType()
Returns the String representation of the
MetricType. |
MetricType |
getTypeRaw()
Returns the
MetricType of the metric |
String |
getUnit()
Returns the unit of the metric.
|
int |
hashCode() |
boolean |
isReusable()
Can the metric be reused (i.e.
|
void |
setDescription(String description)
Sets the description of the metric.
|
void |
setDisplayName(String displayName)
Sets the display name.
|
void |
setName(String name)
Sets the metric name.
|
void |
setReusable(boolean reusable)
Set if the metric can be reusable (i.e.
|
void |
setTags(HashMap<String,String> tags)
Sets the tags hashmap.
|
void |
setType(MetricType type)
Sets the type of the metric
|
void |
setType(String type)
Sets the metric type using a String representation of
MetricType. |
void |
setUnit(String unit)
Sets the unit of the metric.
|
String |
toString() |
public static final String GLOBAL_TAGS_VARIABLE
public Metadata(String name, MetricType type)
name - The name of the metrictype - The type of the metricpublic Metadata(String name, MetricType type, String unit)
name - The name of the metrictype - The type of the metricunit - The units of the metricpublic Metadata(String name, String displayName, String description, MetricType type, String unit)
name - The name of the metricdisplayName - The display (friendly) name of the metricdescription - The description of the metrictype - The type of the metricunit - The units of the metricpublic Metadata(String name, String displayName, String description, MetricType type, String unit, String tags)
name - The name of the metricdisplayName - The display (friendly) name of the metricdescription - The description of the metrictype - The type of the metricunit - The units of the metrictags - The tags of the metricpublic Metadata(Map<String,String> in)
name - The name of the metricdisplayName - The display (friendly) name of the metricdescription - The description of the metrictype - The type of the metricunit - The units of the metrictags - The tags of the metric - cannot be nullreusable - If true, this metric name is permitted to be used at multiple registration points. If
false, this metric name is only permitted to be used at one registration point per MetricRegistry.in - a map of key/value pairs representing Metadatapublic String getName()
public void setName(String name)
name - the new metric namepublic String getDisplayName()
public void setDisplayName(String displayName)
displayName - the new display namepublic String getDescription()
public void setDescription(String description)
description - the new descriptionpublic String getType()
MetricType.MetricTypepublic MetricType getTypeRaw()
MetricType of the metricMetricTypepublic void setType(String type) throws IllegalArgumentException
MetricType.type - the new metric typeIllegalArgumentException - if the String is not a valid MetricTypepublic void setType(MetricType type)
type - the new metric typepublic String getUnit()
public void setUnit(String unit)
unit - the new unitpublic boolean isReusable()
public void setReusable(boolean reusable)
reusable - True if reusable, false otherwisepublic String getTagsAsString()
public HashMap<String,String> getTags()
public void addTag(String kvString)
kvString - Input stringpublic void addTags(String tagsString)
addTag(String) on each tag.tagsString - a string containing multiple tagspublic void setTags(HashMap<String,String> tags)
tags - a hashmap containing tags.Copyright © 2017. All rights reserved.