public class Metadata
extends java.lang.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 java.lang.String |
GLOBAL_TAGS_VARIABLE
The environment variable used to pass in global tags.
|
Constructor and Description |
---|
Metadata(java.util.Map<java.lang.String,java.lang.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(java.lang.String name,
MetricType type)
Constructs a Metadata object with default units
|
Metadata(java.lang.String name,
MetricType type,
java.lang.String unit)
Constructs a Metadata object
|
Metadata(java.lang.String name,
java.lang.String displayName,
java.lang.String description,
MetricType type,
java.lang.String unit)
Constructs a Metadata object
|
Metadata(java.lang.String name,
java.lang.String displayName,
java.lang.String description,
MetricType type,
java.lang.String unit,
java.lang.String tags)
Constructs a Metadata object
|
Modifier and Type | Method and Description |
---|---|
void |
addTag(java.lang.String kvString)
Add one single tag with the format: 'key=value'.
|
void |
addTags(java.lang.String tagsString)
Add multiple tags delimited by commas.
|
java.lang.String |
getDescription()
Returns the description of the metric.
|
java.lang.String |
getDisplayName()
Returns the display name if set, otherwise this method returns the metric name.
|
java.lang.String |
getName()
Returns the metric name.
|
java.util.HashMap<java.lang.String,java.lang.String> |
getTags()
Returns the underlying HashMap containing the tags.
|
java.lang.String |
getTagsAsString()
Gets the list of tags as a single String in the format 'key="value",key2="value2",...'
|
java.lang.String |
getType()
Returns the String representation of the
MetricType . |
MetricType |
getTypeRaw()
Returns the
MetricType of the metric |
java.lang.String |
getUnit()
Returns the unit of the metric.
|
int |
hashCode() |
boolean |
isReusable()
Can the metric be reused (i.e.
|
void |
setDescription(java.lang.String description)
Sets the description of the metric.
|
void |
setDisplayName(java.lang.String displayName)
Sets the display name.
|
void |
setName(java.lang.String name)
Sets the metric name.
|
void |
setReusable(boolean reusable)
Set if the metric can be reusable (i.e.
|
void |
setTags(java.util.HashMap<java.lang.String,java.lang.String> tags)
Sets the tags hashmap.
|
void |
setType(MetricType type)
Sets the type of the metric
|
void |
setType(java.lang.String type)
Sets the metric type using a String representation of
MetricType . |
void |
setUnit(java.lang.String unit)
Sets the unit of the metric.
|
java.lang.String |
toString() |
public static final java.lang.String GLOBAL_TAGS_VARIABLE
public Metadata(java.lang.String name, MetricType type)
name
- The name of the metrictype
- The type of the metricpublic Metadata(java.lang.String name, MetricType type, java.lang.String unit)
name
- The name of the metrictype
- The type of the metricunit
- The units of the metricpublic Metadata(java.lang.String name, java.lang.String displayName, java.lang.String description, MetricType type, java.lang.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(java.lang.String name, java.lang.String displayName, java.lang.String description, MetricType type, java.lang.String unit, java.lang.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(java.util.Map<java.lang.String,java.lang.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 java.lang.String getName()
public void setName(java.lang.String name)
name
- the new metric namepublic java.lang.String getDisplayName()
public void setDisplayName(java.lang.String displayName)
displayName
- the new display namepublic java.lang.String getDescription()
public void setDescription(java.lang.String description)
description
- the new descriptionpublic java.lang.String getType()
MetricType
.MetricType
public MetricType getTypeRaw()
MetricType
of the metricMetricType
public void setType(java.lang.String type) throws java.lang.IllegalArgumentException
MetricType
.type
- the new metric typejava.lang.IllegalArgumentException
- if the String is not a valid MetricType
public void setType(MetricType type)
type
- the new metric typepublic java.lang.String getUnit()
public void setUnit(java.lang.String unit)
unit
- the new unitpublic boolean isReusable()
public void setReusable(boolean reusable)
reusable
- True if reusable, false otherwisepublic java.lang.String getTagsAsString()
public java.util.HashMap<java.lang.String,java.lang.String> getTags()
public void addTag(java.lang.String kvString)
kvString
- Input stringpublic void addTags(java.lang.String tagsString)
addTag(String)
on each tag.tagsString
- a string containing multiple tagspublic void setTags(java.util.HashMap<java.lang.String,java.lang.String> tags)
tags
- a hashmap containing tags.public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object