Class OpenTsdbMetricStreamDefinition

    • Constructor Summary

      Constructors 
      Constructor Description
      OpenTsdbMetricStreamDefinition​(java.lang.String id, java.lang.String metric, MetricAggregator aggregator, java.lang.Boolean convertToRate, DownsamplingSpecification downsampling, java.util.Map<java.lang.String,​java.util.List<java.lang.String>> tags, com.elastisys.scale.commons.json.types.TimeInterval dataSettlingTime, com.elastisys.scale.commons.json.types.TimeInterval queryChunkSize)
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.joda.time.Interval adjustForDataSettlingTime​(org.joda.time.Interval queryInterval)
      Adjusts a query time interval to not include data points more recent than the dataSettlingTime configured for the metric stream.
      boolean equals​(java.lang.Object obj)  
      MetricAggregator getAggregator()
      Returns the aggregation function used to aggregate MetricValues in the metric stream.
      org.joda.time.DateTime getDataSettlingPoint()
      Returns the current point in time before which data points can be regarded as "settled" (according to the dataSettlingTime of the stream), and that hence are considered to be safe to query without risking to see incomplete data.
      com.elastisys.scale.commons.json.types.TimeInterval getDataSettlingTime()
      Returns the minimum age of requested data points.
      DownsamplingSpecification getDownsampling()
      Returns the down-sampling to apply to MetricValues in the metric stream.
      java.lang.String getId()
      Returns the id of the metric stream.
      java.lang.String getMetric()
      Returns the OpenTSDB metric that the metric stream retrieves MetricValues for.
      java.lang.String getQuery()
      Builds an OpenTSDB query string from this OpenTsdbMetricStreamDefinition, or throws an exception in case this fails.
      com.elastisys.scale.commons.json.types.TimeInterval getQueryChunkSize()
      The maximum time period that a single query against the OpenTSDB server will attempt to fetch in a single call.
      java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getTags()
      Returns the collection of tags used to filter the MetricValues returned from the metric stream.
      int hashCode()  
      boolean isConvertToRate()
      Returns true if the stream will feed the change rate of the metric, rather than the absolute values of the metric.
      java.lang.String makeQuery​(org.joda.time.Interval interval)
      Builds a time-bounded OpenTSDB query string from a time interval and this OpenTsdbMetricStreamDefinition, or throws an exception in case this fails.
      java.lang.String toString()  
      void validate()
      Validates that this OpenTsdbMetricStreamDefinition contains sufficient information to allow a valid OpenTSDB query to be built.
      OpenTsdbMetricStreamDefinition withConverToRate​(boolean convertToRate)
      Creates a field-by-field copy of this object but sets a different rate conversion in the returned copy.
      OpenTsdbMetricStreamDefinition withDownsampling​(DownsamplingSpecification downsampling)
      Creates a field-by-field copy of this object but sets a different downsampling in the returned copy.
      OpenTsdbMetricStreamDefinition withTags​(java.util.Map<java.lang.String,​java.util.List<java.lang.String>> tags)
      Creates a field-by-field copy of this object but sets a different tags in the returned copy.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • DEFAULT_QUERY_CHUNK_SIZE

        public static final com.elastisys.scale.commons.json.types.TimeInterval DEFAULT_QUERY_CHUNK_SIZE
        Default value for queryChunkSize.
      • DEFAULT_RATE_CONVERSION

        public static final java.lang.Boolean DEFAULT_RATE_CONVERSION
        Default for convertToRate.
      • VALID_OPENTSDB_IDENTIFIER

        public static final java.util.regex.Pattern VALID_OPENTSDB_IDENTIFIER
        Regular expression describing a valid OpenTSDB metric/tag-key/tag-value identifier.
    • Constructor Detail

      • OpenTsdbMetricStreamDefinition

        public OpenTsdbMetricStreamDefinition​(java.lang.String id,
                                              java.lang.String metric,
                                              MetricAggregator aggregator,
                                              java.lang.Boolean convertToRate,
                                              DownsamplingSpecification downsampling,
                                              java.util.Map<java.lang.String,​java.util.List<java.lang.String>> tags,
                                              com.elastisys.scale.commons.json.types.TimeInterval dataSettlingTime,
                                              com.elastisys.scale.commons.json.types.TimeInterval queryChunkSize)
        Parameters:
        id - The id of the metric stream. This is the id that will be used by clients wishing to subscribe to MetricValues for this metric stream. Required.
        metric - The OpenTSDB metric that the metric stream retrieves MetricValues for. Required.
        aggregator - The aggregation function used to aggregate MetricValue s in the metric stream. Required.
        convertToRate - When true the stream will feed the change rate of the metric, rather than the absolute values of the metric. Optional. Default: DEFAULT_RATE_CONVERSION.
        downsampling - The down-sampling to apply to MetricValues in the metric stream. May be null.
        tags - The collection of tags used to filter the MetricValues returned from the metric stream. May be null.
        dataSettlingTime - The minimum age (in seconds) of requested data points. The MetricStreamer will never request values newer than this from OpenTSDB. This value can be regarded as the expected "settling time" of new data points.

        When requesting recent aggregate metric data points, there is always a risk of seeing partial/incomplete results before metric values from all instances have been registered. Typically, it takes a couple of minutes for all instances to report their values to CloudWatch.

        The value to set for this field depends on the reporting frequency of monitoring agents, but as a general rule-of-thumb, this value can be set to be about 1.5 times the length of the reporting-interval for monitoring agents.

        If null, a settling time of zero is assumed.

        queryChunkSize - The maximum time period that a single query against the OpenTSDB server will attempt to fetch in a single call. A query with a longer time interval will be run incrementally, each fetching a sub-interval of this duration. This type of incremental retrieval of large QueryResultSets limits the amount of (memory) resources involved in processing large queries. May be null. Default: .
    • Method Detail

      • getId

        public java.lang.String getId()
        Returns the id of the metric stream. This is the id that will be used by clients wishing to subscribe to MetricValues for this metric stream.
        Returns:
      • getMetric

        public java.lang.String getMetric()
        Returns the OpenTSDB metric that the metric stream retrieves MetricValues for.
        Returns:
      • getAggregator

        public MetricAggregator getAggregator()
        Returns the aggregation function used to aggregate MetricValues in the metric stream.
        Returns:
      • isConvertToRate

        public boolean isConvertToRate()
        Returns true if the stream will feed the change rate of the metric, rather than the absolute values of the metric.
        Returns:
      • getDownsampling

        public DownsamplingSpecification getDownsampling()
        Returns the down-sampling to apply to MetricValues in the metric stream.
        Returns:
      • getTags

        public java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getTags()
        Returns the collection of tags used to filter the MetricValues returned from the metric stream.
        Returns:
      • getDataSettlingTime

        public com.elastisys.scale.commons.json.types.TimeInterval getDataSettlingTime()
        Returns the minimum age of requested data points. The MetricStreamer will never request values newer than this from OpenTSDB. This value can be regarded as the expected "settling time" of new data points.

        When requesting recent aggregate metric data points, there is always a risk of seeing partial/incomplete results before metric values from all instances have been registered. Typically, it takes a couple of minutes for all instances to report their values to CloudWatch.

        The value to set for this field depends on the reporting frequency of monitoring agents, but as a general rule-of-thumb, this value can be set to be about 1.5 times the length of the reporting-interval for monitoring agents.

        Returns:
      • getQueryChunkSize

        public com.elastisys.scale.commons.json.types.TimeInterval getQueryChunkSize()
        The maximum time period that a single query against the OpenTSDB server will attempt to fetch in a single call. A query with a longer time interval will be run incrementally, each fetching a sub-interval of this duration. This type of incremental retrieval of large QueryResultSets limits the amount of (memory) resources involved in processing large queries.
        Returns:
      • getQuery

        public java.lang.String getQuery()
                                  throws java.lang.RuntimeException
        Builds an OpenTSDB query string from this OpenTsdbMetricStreamDefinition, or throws an exception in case this fails. The created query will not be bounded by a certain time interval.
        Returns:
        The query string. Note that the returned query is not a complete URL. More specifically, it does not include the host/port-part of a full URL.
        Throws:
        java.lang.RuntimeException - if a OpenTSDB query could not be built (for example, due to missing required fields).
      • makeQuery

        public java.lang.String makeQuery​(org.joda.time.Interval interval)
                                   throws java.lang.RuntimeException,
                                          java.lang.IllegalArgumentException
        Builds a time-bounded OpenTSDB query string from a time interval and this OpenTsdbMetricStreamDefinition, or throws an exception in case this fails.
        Parameters:
        interval - The time interval used to restrict the query.
        Returns:
        The query string. Note that the returned query is not a complete URL. More specifically, it does not include the host/port-part of a full URL.
        Throws:
        java.lang.RuntimeException - if a OpenTSDB query could not be built (for example, due to missing required fields).
        java.lang.IllegalArgumentException - If an illegal query interval was specified (for example, the start of the query interval is later than the data settling time).
      • getDataSettlingPoint

        public org.joda.time.DateTime getDataSettlingPoint()
        Returns the current point in time before which data points can be regarded as "settled" (according to the dataSettlingTime of the stream), and that hence are considered to be safe to query without risking to see incomplete data.

        Queries should not ask for more recent data points than this.

        Returns:
      • adjustForDataSettlingTime

        public org.joda.time.Interval adjustForDataSettlingTime​(org.joda.time.Interval queryInterval)
                                                         throws java.lang.IllegalArgumentException
        Adjusts a query time interval to not include data points more recent than the dataSettlingTime configured for the metric stream.

        Should the Interval be too recent (its start time being later than the data settling time), the query is disallowed and an IllegalArgumentException is thrown.

        Parameters:
        queryInterval - A query time interval.
        Returns:
        The adjusted query interval (with an end time earlier than dataSettlingTime).
        Throws:
        java.lang.IllegalArgumentException - If the start of the query interval is later than the data settling time.
      • validate

        public void validate()
                      throws java.lang.IllegalArgumentException
        Validates that this OpenTsdbMetricStreamDefinition contains sufficient information to allow a valid OpenTSDB query to be built. If it does, the method will just return. If it is found to be invalid, a IllegalArgumentException is thrown.
        Throws:
        java.lang.IllegalArgumentException
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

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

        public OpenTsdbMetricStreamDefinition withConverToRate​(boolean convertToRate)
        Creates a field-by-field copy of this object but sets a different rate conversion in the returned copy.
        Parameters:
        convertToRate -
        Returns:
      • withTags

        public OpenTsdbMetricStreamDefinition withTags​(java.util.Map<java.lang.String,​java.util.List<java.lang.String>> tags)
        Creates a field-by-field copy of this object but sets a different tags in the returned copy.
        Parameters:
        tags -
        Returns: