Class Metadata

java.lang.Object
org.eclipse.microprofile.metrics.Metadata

public class Metadata extends 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 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
     
  • Field Details

    • GLOBAL_TAGS_VARIABLE

      public static final String GLOBAL_TAGS_VARIABLE
      The environment variable used to pass in global tags.
      See Also:
  • Constructor Details

    • Metadata

      public Metadata(String name, MetricType type)
      Constructs a Metadata object with default units
      Parameters:
      name - The name of the metric
      type - The type of the metric
    • Metadata

      public Metadata(String name, MetricType type, String unit)
      Constructs a Metadata object
      Parameters:
      name - The name of the metric
      type - The type of the metric
      unit - The units of the metric
    • Metadata

      public Metadata(String name, String displayName, String description, MetricType type, String unit)
      Constructs a Metadata object
      Parameters:
      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
    • 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 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
    • Metadata

      public 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
      Parameters:
      in - a map of key/value pairs representing Metadata
  • Method Details

    • getName

      public String getName()
      Returns the metric name.
      Returns:
      the metric name.
    • setName

      public void setName(String name)
      Sets the metric name.
      Parameters:
      name - the new metric name
    • getDisplayName

      public String getDisplayName()
      Returns the display name if set, otherwise this method returns the metric name.
      Returns:
      the display name
    • setDisplayName

      public void setDisplayName(String displayName)
      Sets the display name.
      Parameters:
      displayName - the new display name
    • getDescription

      public String getDescription()
      Returns the description of the metric.
      Returns:
      the description
    • setDescription

      public void setDescription(String description)
      Sets the description of the metric.
      Parameters:
      description - the new description
    • getType

      public String getType()
      Returns the String representation of the MetricType.
      Returns:
      the MetricType as a String
      See Also:
    • getTypeRaw

      public MetricType getTypeRaw()
      Returns the MetricType of the metric
      Returns:
      the MetricType
    • setType

      public void setType(String type) throws IllegalArgumentException
      Sets the metric type using a String representation of MetricType.
      Parameters:
      type - the new metric type
      Throws:
      IllegalArgumentException - if the String is not a valid MetricType
    • setType

      public void setType(MetricType type)
      Sets the type of the metric
      Parameters:
      type - the new metric type
    • getUnit

      public String getUnit()
      Returns the unit of the metric.
      Returns:
      the unit
    • setUnit

      public void setUnit(String unit)
      Sets the unit of the metric.
      Parameters:
      unit - the new unit
    • getTagsAsString

      public 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 HashMap<String,String> getTags()
      Returns the underlying HashMap containing the tags.
      Returns:
      a hashmap of tags
    • addTag

      public void addTag(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(String tagsString)
      Add multiple tags delimited by commas. The format must be in the form 'key1=value1, key2=value2'. This method will call addTag(String) on each tag.
      Parameters:
      tagsString - a string containing multiple tags
    • setTags

      public void setTags(HashMap<String,String> tags)
      Sets the tags hashmap.
      Parameters:
      tags - a hashmap containing tags.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object