Class OpenTsdbQueryBuilder
- java.lang.Object
-
- com.elastisys.autoscaler.metricstreamers.opentsdb.query.OpenTsdbQueryBuilder
-
public class OpenTsdbQueryBuilder extends java.lang.ObjectAn OpenTSDB query builder that uses the builder pattern to construct a query string that can be submitted to a OpenTSDB server endpoint. Note that the returned query is not a complete URL. More specifically, it does not include the host/port-part of a full URL. A returned query string may, for instance, look as follows:/q?&m=sum:proc.stat.cpu&ascii&nocache
The client needs to turn the query string into a full URL by adding protocol, host, and a port. TheOpenTsdbQueryBuildersupports all functionality offered by the OpenTSDB HTTP API specification. Read about metrics and tags and OpenTSDB query exeution to learn more about OpenTSDB's operation.
-
-
Constructor Summary
Constructors Constructor Description OpenTsdbQueryBuilder()Constructs a newOpenTsdbQueryBuilder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Stringbuild()Builds the query string that has been constructed with theOpenTsdbQueryBuilder's methods.OpenTsdbQueryBuilderwithAggregator(MetricAggregator aggregator)Sets theMetricAggregatorfunction used to aggregate values from different time-series of the metric for the query being built.OpenTsdbQueryBuilderwithDownsamplingSpecification(DownsamplingSpecification downsamplingSpecification)Adds a down-sampling specification to the query being built.OpenTsdbQueryBuilderwithInterval(org.joda.time.Interval interval)Sets the interval of interest, limiting the built query to include onlyMetricValues reported within the specified points in time.OpenTsdbQueryBuilderwithMetric(java.lang.String metric)Sets the metric for the query being built.OpenTsdbQueryBuilderwithRateConversion(boolean convertToRate)Adds a flag indicating whether returned metric values are to be converted to rate.OpenTsdbQueryBuilderwithTags(java.util.Map<java.lang.String,java.util.List<java.lang.String>> tags)Adds a collection of filter tags to the query being built.
-
-
-
Constructor Detail
-
OpenTsdbQueryBuilder
public OpenTsdbQueryBuilder()
Constructs a newOpenTsdbQueryBuilder.
-
-
Method Detail
-
withMetric
public OpenTsdbQueryBuilder withMetric(java.lang.String metric)
Sets the metric for the query being built.- Parameters:
metric- The metric for which to retrieve values.- Returns:
- The builder itself, enabling chaining of build instructions.
-
withAggregator
public OpenTsdbQueryBuilder withAggregator(MetricAggregator aggregator)
Sets theMetricAggregatorfunction used to aggregate values from different time-series of the metric for the query being built.- Parameters:
aggregator- The aggregation function to use for aggregating values.- Returns:
- The builder itself, enabling chaining of build instructions.
-
withDownsamplingSpecification
public OpenTsdbQueryBuilder withDownsamplingSpecification(DownsamplingSpecification downsamplingSpecification)
Adds a down-sampling specification to the query being built.- Parameters:
downsamplingSpecification- The down-sampling specification to add.- Returns:
- The builder itself, enabling chaining of build instructions.
-
withRateConversion
public OpenTsdbQueryBuilder withRateConversion(boolean convertToRate)
Adds a flag indicating whether returned metric values are to be converted to rate. Whentrue, the built query will ask for the change rate of the metric, rather than the absolute values of the metric.- Parameters:
convertToRate- A boolean flag that whentruecauses the built query to ask for the change rate of the metric, rather than the absolute values of the metric.- Returns:
- The builder itself, enabling chaining of build instructions.
-
withInterval
public OpenTsdbQueryBuilder withInterval(org.joda.time.Interval interval)
Sets the interval of interest, limiting the built query to include onlyMetricValues reported within the specified points in time.- Parameters:
interval- The interval of interest.- Returns:
- The builder itself, enabling chaining of build instructions.
-
withTags
public OpenTsdbQueryBuilder withTags(java.util.Map<java.lang.String,java.util.List<java.lang.String>> tags)
Adds a collection of filter tags to the query being built. Tags can, for example, be used to filter query results specifying that onlyMetricValues with a given tag be returned or to specify thatMetricValues are to be returned on a per-host basis rather than in aggregated form. Read about OpenTSDB query exeution for more details on how to use filter tags. As an example, ifMetricValues are tagged with ahosttag, ahostfilter tag can be set to the list of hosts for which to returnMetricValues. It is also possible to use a wild-card (*) as value for a given tag, which causes the OpenTSDB system to report all metrics that have the given tag, regardless of value.- Parameters:
tags- A mapping between tag keys and the list of requested values for each tag key.- Returns:
- The builder itself, enabling chaining of build instructions.
-
build
public java.lang.String build() throws java.lang.RuntimeExceptionBuilds the query string that has been constructed with theOpenTsdbQueryBuilder's methods. The returned query can be sent (by HTTP GET) to a OpenTSDB server.- Returns:
- The query string produced by the builder. Note that the returned query is not a complete URL. More specifically, it does not include the host/port-part of a full URL. The client needs to turn the query string into a full URL by adding protocol, host, and a port.
- Throws:
java.lang.RuntimeException- If the query could not be built.
-
-