1,背景
时序数据库在使用上,随着使用周期的增长,时间线也会随之增加,当达到阀值后,需要进行时间线的删除。
2,时间线
时间线(TSUID),对每一个Data Point,metrics、timestamp、tagKey和tagValue都是必要的构成元素。除timestamp外,metrics、tagKey和tagValue的UID就可组成一个TSUID,每一个TSUID关联一个时间序列,如下所示:
<metrics_UID><tagKey1_UID><tagValue1_UID>[…<tagKeyN_UID><tagValueN_UID>]
UID的全称为Unique Identifier,这些UID被保存在OpenTSDB的元数据表中,默认是“tsdb-uid”,可以配置。
UID在设计和分配上遵循部分规则:Metric、TagKey、TagValue的UID都是独立分配,且唯一;UID的范围是0x000000到0xFFFFFF。
3,查询时间线
列举一种查询时间线的方法,步骤如下:
1),使用/api/suggest接口,查询所有Metric
/api/suggest?type=metrics
==>
[
"com.test.metric0","com.test.metric1","com.test.metric10","com.test.metric11",
"com.test.metric2","com.test.metric3","com.test.metric4","com.test.metric5",
"com.test.metric6","com.test.metric7","com.test.metric8","com.test.metric9"
]
2),使用/api/search/lookup接口,查询Metric包含的TagKey-TagValue对,以及TSUID
/api/search/lookup?m=com.test.metric8&limit=3
==>
{"type":"LOOKUP","metric":"com.test.metric8","tags":[],"limit":3,"time":30.0,
"results":[
{"tags":
{"tag4":"tag4_0","tag5":"tag5_1","tag2":"tag2_4","tag3":"tag3_1","tag1":"tag1_2"},
"metric":"com.test.metric8",
"tsuid":"00000F00000700002800000800002C00000900003000000A00003500000B00003A"
},
{"tags":
{"tag4":"tag4_0","tag5":"tag5_1","tag2":"tag2_4","tag3":"tag3_1","tag1":"tag1_4"},
"metric":"com.test.metric8",
"tsuid":"00000F00000700002800000800002C00000900003000000A00003500000B00003B"
},
{"tags":
{"tag4":"tag4_0","tag5":"tag5_1","tag2":"tag2_4","tag3":"tag3_1","tag1":"tag1_5"},
"metric":"com.test.metric8",
"tsuid":"00000F00000700002800000800002C00000900003000000A00003500000B00003C"
}
],
"startIndex":0,"totalResults":3
}
4,删除时间线
使用/api/query接口,批量删除时间线。其中tag支持正则,示例中部分参数省略。
/api/query -X POST
--header 'Content-Type: application/json'curl \
--data '{
"delete": true,
"start": 1645000000000,
"end": 1645000001000,
"queries": [
{
"aggregator": "none",
"explicitTags": false,
"filters": [
{
"filter": "0.01",
"groupBy": false,
"tagk": "tag",
"type": "lt"
}
],
"metric": "com.test.metric8"
}
]
}
'
5,总结
总体来说比较简单,没什么难点。