文档

开发指南

更新时间:
一键部署

本文介绍TSDB for Prometheus支持的label运算符和聚合运算。

PromQL参考

PromQL是Prometheus提供的一种功能查询语言,允许用户实时选择和汇总时间序列数据。如要了解更多有关PromQL的内容,请参考Prometheus官方提供的PromQL文档

TSDB for Prometheus内置实现的remote storage adapter接口,极大程度上兼容Prometheus的查询功能。

支持的Label运算符

TSDB for Prometheus支持4种label运算符,包括=!==~!~等4种运算符,查询示例如下:

node__cpu__seconds__total{cpu="1",mode="user"}
node__cpu__seconds__total{cpu!="1",mode="user"}

node__cpu__seconds__total{cpu=~"1",mode="user"}
node__cpu__seconds__total{cpu=~"1|2|3",mode="user"}

node__cpu__seconds__total{cpu!~"1",mode="user"}
node__cpu__seconds__total{cpu!~"1|2|3",mode="user"}

TSDB for Prometheus对于PromQL中的正则表达式匹配,对于=~目前仅支持|*两个符号。对于!~暂时仅支持|,不支持符号*的查询。查询示例如下:

node__cpu__seconds__total{mode=~"user|sys"}    #支持
node__cpu__seconds__total{mode=~"use*"}        #支持
node__cpu__seconds__total{mode=~"user.+"}      #不支持

node__cpu__seconds__total{mode!~"user|sys"}    #支持
node__cpu__seconds__total{mode!~"use*"}        #不支持
node__cpu__seconds__total{mode!~"user.+"}      #不支持

对PromQL的正则表达式查询的更多支持,TSDB for Prometheus目前正在紧锣密鼓开发中,敬请期待。

支持的聚合运算

TSDB for Prometheus支持的Prometheus的聚合运算包括:min,max,avg,stddev,stdvar,count,topk,bottomk,quantile,count_values等,查询示例如下:

min (node__cpu__seconds__total)
max (node__cpu__seconds__total)
avg (node__cpu__seconds__total)
stddev (node__cpu__seconds__total)
stdvar (node__cpu__seconds__total)
count (node__cpu__seconds__total)
topk (1,node__cpu__seconds__total)
bottomk (1,node__cpu__seconds__total)
quantile(1,node__cpu__seconds__total)
count_values("count", node__cpu__seconds__total)

注意事项

Prometheus支持的字符与TSDB支持的字符不同,其具体差异如下表所示:

Prometheus

TSDB

metric

[a-zA-Z:][a-zA-Z0-9:]*

只可包含大小写英文字母、中文、数字,以及特殊字符 -_./():,[]=‘#

tagKey

[a-zA-Z][a-zA-Z0-9]* ,且以>开头的tagName保留为内部使用。

只可包含大小写英文字母、中文、数字,以及特殊字符 -_./():,[]=‘#

tagValue

可以为任意Unicode字符。

只可包含大小写英文字母、中文、数字,以及特殊字符 -_./():,[]=‘#

注意
  • 由于上述字符支持的差异,数据若通过Prometheus写入,则建议数据也通过Prometheus查询。若使用TSDB的原生查询接口查询这些数据,获取的tagvalue有可能出现乱码。

  • TSDB在对tagValue中不支持的字符进行Encode(编码)和Decode(解码)时,使用了#作为标识字符,因此通过Prometheus写入TSDB的tagValue最好不要包含#字符。

  • 通过Prometheus写入的数据,如果以TSDB的原生查询接口读出,请保证写入的tagvalue不包含TSDB无法识别的字符。通过TSDB原生写入接口写入的数据,如果以Prometheus读出,请保证写入的metric,tagkey不包含Prometheus无法识别的字符。

  • 本页导读 (1)
文档反馈