If you want to query the information about time series, such as the metric name and data source, or you want to list time series that meet specified conditions, you can call the QueryTimeseriesMeta operation. This operation allows you to query time series by specific conditions such as metric name, data source, tag, attribute, and update time.
Prerequisites
Time series data is written to the time series table. For more information, see Write time series data.
A TimeseriesClient instance is initialized. For more information, see Initialize an OTSClient instance.
Parameters
The metaQueryCondition parameter specifies the conditions for a time series retrieval. The conditions include compositeMetaQueryCondition, measurementMetaQueryCondition, dataSourceMetaQueryCondition, tagMetaQueryCondition, attributeMetaQueryCondition, and updateTimeMetaQueryCondition. The following table describes the parameters.
Parameter | Required | Description |
compositeMetaQueryCondition | No | The composite condition, which includes the following content:
|
measurementMetaQueryCondition | Yes. You must specify one of the parameters. | The metric name condition, which includes the following content:
|
dataSourceMetaQueryCondition | The data source condition, which includes the following content:
| |
tagMetaQueryCondition | The tag condition, which includes the following content:
| |
attributeMetaQueryCondition | The attribute condition for the metadata of the time series. The attribute condition includes the following content:
| |
updateTimeMetaQueryCondition | The update time condition for the metadata of the time series. The update time condition includes the following content:
|
Examples
The following sample code provides an example on how to query the metric name, data source, and tags of the time series based on the specified condition. The specified condition can be a composite condition.
func QueryTimeseriesMetaSample(client *tablestore.TimeseriesClient , timeseriesTableName string) {
fmt.Println("[Info]: Begin to query timeseries table meta!")
// Construct multiple query conditions.
measurementMetaQueryCondition := tablestore.NewMeasurementQueryCondition(tablestore.OP_GREATER_EQUAL , "")
datasourceMetaQueryCondition := tablestore.NewDataSourceMetaQueryCondition(tablestore.OP_GREATER_EQUAL , "")
tagMetaQueryCondition := tablestore.NewTagMetaQueryCondition(tablestore.OP_GREATER_THAN , "City" , "")
// Construct a composite condition.
compsiteMetaQueryCondition := tablestore.NewCompositeMetaQueryCondition(tablestore.OP_AND)
compsiteMetaQueryCondition.AddSubConditions(measurementMetaQueryCondition)
compsiteMetaQueryCondition.AddSubConditions(datasourceMetaQueryCondition)
compsiteMetaQueryCondition.AddSubConditions(tagMetaQueryCondition)
// Construct the query request.
queryTimeseriesMetaRequest := tablestore.NewQueryTimeseriesMetaRequest(timeseriesTableName)
queryTimeseriesMetaRequest.SetCondition(compsiteMetaQueryCondition)
queryTimeseriesMetaRequest.SetLimit(-1)
// Call the time series client-related operation to execute the query request.
queryTimeseriesTableResponse , err := client.QueryTimeseriesMeta(queryTimeseriesMetaRequest)
if err != nil {
fmt.Println("[Error]: Query timeseries table meta failed with error: " , err)
return
}
fmt.Println("[Info]: Query timeseries table meta succeed: ")
for i := 0; i < len(queryTimeseriesTableResponse.GetTimeseriesMetas()); i++ {
curTimeseriesMeta := queryTimeseriesTableResponse.GetTimeseriesMetas()[i]
fmt.Println("[Info]: Meta_" , i , ": " , "Measurement: " , curTimeseriesMeta.GetTimeseriesKey().GetMeasurementName() ,
"Source: " , curTimeseriesMeta.GetTimeseriesKey().GetDataSource() ,
"Tags: " , curTimeseriesMeta.GetTimeseriesKey().GetTags(),
"Attrs: " , curTimeseriesMeta.GetAttributeSlice())
}
fmt.Println("[Info]: QueryTimeseriesMetaSample finished !")
}
FAQ
References
For more information about the API operation, see QueryTimeseriesMeta.
If the attributes in the metadata of a time series do not meet your business requirements, you can update or delete time series metadata. For more information, see Update time series metadata and Delete time series metadata.
After you retrieve the required time series, you can query time series data based on the time series. For more information, see Query time series data.