Package org.eclipse.microprofile.metrics
Class Metadata
java.lang.Object
org.eclipse.microprofile.metrics.Metadata
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
Modifier and TypeFieldDescriptionstatic final String
The environment variable used to pass in global tags. -
Constructor Summary
ConstructorDescriptionConstructs a Metadata objectMetadata
(String name, String displayName, String description, MetricType type, String unit, String tags) Constructs a Metadata objectMetadata
(String name, MetricType type) Constructs a Metadata object with default unitsMetadata
(String name, MetricType type, String unit) Constructs a Metadata objectConstructs 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
Modifier and TypeMethodDescriptionvoid
Add one single tag with the format: 'key=value'.void
Add multiple tags delimited by commas.Returns the description of the metric.Returns the display name if set, otherwise this method returns the metric name.getName()
Returns the metric name.getTags()
Returns the underlying HashMap containing the tags.Gets the list of tags as a single String in the format 'key="value",key2="value2",...'getType()
Returns the String representation of theMetricType
.Returns theMetricType
of the metricgetUnit()
Returns the unit of the metric.int
hashCode()
boolean
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
Sets the metric name.void
setReusable
(boolean reusable) Set if the metric can be reusable (i.e.void
Sets the tags hashmap.void
Sets the metric type using a String representation ofMetricType
.void
setType
(MetricType type) Sets the type of the metricvoid
Sets the unit of the metric.toString()
-
Field Details
-
GLOBAL_TAGS_VARIABLE
The environment variable used to pass in global tags.- See Also:
-
-
Constructor Details
-
Metadata
Constructs a Metadata object with default units- Parameters:
name
- The name of the metrictype
- The type of the metric
-
Metadata
Constructs a Metadata object- Parameters:
name
- The name of the metrictype
- The type of the metricunit
- The units of the metric
-
Metadata
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(String name, String displayName, String description, MetricType type, String unit, 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
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 Details
-
getName
Returns the metric name.- Returns:
- the metric name.
-
setName
Sets the metric name.- Parameters:
name
- the new metric name
-
getDisplayName
Returns the display name if set, otherwise this method returns the metric name.- Returns:
- the display name
-
setDisplayName
Sets the display name.- Parameters:
displayName
- the new display name
-
getDescription
Returns the description of the metric.- Returns:
- the description
-
setDescription
Sets the description of the metric.- Parameters:
description
- the new description
-
getType
Returns the String representation of theMetricType
.- Returns:
- the MetricType as a String
- See Also:
-
getTypeRaw
Returns theMetricType
of the metric- Returns:
- the
MetricType
-
setType
Sets the metric type using a String representation ofMetricType
.- Parameters:
type
- the new metric type- Throws:
IllegalArgumentException
- if the String is not a validMetricType
-
setType
Sets the type of the metric- Parameters:
type
- the new metric type
-
getUnit
Returns the unit of the metric.- Returns:
- the unit
-
setUnit
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
Gets the list of tags as a single String in the format 'key="value",key2="value2",...'- Returns:
- a String containing the tags
-
getTags
Returns the underlying HashMap containing the tags.- Returns:
- a hashmap of tags
-
addTag
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
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
Sets the tags hashmap.- Parameters:
tags
- a hashmap containing tags.
-
hashCode
public int hashCode() -
toString
-