[ Splunk Search ] ์ฃผ์‹ ํ”„๋กœ์ ํŠธ์— ์‚ฌ์šฉ๋œ ๋ช…๋ น์–ด ๋ถ„์„ํ•˜๊ธฐ
๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Splunk/Splunk Search

[ Splunk Search ] ์ฃผ์‹ ํ”„๋กœ์ ํŠธ์— ์‚ฌ์šฉ๋œ ๋ช…๋ น์–ด ๋ถ„์„ํ•˜๊ธฐ

728x90
๋ฐ˜์‘ํ˜•

๐Ÿ”† ์˜ค๋Š˜์˜ ๋ชฉํ‘œ ๐Ÿ”†

     ๐Ÿชจ ์•„๋ž˜์˜ ๋ฐฐ์—ดํ˜• ๋ฐ์ดํ„ฐ๋ฅผ ๋…๋ฆฝ๋œ ์—ด ๋ฐ์ดํ„ฐ๋กœ ๋งŒ๋“ค์ž!!

{
    "Sharpe": 0.49486577087259837, 
    "Returns": 0.09653658218825922, 
    "Risk": 0.19507629719072297, 
    "idx": 999, 
    "code": ["008770.KS", "010620.KS", "011170.KS", "024110.KS", "192820.KS"], 
    "rate": [0.027731564480966874, 0.056647087277405216, 0.5564385158412494, 0.0045145824210048, 0.35466824997937374], 
    "date": "2021-01-11"
}

 

 

     ๐Ÿชจ ์›ํ•˜๋Š” ๊ฒฐ๊ณผ

 

index="monte" 
| head 1 
| rename code{} as codes
| rename rate{} as rates
| eval fields_value=mvzip(codes, rates)
| mvexpand fields_value
| eval fields_value = split(fields_value, ",")
| eval code = mvindex(fields_value, 0)
| eval rate = mvindex(fields_value, 1)
| rex field=code "^(?<code>\\d+).KS" 
| lookup kospi_200 code OUTPUT name 
| table date, idx, code, Sharpe, Returns, Risk, rate
  • ์š” ๋ช…๋ น์–ด๋ฅผ ๋ฝ€๊ฐœ๋ณด์ž!

 

 

๐Ÿ€ head ๐Ÿ€

  • ์ด๋ ฅ ๊ฒ€์ƒ‰์˜ ๊ฒฝ์šฐ ๊ฐ€์žฅ ์ตœ๊ทผ์˜ ์ด๋ฒคํŠธ N๊ฐœ๋ฅผ ๋‚˜ํƒ€๋ƒ„
  • ์‹ค์‹œ๊ฐ„ ๊ฒ€์ƒ‰์˜ ๊ฒฝ์šฐ ๊ฐ€์žฅ ๋จผ์ € ์ˆ˜์ง‘๋œ ์ด๋ฒคํŠธ N๊ฐœ๋ฅผ ๋‚˜ํƒ€๋ƒ„

 

 

๐Ÿ€ rename ๐Ÿ€

  • ํ•˜๋‚˜ ์ด์ƒ์˜ ํ•„๋“œ ์ด๋ฆ„์„ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ๋‹ค.
  • ์™€์ผ๋“œ์นด๋“œ ๋ฌธ์ž๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ด๋ฆ„์ด ์œ ์‚ฌํ•œ ํ•„๋“œ์˜ ์ด๋ฆ„์„ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ๋‹ค.

(์ขŒ) ์ „, (์šฐ) ํ›„

 

 

๐Ÿ€ eval ๐Ÿ€

  • ์‹์„ ๊ณ„์‚ฐํ•˜๊ณ  ๊ฒฐ๊ณผ ๊ฐ’์„ ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ ํ•„๋“œ์— ๋„ฃ๋Š”๋‹ค.
    • ์ง€์ •ํ•˜๋Š” ํ•„๋“œ ์ด๋ฆ„์ด ๋ฐ์ดํ„ฐ์— ์—†์„ ๋•Œ, ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ์— ์ƒˆ ํ•„๋“œ๊ฐ€ ์ถ”๊ฐ€๋จ
    • ์ง€์ •ํ•˜๋Š” ํ•„๋“œ ์ด๋ฆ„์ด ๋ฐ์ดํ„ฐ์— ์žˆ์„ ๋•Œ, ํ•ด๋‹น ํ•„๋“œ ๊ฐ’์„ eval ์‹์˜ ๊ฒฐ๊ณผ๋กœ ๋ฎ์–ด์”€
  • ์ˆซ์ž, ๋ฌธ์ž์—ด ๋ฐ ๋ถ€์šธ์‹์„ ํ‰๊ฐ€ํ•œ๋‹ค.
  • ํ•œ ๊ฒ€์ƒ‰์—์„œ ์‰ผํ‘œ๋ฅผ ์‚ฌ์šฉํ•ด ์—ฌ๋Ÿฌ eval ์‹์„ ์—ฐ์‡„์ ์œผ๋กœ ์—ฐ๊ฒฐํ•˜์—ฌ ์ดํ›„์˜ ์‹์„ ๊ตฌ๋ถ„ํ•  ์ˆ˜ ์žˆ์Œ.
  • ๊ฒ€์ƒ‰์—์„œ๋Š” ์—ฌ๋Ÿฌ eval ์‹์„ ์™ผ์ชฝ์—์„œ ์˜ค๋ฅธ์ชฝ ์ˆœ์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๋ฏ€๋กœ,
    ์ดํ›„ ์‹์—์„œ ์ด์ „์— ํ‰๊ฐ€ํ•œ ํ•„๋“œ๋ฅผ ์ฐธ์กฐํ•  ์ˆ˜ ์žˆ๋‹ค.
  • eval์—์„œ ์ƒˆ๋กœ ์ƒ์„ฑ๋œ ํ•„๋“œ๋Š” ๊ด€์‹ฌ ํ•„๋“œ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 

