DataPrime 집계 표현식

이 가이드에서는 집계에 사용할 수 있는 IBM® Cloud Logs DataPrime 표현식에 대한 용어집을 제공합니다.

any_value

그룹에 널이 아닌 표현식 값을 반환합니다. 표현식이 정의되어 있지 않으면 기본값은 $data 객체입니다.

any_value(expression: any?)

그룹의 모든 표현식 값이 null인 경우 null을 반환합니다.

예:

groupby $m.severity calculate any_value($d.url)

avg

그룹 내 숫자 표현식의 평균값을 계산합니다.

avg(expression: number)

예:

groupby $m.severity calculate avg($d.duration) as average_duration

count

널이 아닌 표현식 값을 계산합니다. 표현식을 정의하지 않으면 모든 행이 카운트됩니다.

count(expression: any?) [into <keypath>]

별칭을 제공하여 결과가 기록될 키 경로를 재정의할 수 있습니다.

예를 들어 쿼리의 다음 부분은 다음과 같습니다

count() into $d.num_rows

를 입력하면 다음 형식의 단일 행이 생성됩니다:

{ "num_rows": 7532 }

count_if

조건을 만족하는 행에서 null이 아닌 표현식 값을 계산합니다. 표현식이 정의되어 있지 않으면 조건을 만족하는 모든 행이 카운트됩니다.

count_if(condition: bool, expression: any?)

예:

groupby $m.severity calculate count_if($d.duration > 500) as $d.high_duration_logs
groupby $m.severity calculate count_if($d.duration > 500, $d.company_id) as $d.high_duration_logs

distinct_count

널이 아닌 고유 표현식 값을 계산합니다.

distinct_count(expression: any)

예:

groupby $l.applicationname calculate distinct_count($d.username) as active_users

distinct_count_if

조건을 만족하는 행에서 널이 아닌 고유 표현식 값을 계산합니다.

distinct_count_if(condition: bool, expression: any)

예:

groupby $l.applicationname calculate distinct_count_if($m.severity == 'Error', $d.username) as users_with_errors

max

그룹에 있는 숫자 표현식의 최대값을 계산합니다.

max(expression: number | timestamp)

예:

groupby $m.severity calculate max($d.duration)

min

그룹에 있는 숫자 표현식의 최소값을 계산합니다.

min(expression: number | timestamp)

예:

groupby $m.severity calculate min($d.duration)

percentile

그룹 내 숫자 표현식의 대략적인 n 번째 백분위수 값을 계산합니다.

percentile(percentile: number, expression: number, error_threshold: number?)

백분위수 계산은 근사치이므로 0~1 범위의 error_threshold 매개변수를 사용하여 정확도를 제어할 수 있습니다(기본값은 0.01 ). 값이 낮을수록 쿼리 시간이 길어지는 대신 정확도가 향상됩니다.

예:

groupby $m.severity calculate percentile(0.99, $d.duration) as p99_latency

sample_stddev

그룹에 있는 숫자 표현식의 샘플 표준 편차를 계산합니다.

sample_stddev(expression: number)

예:

groupby $m.severity calculate sample_stddev($d.duration)

sample_variance

그룹 내 숫자 표현식의 분산을 계산합니다.

sample_variance(expression: number)

예:

groupby $m.severity calculate sample_variance($d.duration)

stddev

그룹 내 숫자 표현식의 표준 편차를 계산합니다.

stddev(expression: number)

예:

groupby $m.severity calculate stddev($d.duration)

sum

그룹에 있는 숫자 표현식의 합계를 계산합니다.

sum(expression: number)

예:

groupby $m.severity calculate sum($d.duration) as total_duration

variance

그룹 내 숫자 표현식의 분산을 계산합니다.

variance(expression: number)

예:

groupby $m.severity calculate variance($d.duration)

DataPrime 집계 표현식

그룹별 연산자로 쿼리할 때 결과 버킷에 집계 함수(예: asavg, max, sum)를 적용할 수 있습니다. 이 기능을 사용하면 표현식 자체 내에서 집계 표현식을 조작할 수 있으므로 데이터를 계산하고 동시에 조작할 수 있습니다.

예제 1

이 예제에서는 connect_durationbatch_duration 필드가 있는 로그를 가져와서 지역별로 해당 기간의 평균 간의 비율을 계산합니다.

# Query
source logs
  | groupby region calculate avg(connect_duration) / avg(batch_duration)

예제 2

이 쿼리는 전체 로그 수 중 kubernetes_pod_name 이 없는 로그의 백분율을 계산합니다. 계산은 하위 시스템별로 수행됩니다.

# Query
source logs
| groupby $l.subsystemname calculate
  sum(if(kubernetes.pod_name != null,1,0)) / count() as pct_without_pod_name

예제 3

이 쿼리는 부서별 최대 급여와 최소 급여의 비율을 계산하고 행당 추가 열로 Based on N Employees 문자열을 제공합니다.

# Query
source logs
| groupby department_id calculate
    max(salary) / min(salary) as salary_ratio
    `Based on {count()} Employees`

예제 4

이 쿼리는 오류 로그와 정보 로그 간의 비율을 계산합니다.

source logs
| groupby $m.timestamp / 1h as hour calculate
    count_if($m.severity == '5') / count_if($m.severity == '3') as error_to_info_ratio