splunk/ 코드 예문

Algo rhythm·2022년 8월 12일
0

stats 통계 결과 출력(transforming command)

예시

stats sum(price) as totalPrice by productName
제품 별 총 판매금액을 출력
totalPrice 라는 이름의 필드를 생성하고 productName 필드의 값 별로 price 필드 값의 합계를 구함

eval 새로운 필드를 추가

예시 1

index=network sourcetype=cisco_wsa_squid
| stats sum(sc_bytes) as bytes by usage
| eval bandwidth = bytes/(1024*1024)
| eval bandwidth = round(bandwidth,2)

... 명령문 권한

index=network sourcetype=cisco_wsa_squid
| stats sum(sc_bytes) as bytes by usage
| eval bandwidth = bytes/(1024*1024), bandwidth = round(bandwidth,2)

예시 2

index=sales sourcetype="vendor_sales" VendorCountry="United States"
| stats sum(price) as Sales by VendorStateProvince
| eval Performance = case(Sales<=100, "Needs immediate evaluation", Sales<150, "Underperformer", Sales>=150, "Overperformer")
| eval Verict = if(Performance IN("Underperformer", "Needs immediate evaluation"), "Send to marketing", null())
| eval Sales = "$".tostring(Sales, "commas")

VendorStateProvince 값 별로 판매 금액의 합계를 구한다음 Sales 필드를 채움
Performance 필드를 생성하여 Sales 필드 값을 바탕으로 기준에 따라 Performance 필드를 채움
Verict 필드를 생성하여 Performance 필드 값을 바탕으로 해당 값이면, "Send to marketing" 값을 채우고 그 외의 값은 공란으로 둠
Sales 필드에 달려 표시와 콤마를 추가

예시 3

index=network sourcetype="cisco_wsa_squid" 
| stats sum(sc_bytes) as Bytes by usage
| eval bandwidth = round(Bytes/pow(1024,2), 2)
| sort -bandwidth
| rename bandwidth as "Bandwidth (MB)"

sort -bandwidth : 내림차순 정렬	
profile
배운 건 써 먹자

0개의 댓글