โ˜˜๏ธ eval ๋ช…๋ น์˜ ํ•จ์ˆ˜ : mvzip(X, Y, "Z") โ˜˜๏ธ

  • ๋‘ ๊ฐœ์˜ ๋‹ค์ค‘๊ฐ’ ํ•„๋“œ( X, Y )๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  X์˜ ์ฒซ ๋ฒˆ์งธ ๊ฐ’๊ณผ  Y์˜ ์ฒซ ๋ฒˆ์งธ ๊ฐ’,
    X์˜ ๋‘ ๋ฒˆ์งธ ๊ฐ’๊ณผ Y์˜ ๋‘ ๋ฒˆ์งธ ๊ฐ’์„ ์—ฐ๊ฒฐํ•˜๋Š” ๋“ฑ์˜ ๋ฐฉ์‹์œผ๋กœ ํ•„๋“œ๋ฅผ ๊ฒฐํ•ฉํ•œ๋‹ค.
  • ์„ธ ๋ฒˆ์งธ ์ธ์ˆ˜ Z๋Š” ์„ ํƒ ์‚ฌํ•ญ์ด๋ฉฐ, ๋‘ ๊ฐ’์„ ์กฐ์ธํ•˜๊ธฐ ์œ„ํ•œ ๊ตฌ๋ถ„์ž๋ฅผ ์ง€์ •ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ
    ๊ธฐ๋ณธ๊ฐ’์€ ์‰ผํ‘œ์ด๋‹ค.

 

 

 

โ˜˜๏ธ eval ๋ช…๋ น์˜ ํ•จ์ˆ˜ : split(X, "Y") โ˜˜๏ธ

  • ์ด ํ•จ์ˆ˜๋Š” ๋‘ ๊ฐœ์˜ ์ธ์ˆ˜์ธ ํ•„๋“œ X์™€ ๊ตฌ๋ถ„์ž Y๋ฅผ ์‚ฌ์šฉํ•˜๊ณ , X์˜ ๊ฐ’์„ ๊ตฌ๋ถ„์ž Y๋กœ ๊ตฌ๋ถ„ํ•˜๊ณ  X๋ฅผ ๋‹ค์ค‘๊ฐ’ ํ•„๋“œ๋กœ ๋ฐ˜ํ™˜

 

 

 

โ˜˜๏ธ eval ๋ช…๋ น์˜ ํ•จ์ˆ˜ : mvindex(MVFIELD,STARTINDEX, ENDINDEX)โ˜˜๏ธ

  • ์ด ํ•จ์ˆ˜๋Š” ์‹œ์ž‘ ๋ฐ ์ข…๋ฃŒ ์ธ๋ฑ์Šค ๊ฐ’์„ ์‚ฌ์šฉํ•˜์—ฌ ๋‹ค์ค‘๊ฐ’ ํ•„๋“œ์˜ ๋ถ€๋ถ„ ์ง‘ํ•ฉ์„ ๋ฐ˜ํ™˜
    • MVFIELD: ๋‹ค์ค‘๊ฐ’ ํ•„๋“œ (ํ•„์ˆ˜) 
    • STARTINDEX: ์ˆซ์ž (ํ•„์ˆ˜)
    • ENDINDEX: ์ˆซ์ž (์„ ํƒ ์‚ฌํ•ญ)
  • ์ธ๋ฑ์Šค๋Š” 0๋ถ€ํ„ฐ ์‹œ์ž‘
  • STARTINDEX ์ธ์ˆ˜๋งŒ ์ง€์ •๋œ ๊ฒฝ์šฐ ํ•ด๋‹น ๊ฐ’๋งŒ ๊ฒฐ๊ณผ์— ํฌํ•จ๋จ
  • ENDINDEX ์ธ์ˆ˜๊ฐ€ ์ง€์ •๋œ ๊ฒฝ์šฐ STARTINDEX๋ถ€ํ„ฐ ENDINDEX๊นŒ์ง€์˜ ๊ฐ’ ๋ฒ”์œ„๊ฐ€ ๊ฒฐ๊ณผ์— ํฌํ•จ๋จ
  • STARTINDEX์™€ ENDINDEX๋ชจ๋‘ ์Œ์ˆ˜์ผ ์ˆ˜ ์žˆ๋‹ค. 
    • -1 ์ธ๋ฑ์Šค๋Š” ๋ฆฌ์ŠคํŠธ์˜ ๋งˆ์ง€๋ง‰ ๊ฐ’์„ ์ง€์ •ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ
    • ์ธ๋ฑ์Šค๊ฐ€ ๋ฒ”์œ„๋ฅผ ๋ฒ—์–ด๋‚ฌ๊ฑฐ๋‚˜ ์œ ํšจํ•˜์ง€ ์•Š์œผ๋ฉด NULL์„ ๋ฐ˜ํ™˜
