Package org.eclipse.microprofile.metrics
Class Metadata
- java.lang.Object
-
- org.eclipse.microprofile.metrics.Metadata
-
public class Metadata extends java.lang.Object
Bean holding the metadata of one single metric. The metadata contains:-
Name
: (Required) The name of the metric. -
Display name
: (Optional) The display (friendly) name of the metric. By default, it is set to theName
. -
Description
: (Optional) A human readable description of the metric. -
Type
: (Required) The type of the metric. SeeMetricType
. -
Unit
: (Optional) The unit of the metric. The unit may be any unit specified as a String or one specified inMetricUnits
. -
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 variableMP_METRICS_TAGS
. For example, the following can be used to set the global tags:export MP_METRICS_TAGS=app=shop,tier=integration
-
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
GLOBAL_TAGS_VARIABLE
The environment variable used to pass in global tags.
-
Constructor Summary
Constructors Constructor Description Metadata(java.lang.String name, java.lang.String displayName, java.lang.String description, MetricType type, java.lang.String unit)
Constructs a Metadata objectMetadata(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 objectMetadata(java.lang.String name, MetricType type)
Constructs a Metadata object with default unitsMetadata(java.lang.String name, MetricType type, java.lang.String unit)
Constructs a Metadata objectMetadata(java.util.Map<java.lang.String,java.lang.String> in)
Constructs a Metadata object from a map with the following keysname
- 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 theMetricType
.MetricType
getTypeRaw()
Returns theMetricType
of the metricjava.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(java.lang.String type)
Sets the metric type using a String representation ofMetricType
.void
setType(MetricType type)
Sets the type of the metricvoid
setUnit(java.lang.String unit)
Sets the unit of the metric.java.lang.String
toString()
-
-
-
Field Detail
-
GLOBAL_TAGS_VARIABLE
public static final java.lang.String GLOBAL_TAGS_VARIABLE
The environment variable used to pass in global tags.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Metadata
public Metadata(java.lang.String name, MetricType type)
Constructs a Metadata object with default units- Parameters:
name
- The name of the metrictype
- The type of the metric
-
Metadata
public Metadata(java.lang.String name, MetricType type, java.lang.String unit)
Constructs a Metadata object- Parameters:
name
- The name of the metrictype
- The type of the metricunit
- The units of the metric
-
Metadata
public Metadata(java.lang.String name, java.lang.String displayName, java.lang.String description, MetricType type, java.lang.String unit)
Constructs a Metadata object- Parameters:
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 metric
-
Metadata
public 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- Parameters:
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
-
Metadata
public Metadata(java.util.Map<java.lang.String,java.lang.String> in)
Constructs a Metadata object from a map with the following keysname
- 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.
- Parameters:
in
- a map of key/value pairs representing Metadata
-
-
Method Detail
-
getName
public java.lang.String getName()
Returns the metric name.- Returns:
- the metric name.
-
setName
public void setName(java.lang.String name)
Sets the metric name.- Parameters:
name
- the new metric name
-
getDisplayName
public java.lang.String getDisplayName()
Returns the display name if set, otherwise this method returns the metric name.- Returns:
- the display name
-
setDisplayName
public void setDisplayName(java.lang.String displayName)
Sets the display name.- Parameters:
displayName
- the new display name
-
getDescription
public java.lang.String getDescription()
Returns the description of the metric.- Returns:
- the description
-
setDescription
public void setDescription(java.lang.String description)
Sets the description of the metric.- Parameters:
description
- the new description
-
getType
public java.lang.String getType()
Returns the String representation of theMetricType
.- Returns:
- the MetricType as a String
- See Also:
MetricType
-
getTypeRaw
public MetricType getTypeRaw()
Returns theMetricType
of the metric- Returns:
- the
MetricType
-
setType
public void setType(java.lang.String type) throws java.lang.IllegalArgumentException
Sets the metric type using a String representation ofMetricType
.- Parameters:
type
- the new metric type- Throws:
java.lang.IllegalArgumentException
- if the String is not a validMetricType
-
setType
public void setType(MetricType type)
Sets the type of the metric- Parameters:
type
- the new metric type
-
getUnit
public java.lang.String getUnit()
Returns the unit of the metric.- Returns:
- the unit
-
setUnit
public void setUnit(java.lang.String unit)
Sets the unit of the metric.- Parameters:
unit
- the new unit
-
isReusable
public boolean isReusable()
Can the metric be reused (i.e. same name registered multiple times)?- Returns:
- True if reusable, false otherwise
-
setReusable
public void setReusable(boolean reusable)
Set if the metric can be reusable (i.e. same name registered multiple times)?- Parameters:
reusable
- True if reusable, false otherwise
-
getTagsAsString
public java.lang.String getTagsAsString()
Gets the list of tags as a single String in the format 'key="value",key2="value2",...'- Returns:
- a String containing the tags
-
getTags
public java.util.HashMap<java.lang.String,java.lang.String> getTags()
Returns the underlying HashMap containing the tags.- Returns:
- a hashmap of tags
-
addTag
public void addTag(java.lang.String kvString)
Add one single tag with the format: 'key=value'. If the input is empty or does not contain a '=' sign, the entry is ignored.- Parameters:
kvString
- Input string
-
addTags
public void addTags(java.lang.String tagsString)
Add multiple tags delimited by commas. The format must be in the form 'key1=value1, key2=value2'. This method will calladdTag(String)
on each tag.- Parameters:
tagsString
- a string containing multiple tags
-
setTags
public void setTags(java.util.HashMap<java.lang.String,java.lang.String> tags)
Sets the tags hashmap.- Parameters:
tags
- a hashmap containing tags.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-