TimeSeriesテーブルのデータを使用して Prometheus クエリを評価します。
構文
prometheusQuery('db_name', 'time_series_table', 'promql_query', evaluation_time)
prometheusQuery(db_name.time_series_table, 'promql_query', evaluation_time)
prometheusQuery('time_series_table', 'promql_query', evaluation_time)引数
db_name- TimeSeries テーブルが配置されているデータベース名。time_series_table- TimeSeries テーブルの名前。promql_query- PromQL 構文で記述されたクエリ。evaluation_time - 評価時刻のタイムスタンプ。現在時刻でクエリを評価するには、evaluation_timeとしてnow()` を使用します。
戻り値
この関数は、パラメータ promql_query に渡されたクエリの結果タイプに応じて、異なるカラムを返します。
| 結果タイプ | 結果カラム | 例 |
|---|---|---|
| vector | tags Array(Tuple(String, String)), timestamp TimestampType, value ValueType | prometheusQuery(mytable, 'up') |
| matrix | tags Array(Tuple(String, String)), time_series Array(Tuple(TimestampType, ValueType)) | prometheusQuery(mytable, 'up[1m]') |
| scalar | scalar ValueType | prometheusQuery(mytable, '1h30m') |
| string | string String | prometheusQuery(mytable, '"abc"') |
PromQL でサポートされている機能
セレクタ
インスタントセレクタ、レンジセレクタ、ラベルマッチャー (=、!=、=~、!~) 、OFFSET修飾子、@タイムスタンプ修飾子、サブクエリ。
関数
| カテゴリ | 関数 |
|---|---|
| 範囲 | rate, irate, delta, idelta, increase, last_over_time, deriv, changes, resets |
| 数学 | abs, sgn, floor, ceil, sqrt, exp, ln, log2, log10, rad, deg, round, clamp, clamp_min, clamp_max |
| 三角関数 | sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh |
| DateTime | day_of_week, day_of_month, days_in_month, day_of_year, minute, hour, month, year |
| ラベル | label_replace, label_join |
| 型 | scalar, vector |
| ヒストグラム | histogram_quantile |
| その他 | time, pi |
注記: histogram_quantile は、従来のヒストグラムのバケット (le ラベルで識別) に対して線形補間を使用します。ネイティブヒストグラムはサポートされていません。phi (分位点レベル) 引数は定数スカラーである必要があります。histogram_quantile(time() / 1000, ...) のようにステップごとに変化する式は、NOT_IMPLEMENTED 例外で拒否されます。
演算子
on()/ignoring() および group_left()/group_right() 修飾子を含む、算術 (+, -, *, /, %, ^, atan2) および比較 (省略可能な bool を伴う ==, !=, <, >, <=, >=) 二項演算子。
on()/ignoring() 修飾子を含む、論理 Set 演算子 and、or、unless。
単項演算子 + と -。
集計演算子
sum, avg, min, max, count, stddev, stdvar, group, quantile, topk, bottomk, limitk — オプションで by() または without() 修飾子を使用できます。
未サポート
- 集計演算子
count_values - 範囲関数
predict_linear,avg_over_time,min_over_time,max_over_time,sum_over_time,count_over_time,quantile_over_time,stddev_over_time,stdvar_over_time,present_over_time,absent_over_time,mad_over_time,first_over_time,ts_of_min_over_time,ts_of_max_over_time,ts_of_last_over_time,ts_of_first_over_time - 関数
absent
例
SELECT * FROM prometheusQuery(mytable, 'rate(http_requests{job="prometheus"}[10m])[1h:10m]', now())