addcoltotals 명령
addcoltotals 명령
addcoltotals 명령은 각 열의 합을 계산하고 각 열의 합계를 보여주는 요약 행을 추가해요. 이 명령은 row=false 및 col=true로 addtotals를 사용하는 것과 동일하므로, 열 합계가 있는 요약 보고서를 만드는 데 유용해요. 이 명령은 숫자 필드(정수, 부동 소수점, 더블)만 처리하며, 비숫자 필드는 필드 목록에 명시적으로 지정되더라도 무시돼요.
출처: 문서
본문
구문(Syntax)
addcoltotals 명령은 다음과 같은 구문을 가져요.
addcoltotals [field-list] [label=<string>] [labelfield=<field>]
매개변수(Parameters)
addcoltotals 명령은 다음 매개변수를 지원해요.
| Parameter | Required/Optional | Description |
|---|---|---|
<field-list> |
Optional | 더할 숫자 필드의 쉼표로 구분된 목록. 기본적으로 모든 숫자 필드가 더해져요. |
labelfield |
Optional | 레이블이 배치되는 필드. 필드가 없으면 생성되고 새 필드의 요약 행(마지막 행)에 레이블이 표시돼요. |
label |
Optional | 계산된 합계를 식별하기 위해 요약 행(마지막 행)에 나타나는 텍스트. labelfield와 함께 사용하면 이 텍스트가 요약 행의 지정된 필드에 배치돼요. 기본값은 Total이에요. |
예시 1: 심각도 분류에 열 합계 추가하기
다음 쿼리는 심각도 분류에 합계 행을 추가하여 모든 로그 항목의 총 합계를 보여줘요.
source=otellogs
| stats count() as log_count by severityText
| sort severityText
| fields severityText, log_count
| addcoltotals labelfield='severityText'
이 쿼리는 다음과 같은 결과를 반환해요.
| severityText | log_count |
|---|---|
| DEBUG | 3 |
| ERROR | 7 |
| INFO | 6 |
| WARN | 4 |
| Total | 20 |
예시 2: 사용자 정의 레이블로 열 합계 추가하기
다음 쿼리는 사용자 정의 요약 레이블로 서비스별 오류 수에 합계를 추가해요.
source=otellogs
| where severityText = 'ERROR'
| stats count() as errors by `resource.attributes.service.name`
| sort `resource.attributes.service.name`
| addcoltotals errors label='Grand Total' labelfield='Summary'
이 쿼리는 다음과 같은 결과를 반환해요.
| errors | resource.attributes.service.name | Summary |
|---|---|---|
| 2 | checkout | null |
| 1 | frontend-proxy | null |
| 2 | payment | null |
| 1 | product-catalog | null |
| 1 | recommendation | null |
| 7 | null | Grand Total |
예시 3: 모든 옵션 사용하기
다음 쿼리는 모든 옵션이 설정된 addcoltotals 명령을 사용해 지정된 숫자 필드만 합산하고 요약 레이블을 새 열에 배치해요.
source=otellogs
| where severityText IN ('ERROR', 'WARN')
| eval error_count = IF(severityText = 'ERROR', 1, 0), warn_count = IF(severityText = 'WARN', 1, 0)
| stats sum(error_count) as errors, sum(warn_count) as warnings by `resource.attributes.service.name`
| sort `resource.attributes.service.name`
| addcoltotals errors, warnings label='Sum' labelfield='Column Total'
이 쿼리는 다음과 같은 결과를 반환해요.
| errors | warnings | resource.attributes.service.name | Column Total |
|---|---|---|---|
| 2 | 0 | checkout | null |
| 1 | 2 | frontend-proxy | null |
| 2 | 0 | payment | null |
| 1 | 2 | product-catalog | null |
| 1 | 0 | recommendation | null |
| 7 | 4 | null | Sum |