時序模型是針對時間序列資料的特點進行設計,適用於物聯網裝置監控、裝置採集資料、機器監控資料等情境,能提供高並發寫入和查詢以及PB級海量資料的低成本儲存。本文介紹如何使用命令列工具使用時序模型。
前提條件
已建立執行個體。具體操作,請參見建立執行個體。
注意事項
目前支援時序模型功能的地區包括華東1(杭州)、華東2(上海)、華北2(北京)、華北3(張家口)、華北6(烏蘭察布)、華南1(深圳)、西南1(成都)、中國香港、日本(東京)、新加坡、馬來西亞(吉隆坡)、印尼(雅加達)、德國(法蘭克福)、英國(倫敦)、美國(矽谷)、美國(維吉尼亞)、沙特(利雅得)。
操作步驟
步驟一:配置接入執行個體資訊
通過config命令配置接入資訊。
執行前請使用您的執行個體Endpoint、執行個體名稱、AccessKey ID、AccessKey Secret替換命令中的endpoint、instance、id、key。
config --endpoint https://myinstance.cn-hangzhou.ots.aliyuncs.com --instance myinstance --id NTSVL******************** --key 7NR2****************************************
步驟二:建立並使用時序表
建立時序表後,選擇要進行操作的時序表,以便進行後續表操作或者資料操作。
執行以下命令,建立mytable時序表。
create -m timeseries -t mytable --ttl -1
執行如下命令,使用mytable時序表。
use --ts -t mytable
步驟三:資料操作
根據需要進行資料操作,您可以寫入時序資料、查詢時序資料以及行政時間線中繼資料。
寫入時序資料
插入一行時序資料
以下樣本用於插入一行資料到時序表中。
putts --k '["cpu","localhost",["region=hangzhou","os=ubuntu"]]' --field '[{"c":"fieldname","v":"fieldvalue"},{"c":"bool_field","v":true},{"c":"double_field","v":1.1},{"c":"int_value","v":10,"isint":true}]' --time 1737451312000000
匯入時序資料
以下樣本用於匯入import_timeseries.txt檔案中的時序資料到時序表中。
import_timeseries --input /temp/import_timeseries.txt
import_timeseries.txt檔案中的配置樣本如下:
cpu,hostname=host_0,region=cn-hangzhou usage_user=58i,usage_system=2i,usage_idle=24i 1609459200000000000 cpu,hostname=host_1,region=cn-hangzhou usage_user=58i,usage_system=2i,usage_idle=24i 1609459200000000000
查詢時序資料
以下樣本用於查詢度量名稱為cpu,資料來源標識為host_0,且標籤為"hostname=host_0"和"region=cn-hangzhou"的時間軸中1667638230000000之前產生的所有時序資料。
如需使用SQL查詢表中資料,請參見SQL查詢。
getts --k '["cpu","host_0",["hostname=host_0","region=cn-hangzhou"]]' --time_start 0 --time_end 1667638230000000 --limit 100
行政時間線中繼資料
檢索時間軸
以下樣本用於檢索度量名稱為cpu且資料來源標識為host_0的時間軸。
query_ts_meta --measurement cpu --datasource host_0 --limit 10
掃描時間軸
以下樣本用於擷取時序表中最多10個時間軸。
query_ts_meta --limit 10
更新時間軸
以下樣本用於更新指定時間軸的屬性為"hostname=host_1"和"region=cn-hangzhou"。
update_ts_meta --k '["cpu","host_1",["hostname=host_1","region=cn-hangzhou"]]' --attrs '["hostname=host_1","region=cn-hangzhou"]'