prometheusQuery

prometheusQuery

TimeSeries 테이블의 데이터를 사용해 Prometheus 쿼리(PromQL)를 평가하는 테이블 함수예요.

출처: 문서

본문

TimeSeries 테이블의 데이터를 사용해 Prometheus 쿼리를 평가해요.

문법 (Syntax)

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)

인자 (Arguments)

  • db_name - TimeSeries 테이블이 있는 데이터베이스의 이름이에요.
  • time_series_table - TimeSeries 테이블의 이름이에요.
  • promql_query - PromQL 문법으로 작성된 쿼리예요.
  • evaluation_time - 평가 타임스탬프예요. 현재 시점에 쿼리를 평가하려면 evaluation_time으로 now()를 사용하세요.

반환값 (Returned value)

함수는 promql_query 파라미터로 전달된 쿼리의 결과 타입에 따라 다른 컬럼을 반환할 수 있어요:

결과 타입 결과 컬럼 예시
vector tags Array(Tuple(String, String)), timestamp TimestampType, value ValueType prometheusQuery(mytable, 'up')
matrix tags Array(Tuple(String, String)), samples Array(Tuple(TimestampType, ValueType)) prometheusQuery(mytable, 'up[1m]')
scalar scalar ValueType prometheusQuery(mytable, '1h30m')
string string String prometheusQuery(mytable, '"abc"')

TimeSeries 테이블의 버전이 2 이하이면 samples 컬럼의 이름은 time_series예요.

지원되는 PromQL 기능 (Supported PromQL Features)

셀렉터 (Selectors)

인스턴트 셀렉터, 범위 셀렉터, 라벨 매처(=, !=, =~, !~), offset 수정자, @ 타임스탬프 수정자, 서브쿼리.

함수 (Functions)

카테고리 함수
Range rate, irate, delta, idelta, increase, last_over_time, sum_over_time, avg_over_time, count_over_time, max_over_time, min_over_time, ts_of_max_over_time, ts_of_min_over_time, deriv, changes, resets, present_over_time, absent_over_time, quantile_over_time, predict_linear
Math abs, sgn, floor, ceil, sqrt, exp, ln, log2, log10, rad, deg, round, clamp, clamp_min, clamp_max
Trig 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 label_replace, label_join
Type scalar, vector
Histogram histogram_quantile
Other time, pi, absent

참고: histogram_quantile은 고전적 히스토그램 버킷(le 라벨로 식별)에 대해 선형 보간을 사용해요. 네이티브 히스토그램은 지원되지 않아요. phi(분위수 수준) 인자는 상수 스칼라여야 해요. histogram_quantile(time() / 1000, ...)처럼 단계별로 달라지는 표현식은 NOT_IMPLEMENTED 예외로 거부돼요.

참고: ts_of_min_over_timets_of_max_over_time은 Prometheus에서 실험적 함수예요(거기서는 --enable-feature=promql-experimental-functions로 활성화). ClickHouse는 그 플래그 없이도 이들을 평가해요.

연산자 (Operators)

산술(+, -, *, /, %, ^, atan2) 및 비교(==, !=, <, >, <=, >= 선택적 bool) 이항 연산자이며, on()/ignoring()group_left()/group_right() 수정자를 지원해요.

논리 집합 연산자 and, or, unless이며, on()/ignoring() 수정자를 지원해요.

단항 연산자 +-.

집계 연산자 (Aggregation Operators)

sum, avg, min, max, count, count_values, stddev, stdvar, group, quantile, topk, bottomk, limitk — 선택적 by() 또는 without() 수정자 지원.

아직 지원되지 않음 (Not yet supported)

범위 함수 stddev_over_time, stdvar_over_time, mad_over_time, first_over_time, ts_of_last_over_time, ts_of_first_over_time

예시 (Example)

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

더 알아보기 (Learn more)