跳到主要内容
跳到主要内容

prometheusQuery 表函数

使用来自时间序列表的数据,在评估时间范围内评估 prometheus 查询。

语法

prometheusQueryRange('db_name', 'time_series_table', 'promql_query', start_time, end_time, step)
prometheusQueryRange(db_name.time_series_table, 'promql_query', start_time, end_time, step)
prometheusQueryRange('time_series_table', 'promql_query', start_time, end_time, step)

参数

  • db_name - 包含时间序列表的数据库名称。
  • time_series_table - 一张时间序列表的名称。
  • promql_query - 使用 PromQL 语法 编写的查询。
  • start_time - 评估范围的起始时间。
  • end_time - 评估范围的结束时间。
  • step - 从 start_timeend_time (包括)迭代评估时间所使用的步长。

返回值

该函数可以根据传递给参数 promql_query 的查询结果类型返回不同的列:

结果类型结果列示例
vectortags Array(Tuple(String, String)), timestamp TimestampType, value ValueTypeprometheusQuery(mytable, 'up')
matrixtags Array(Tuple(String, String)), time_series Array(Tuple(TimestampType, ValueType))prometheusQuery(mytable, 'up[1m]')
scalarscalar ValueTypeprometheusQuery(mytable, '1h30m')
stringstring StringprometheusQuery(mytable, '"abc"')

示例

SELECT * FROM prometheusQueryRange(mytable, 'rate(http_requests{job="prometheus"}[10m])[1h:10m]', now() - INTERVAL 10 MINUTES, now(), INTERVAL 1 MINUTE)