Class 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 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 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 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
      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.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.
    • 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 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​(java.lang.String type)
      Sets the metric type using a String representation of MetricType.
      void setType​(MetricType type)
      Sets the type of the metric
      void setUnit​(java.lang.String unit)
      Sets the unit of the metric.
      java.lang.String toString​()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
    • 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 metric
        type - 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 metric
        type - The type of the metric
        unit - 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 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​(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 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​(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. 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 the MetricType.
        Returns:
        the MetricType as a String
        See Also:
        MetricType
      • setType

        public void setType​(java.lang.String type)
                     throws java.lang.IllegalArgumentException
        Sets the metric type using a String representation of MetricType.
        Parameters:
        type - the new metric type
        Throws:
        java.lang.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 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 call addTag(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 class java.lang.Object
      • toString

        public java.lang.String toString​()
        Overrides:
        toString in class java.lang.Object