Class Metric


  • public class Metric
    extends Object
    A metric contains measurements or data points. Each data point has a time stamp of when the measurement occurred and a value that is either a long or double and optionally contains tags. Tags are labels that can be added to better identify the metric. For example, if the measurement was done on server1 then you might add a tag named "host" with a value of "server1". Note that a metric must have at least one tag.
    • Constructor Detail

      • Metric

        protected Metric​(String name)
      • Metric

        protected Metric​(String name,
                         String registeredType)
    • Method Detail

      • addTag

        public Metric addTag​(String name,
                             String value)
        Adds a tag to the data point.
        Parameters:
        name - tag identifier
        value - tag value
        Returns:
        the metric the tag was added to
      • addTags

        public Metric addTags​(Map<String,​String> tags)
        Adds tags to the data point.
        Parameters:
        tags - map of tags
        Returns:
        the metric the tags were added to
      • addDataPoint

        public Metric addDataPoint​(long timestamp,
                                   long value)
        Adds the data point to the metric.
        Parameters:
        timestamp - when the measurement occurred
        value - the measurement value
        Returns:
        the metric
      • addDataPoint

        public Metric addDataPoint​(long value)
        Adds the data point to the metric with a timestamp of now.
        Parameters:
        value - the measurement value
        Returns:
        the metric
      • addDataPoint

        public Metric addDataPoint​(long timestamp,
                                   Object value)
      • addDataPoint

        public Metric addDataPoint​(long timestamp,
                                   double value)
        Adds the data point to the metric.
        Parameters:
        timestamp - when the measurement occurred
        value - the measurement value
        Returns:
        the metric
      • addDataPoint

        public Metric addDataPoint​(double value)
        Adds the data point to the metric with a timestamp of now.
        Parameters:
        value - the measurement value
        Returns:
        the metric
      • addTtl

        public Metric addTtl​(int ttl)
        Adds a time-to-live for this metric specified in seconds. TTL is off by default. Setting ttl to 0 turns it off.
        Parameters:
        ttl - number of seconds that the metric will live
        Returns:
        the metric
      • getTtl

        public int getTtl()
        Returns the time-to-live. If zero, the metric lives forever.
        Returns:
        time to live
      • getName

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

        public Map<String,​String> getTags()
        Returns the tags associated with the data point.
        Returns:
        tag for the data point
      • getType

        public String getType()
        Returns the custom type name. Null if the type is a number.
        Returns:
        custom type name
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object