You can call the QueryTimeseriesMeta operation to retrieve time series that meet multiple specified conditions.

Prerequisites

  • Time series data is written to the time series table. For more information, see Write time series data.
  • The TimeseriesClient is initialized. For more information, see Initialization.

Parameters

The metaQueryCondition parameter specifies the conditions for time series retrieval. The conditions include compositeMetaQueryCondition, measurementMetaQueryCondition, dataSourceMetaQueryCondition, tagMetaQueryCondition, attributeMetaQueryCondition, and updateTimeMetaQueryCondition. The following table describes the parameters.

Parameter Description
compositeMetaQueryCondition The composite condition, which includes the following content:
  • operator: the logical operator. Valid values: AND, OR, and NOT.
  • subConditions: a list of subconditions that can be combined by using operators for complex queries.
measurementMetaQueryCondition The metric name condition, which includes the following content:
  • operator: the relational operator or the prefix match condition. Valid values for the relational operator: =, !=, >, >=, <, and <=.
  • value: the metric name for a match query. Type: string.
dataSourceMetaQueryCondition The data source condition, which includes the following content:
  • operator: the relational operator or the prefix match condition. Valid values for the relational operator: =, !=, >, >=, <, and <=.
  • value: the data source for a match query. Type: string.
tagMetaQueryCondition The tag condition, which includes the following content:
  • operator: the relational operator or the prefix match condition. Valid values for the relational operator: =, !=, >, >=, <, and <=.
  • value: the value of the tag for a match query. Type: string.
attributeMetaQueryCondition The property condition for the metadata of the time series, which includes the following content:
  • operator: the relational operator or the prefix match condition. Valid values for the relational operator: =, !=, >, >=, <, and <=.
  • attributeName: the name of the property. Type: string.
  • value: the value of the property. Type: string.
updateTimeMetaQueryCondition The update time condition for the metadata of the time series, which includes the following content:
  • operator: the relational operator. Valid values: =, !=, >, >=, <, and <=.
  • timeInUs: the timestamp of the time when the time series metadata is updated. Unit: microseconds.

Example

Query all time series in which the metric name is cpu and the tags contain the os tag that is prefixed with Ubuntu in a time series table named test_timeseries_table.

private static void queryTimeseriesMeta(TimeseriesClient client) {
    String tableName = "test_timeseries_table";
    QueryTimeseriesMetaRequest queryTimeseriesMetaRequest = new QueryTimeseriesMetaRequest(tableName);
    // Query the time series in which the metric name is cpu and the tags contains the os tag that is prefixed with Ubuntu. Example: measurement_name="cpu" and have_prefix(os, "Ubuntu").
    CompositeMetaQueryCondition compositeMetaQueryCondition = new CompositeMetaQueryCondition(MetaQueryCompositeOperator.OP_AND);
    compositeMetaQueryCondition.addSubCondition(new MeasurementMetaQueryCondition(MetaQuerySingleOperator.OP_EQUAL, "cpu"));
    compositeMetaQueryCondition.addSubCondition(new TagMetaQueryCondition(MetaQuerySingleOperator.OP_PREFIX, "os", "Ubuntu"));
    queryTimeseriesMetaRequest.setCondition(compositeMetaQueryCondition);
    queryTimeseriesMetaRequest.setGetTotalHits(true);
    QueryTimeseriesMetaResponse queryTimeseriesMetaResponse = client.queryTimeseriesMeta(queryTimeseriesMetaRequest);
    System.out.println(queryTimeseriesMetaResponse.getTotalHits());
    for (TimeseriesMeta timeseriesMeta : queryTimeseriesMetaResponse.getTimeseriesMetas()) {
        System.out.println(timeseriesMeta.getTimeseriesKey().getMeasurementName());
        System.out.println(timeseriesMeta.getTimeseriesKey().getDataSource());
        System.out.println(timeseriesMeta.getTimeseriesKey().getTags());
        System.out.println(timeseriesMeta.getAttributes());
        System.out.println(timeseriesMeta.getUpdateTimeInUs());
    }
}