Class Query
- java.lang.Object
-
- com.elastisys.autoscaler.metricstreamers.influxdb.config.Query
-
public class Query extends java.lang.ObjectRepresents an InfluxDBSELECTquery to be periodically executed by theInfluxdbMetricStreamerto fetch new metrics values. A query should avoid filtering ontimein theWHEREclause, as selecting the approriate interval for which to fetch metrics will be handled by theInfluxdbMetricStreamer. The author ofInfluxdbMetricStreamerqueries need to be aware of the following:- Only select a single field/column in the
SELECTstatement. Any additional fields are ignored in the result processing. - The selected field/column must be a numeric value. If not, errors will be raised during result processing.
- Semi-colons are disallowed. This protects against injecting additional modifying queries/statements.
- It is entirely possible to put together queries that don't make sense. These won't be caught until runtime (when an attmept is made to execute the query against InfluxDB).
- See Also:
MetricStreamDefinition
- Only select a single field/column in the
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classQuery.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Query.Builderbuilder()booleanequals(java.lang.Object obj)java.lang.StringgetFrom()FROMclause.java.lang.StringgetGroupBy()GROUP BYclause.java.lang.StringgetSelect()SELECTclause.java.lang.StringgetWhere()WHEREclause.inthashCode()Queryvalidate()* Checks the validity of field values.QuerywithGroupBy(java.lang.String groupBy)Creates a field-by-field copy of thisQuerywith the groupBy clause replaced in the returned copy.
-
-
-
Constructor Detail
-
Query
public Query(java.lang.String select, java.lang.String from, java.lang.String where, java.lang.String groupBy)Creates aQuery.- Parameters:
select-SELECTclause. For example,mean('request_rate')ornon_negative_derivative(max('value'), 1s). The select statement should select one single field/column (only the first field is handled in result processing). The selected field/column must be a numeric value. If not, errors will be raised during result processing. Surround identifiers with double quotes to support a richer character set for identifiers.from-FROMclause. Specifies the measurement to query for. For example,cpu/system. Surround identifiers with double quotes to support a richer character set for identifiers.where-WHEREclause. Used to filter data based on tags/field values. Avoid filtering ontimein theWHEREclause, as selecting the approriate interval for which to fetch metrics will be handled by theInfluxdbMetricStreamer. Behavior is undefined iftimefilters are inclued. Surround identifiers with double quotes to support a richer character set for identifiers.groupBy-GROUP BYclause. Can be used to downsample data (if combined with an aggregation function in theSELECTclause), for example by specifying something liketime(10s) fill(none). Note: do not group on tags, since that will create different series in the result (one per group) and the result handler will only process the first series (the order may not be deterministic). Use aWHEREclause to query for a particular combination of tags.
-
-
Method Detail
-
getSelect
public java.lang.String getSelect()
SELECTclause. For example,mean('request_rate')ornon_negative_derivative(max('value'), 1s). The select statement should select one single field/column (only the first field is handled in result processing). The selected field/column must be a numeric value. If not, errors will be raised during result processing.- Returns:
-
getFrom
public java.lang.String getFrom()
FROMclause. Specifies the measurement to query for. For example,cpu/system.- Returns:
-
getWhere
public java.lang.String getWhere()
WHEREclause. Used to filter data based on tags/field values. Avoid filtering ontimein theWHEREclause, as selecting the approriate interval for which to fetch metrics will be handled by theInfluxdbMetricStreamer. Behavior is undefined iftimefilters are inclued.- Returns:
-
getGroupBy
public java.lang.String getGroupBy()
GROUP BYclause. Can be used to downsample data (if combined with an aggregation function in theSELECTclause), for example by specifying something liketime(10s) fill(none). Note: do not group on tags, since that will create different series in the result (one per group) and the result handler will only process the first series (the order may not be deterministic). Use aWHEREclause to query for a particular combination of tags.- Returns:
-
withGroupBy
public Query withGroupBy(java.lang.String groupBy)
Creates a field-by-field copy of thisQuerywith the groupBy clause replaced in the returned copy.- Parameters:
groupBy-- Returns:
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
validate
public Query validate() throws java.lang.IllegalArgumentException
* Checks the validity of field values. Throws anIllegalArgumentExceptionif necessary conditions are not satisfied.- Returns:
- Throws:
java.lang.IllegalArgumentException
-
builder
public static Query.Builder builder()
-
-