Class QueryMetric


  • public class QueryMetric
    extends Object
    Query request for a metric. If a metric is queried by name only then all data points for all tags are returned. You can narrow down the query by adding tags so only data points associated with those tags are returned.

    Aggregators may be added to the metric. An aggregator performs an operation on the data such as summing or averaging. If multiple aggregators are added, the output of the first is sent to the input of the next, and so forth until all aggregators have been processed, These are processed in the order they were added.



    The results of the query can be grouped in various ways using a grouper. For example, if you had a metric with a customer tag, the resulting data points could be grouped by the different customers. Multiple groupers can be used so you could, for example, group by tag and value.

    Note that aggregation is very fast but grouping can slow down the query.
    • Constructor Detail

      • QueryMetric

        public QueryMetric​(String name)
    • Method Detail

      • addMultiValuedTags

        public QueryMetric addMultiValuedTags​(Map<String,​List<String>> tags)
        Add a map of tags.
        Parameters:
        tags - tags to add
        Returns:
        the metric
      • addTags

        public QueryMetric addTags​(Map<String,​String> tags)
        Add a map of tags. This narrows the query to only show data points associated with the tags' values.
        Parameters:
        tags - tags to add
        Returns:
        the metric
      • addTag

        public QueryMetric addTag​(String name,
                                  String... values)
        Adds a tag with multiple values. This narrows the query to only show data points associated with the tag's values.
        Parameters:
        name - tag name
        values - tag values
        Returns:
        the metric
      • addAggregator

        public QueryMetric addAggregator​(Aggregator aggregator)
        Adds an aggregator to the metric.
        Parameters:
        aggregator - aggregator to add
        Returns:
        the metric
      • addGrouper

        public QueryMetric addGrouper​(Grouper grouper)
        Add a grouper to the metric.
        Parameters:
        grouper - grouper to add
        Returns:
        the metric
      • setLimit

        public void setLimit​(int limit)
        Limits the number of data point returned from the query. The limit is done before aggregators are executed.
        Parameters:
        limit - maximum number of data points to return
      • setOrder

        public void setOrder​(QueryMetric.Order order)
        Orders the data points. The server default is ascending.
        Parameters:
        order - how data points are sorted
      • getName

        public String getName()
      • getTags

        public com.google.common.collect.ListMultimap<String,​String> getTags()
      • getLimit

        public Integer getLimit()
      • isExcludeTags

        public boolean isExcludeTags()
      • setExcludeTags

        public void setExcludeTags​(boolean exclude)
        If true removes tags from the query response. The default is to include tags.
        Parameters:
        exclude - exclude tags
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object