Class OpenTsdbMetricStreamDefinition
- java.lang.Object
-
- com.elastisys.autoscaler.metricstreamers.opentsdb.config.OpenTsdbMetricStreamDefinition
-
public class OpenTsdbMetricStreamDefinition extends java.lang.ObjectRepresents a metric stream definition for aOpenTsdbMetricStreamer. For more details on the meaning of the different parameters, refer to the OpenTSDB HTTP API specification, metrics and tags and OpenTSDB query exeution.
-
-
Field Summary
Fields Modifier and Type Field Description static com.elastisys.scale.commons.json.types.TimeIntervalDEFAULT_QUERY_CHUNK_SIZEDefault value forqueryChunkSize.static java.lang.BooleanDEFAULT_RATE_CONVERSIONDefault forconvertToRate.static java.util.regex.PatternVALID_OPENTSDB_IDENTIFIERRegular expression describing a valid OpenTSDB metric/tag-key/tag-value identifier.
-
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)Constructs a newOpenTsdbMetricStreamDefinition.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.joda.time.IntervaladjustForDataSettlingTime(org.joda.time.Interval queryInterval)Adjusts a query time interval to not include data points more recent than thedataSettlingTimeconfigured for the metric stream.booleanequals(java.lang.Object obj)MetricAggregatorgetAggregator()Returns the aggregation function used to aggregateMetricValues in the metric stream.org.joda.time.DateTimegetDataSettlingPoint()Returns the current point in time before which data points can be regarded as "settled" (according to thedataSettlingTimeof the stream), and that hence are considered to be safe to query without risking to see incomplete data.com.elastisys.scale.commons.json.types.TimeIntervalgetDataSettlingTime()Returns the minimum age of requested data points.DownsamplingSpecificationgetDownsampling()Returns the down-sampling to apply toMetricValues in the metric stream.java.lang.StringgetId()Returns the id of the metric stream.java.lang.StringgetMetric()Returns the OpenTSDB metric that the metric stream retrievesMetricValues for.java.lang.StringgetQuery()Builds an OpenTSDB query string from thisOpenTsdbMetricStreamDefinition, or throws an exception in case this fails.com.elastisys.scale.commons.json.types.TimeIntervalgetQueryChunkSize()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 theMetricValues returned from the metric stream.inthashCode()booleanisConvertToRate()Returnstrueif the stream will feed the change rate of the metric, rather than the absolute values of the metric.java.lang.StringmakeQuery(org.joda.time.Interval interval)Builds a time-bounded OpenTSDB query string from a time interval and thisOpenTsdbMetricStreamDefinition, or throws an exception in case this fails.java.lang.StringtoString()voidvalidate()Validates that thisOpenTsdbMetricStreamDefinitioncontains sufficient information to allow a valid OpenTSDB query to be built.OpenTsdbMetricStreamDefinitionwithConverToRate(boolean convertToRate)Creates a field-by-field copy of this object but sets a different rate conversion in the returned copy.OpenTsdbMetricStreamDefinitionwithDownsampling(DownsamplingSpecification downsampling)Creates a field-by-field copy of this object but sets a different downsampling in the returned copy.OpenTsdbMetricStreamDefinitionwithTags(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.
-
-
-
Field Detail
-
DEFAULT_QUERY_CHUNK_SIZE
public static final com.elastisys.scale.commons.json.types.TimeInterval DEFAULT_QUERY_CHUNK_SIZE
Default value forqueryChunkSize.
-
DEFAULT_RATE_CONVERSION
public static final java.lang.Boolean DEFAULT_RATE_CONVERSION
Default forconvertToRate.
-
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)Constructs a newOpenTsdbMetricStreamDefinition.- Parameters:
id- The id of the metric stream. This is the id that will be used by clients wishing to subscribe toMetricValues for this metric stream. Required.metric- The OpenTSDB metric that the metric stream retrievesMetricValues for. Required.aggregator- The aggregation function used to aggregateMetricValues in the metric stream. Required.convertToRate- Whentruethe 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 toMetricValues in the metric stream. May benull.tags- The collection of tags used to filter theMetricValues returned from the metric stream. May benull.dataSettlingTime- The minimum age (in seconds) of requested data points. TheMetricStreamerwill 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 about1.5times the length of the reporting-interval for monitoring agents. Ifnull, 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 largeQueryResultSets limits the amount of (memory) resources involved in processing large queries. May benull. 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 toMetricValues for this metric stream.- Returns:
-
getMetric
public java.lang.String getMetric()
Returns the OpenTSDB metric that the metric stream retrievesMetricValues for.- Returns:
-
getAggregator
public MetricAggregator getAggregator()
Returns the aggregation function used to aggregateMetricValues in the metric stream.- Returns:
-
isConvertToRate
public boolean isConvertToRate()
Returnstrueif 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 toMetricValues 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 theMetricValues returned from the metric stream.- Returns:
-
getDataSettlingTime
public com.elastisys.scale.commons.json.types.TimeInterval getDataSettlingTime()
Returns the minimum age of requested data points. TheMetricStreamerwill 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 about1.5times 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 largeQueryResultSets limits the amount of (memory) resources involved in processing large queries.- Returns:
-
getQuery
public java.lang.String getQuery() throws java.lang.RuntimeExceptionBuilds an OpenTSDB query string from thisOpenTsdbMetricStreamDefinition, 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.IllegalArgumentExceptionBuilds a time-bounded OpenTSDB query string from a time interval and thisOpenTsdbMetricStreamDefinition, 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 thedataSettlingTimeof 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.IllegalArgumentExceptionAdjusts a query time interval to not include data points more recent than thedataSettlingTimeconfigured for the metric stream. Should theIntervalbe too recent (its start time being later than the data settling time), the query is disallowed and anIllegalArgumentExceptionis 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.IllegalArgumentExceptionValidates that thisOpenTsdbMetricStreamDefinitioncontains 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, aIllegalArgumentExceptionis thrown.- Throws:
java.lang.IllegalArgumentException
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
withDownsampling
public OpenTsdbMetricStreamDefinition withDownsampling(DownsamplingSpecification downsampling)
Creates a field-by-field copy of this object but sets a different downsampling in the returned copy.- Parameters:
function-- Returns:
-
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:
-
-