| eval code = mvindex(fields_value, 0)
| eval rate = mvindex(fields_value, 1)

 

 

 

๐Ÿ€ mvexpand ๐Ÿ€

  • ๋‹ค์ค‘๊ฐ’ ํ•„๋“œ์˜ ๊ฐ’์„ ๋‹ค์ค‘๊ฐ’ ํ•„๋“œ์˜ ๊ฐ ๊ฐ’์— ๋Œ€ํ•ด ํ•˜๋‚˜์”ฉ ๊ฐœ๋ณ„ ์ด๋ฒคํŠธ๋กœ ํ™•์žฅ
  • ๊ฐ ๊ฒฐ๊ณผ์— ๋Œ€ํ•ด mvexpand ๋ช…๋ น์–ด๋Š” ๋ชจ๋“  ๋‹ค์ค‘๊ฐ’ ํ•„๋“œ์— ๋Œ€ํ•ด ์ƒˆ ์ด๋ฒคํŠธ๋ฅผ ๋งŒ๋“ ๋‹ค.

 

 

 

๐Ÿ€ rex ๐Ÿ€

  • ์ด ๋ช…๋ น์–ด๋Š” ์ •๊ทœ์‹ ๋ช…๋ช… ๊ทธ๋ฃน์„ ์‚ฌ์šฉํ•˜์—ฌ ํ•„๋“œ๋ฅผ ์ถ”์ถœํ•˜๊ฑฐ๋‚˜
    sed ์‹์„ ์‚ฌ์šฉํ•˜์—ฌ ํ•„๋“œ์˜ ๋ฌธ์ œ๋ฅผ ๋ฐ”๊พธ๊ฑฐ๋‚˜ ๋Œ€์ฒดํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ
  • ์ง€์ •๋œ ํ•„๋“œ์˜ ๊ฐ’์„ ๊ณ ์ •๋˜์ง€ ์•Š์€ ์ •๊ทœ์‹๊ณผ ์ผ์น˜์‹œํ‚ค๊ณ ,
    ๋ช…๋ช…๋œ ๊ทธ๋ฃน์„ ํ•ด๋‹น ์ด๋ฆ„์„ ๊ฐ€์ง„ ํ•„๋“œ๋กœ ์ถ”์ถœ
  • ํ›—๋‚  ์ž์„ธํ•˜๊ฒŒ ํฌ์ŠคํŒ…ํ•  ์˜ˆ์ •
| rex field=code "^(?<code>\\d+).KS"
  • ์—ฌ๊ธฐ์„œ๋Š” ๊ธฐ์กด code field์—์„œ ๋‚˜๋ผ ์ฝ”๋“œ ".KS"๋ฅผ ์ง€์›Œ๋ฒ„๋ฆฐ
    ์ˆซ์ž๋กœ๋งŒ๋œ code๋กœ ๋ฐ”๊พธ๊ธฐ ์œ„ํ•ด์„œ ์‚ฌ์šฉ๋จ.

 

 

 

๐Ÿ€ lookup ๐Ÿ€

| lookup kospi_200 code OUTPUT name
  • kospi_200์ด๋ผ๋Š” ๋ฃฉ์—… ํŒŒ์ผ์˜ name์ด๋ผ๋Š” ํ•„๋“œ๋ฅผ ์šฐ๋ฆฌ๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๋ฐ์ดํ„ฐ์˜ code ํ•„๋“œ๋ž‘ ๋งคํ•‘ํ•ด์ค˜

 

  • ์ฝ”๋“œ์— ๋งž๋Š” ํšŒ์‚ฌ ์ด๋ฆ„์ด ์ž˜ ๋งตํ•‘๋˜์–ด ๋“ค์–ด๊ฐ„ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

728x90
๋ฐ˜์‘ํ˜•