ELK Stack - ElasticSearch / Logstash / Kibana
for-of
๋ฌธ์ ๊ฐ์ฒด์ ์ฌ์ฉ์ด ๋ถ๊ฐ๋ฅํด์ Object.entries()
๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ ๋ฐฐ์ด ํํ๋ก ๋ฐ๊พธ์ง๋ง, for-in
๋ฌธ์ ๊ฐ์ฒด์ ๋ฐ๋ก ์ฌ์ฉ์ด ๊ฐ๋ฅํ๋ค!
const obj = { name : "์ดํ๋ฏผ", age: 22}
const array = **Object.entries**(obj) // [ ['name', '์ดํ๋ฏผ'], ['age',22] ]
array[0][0] // 'name' (ํค ๊ฐ)
array[0][1] // '์ดํ๋ฏผ' (value ๊ฐ)
for (let key in obj) {
console.log (`${key} is ${obj[key]}`)
}
// 'name is ์ดํ๋ฏผ'
// 'age is 22'
// ํ๋ก๊ทธ๋๋จธ์ค <https://programmers.co.kr/learn/courses/30/lessons/67256>
const leftNumbers = [ 1,4,7 ] // ์ผ์ชฝ ํคํจ๋์ ํด๋นํ๋ ์ซ์
const rightNumbers = [ 3,6,9 ] // ์ค๋ฅธ์ชฝ ํคํจ๋์ ํด๋นํ๋ ์ซ์
function solution(numbers, hand) {
let answer= ""
// ํ์ฌ ๋ ์์ง ์๊ฐ๋ฝ์ด ์ด๋ค ์์น์ ์๋์ง
const current ={
left : 10 ,
right : 12
}
for (let i = 0; i< numbers.length; i++){
// ๋๋ฅผ ๋ฒํธ๊ฐ ์ผ์ชฝ ํคํจ๋์ ํด๋น๋๋ค๋ฉด(์ผ์ชฝ ์๊ฐ๋ฝ์ผ๋ก ๋๋ฅธ๋ค๋ฉด)
if( leftNumbers.includes(numbers[i]) ){
answer += "L"
current["left"] = numbers[i] // ์ผ์ชฝ ์๊ฐ๋ฝ์ผ๋ก ์์น ๋ณ๊ฒฝ
// ๋๋ฅผ ๋ฒํธ๊ฐ ์ค๋ฅธ์ชฝ ํคํจ๋์ ํด๋น๋๋ค๋ฉด(์ค๋ฅธ์ชฝ ์๊ฐ๋ฝ์ผ๋ก ๋๋ฅธ๋ค๋ฉด)
} else if ( rightNumbers.includes(numbers[i])){
answer+="R"
current["right"]=numbers[i] // ์ค๋ฅธ์ชฝ ์๊ฐ๋ฝ์ผ๋ก ์์น ๋ณ๊ฒฝ
// ๊ฐ์ด๋ฐ ํคํจ๋์ ํด๋นํ ๊ฒฝ์ฐ
} else {
const locationObj = { ...current } // ์ผ์ชฝ, ์ค๋ฅธ์ชฝ ์๊ฐ๋ฝ์ ์์น ๊ฑฐ๋ฆฌ๋ฅผ ์ ์ฅ
for( let hand in locationObj ){
// 0์ ๋๋ ์ ๋ ์์ธ ์ฒ๋ฆฌ = 0์ 11 ์์น ๊ฐ์ผ๋ก ์ฒ๋ฆฌํ๋ค
numbers[i] = numbers[i] === 0 ? 11 : numbers[i]
// ์ผ์ชฝ๊ณผ ์ค๋ฅธ์ชฝ ์์ง ์๊ฐ๋ฝ์ผ๋ก๋ถํฐ ๊ฑฐ๋ฆฌ๊ฐ์ ๊ตฌํ๋ค
let location = Math.abs( numbers[i] - locationObj[hand] )
// ๊ฑฐ๋ฆฌ ์ฐจ์ด๊ฐ 3์นธ ์ด์์ผ ๋๋ ์์๋๋ก ์ด๋ ๊ฐ๋ฅ
if(location >= 3){
location = Math.trunc(location / 3 + location % 3)
}
locationObj[ hand ] = location
}
// ์ผ์ชฝ ์ค๋ฅธ์ชฝ ์๊ฐ๋ฝ ์์น๊ฐ ์๋ก ๋์ผํ ๊ฒฝ์ฐ
// ์ฃผ๋ก ์ฌ์ฉํ๋ ์(๋งค๊ฐ๋ณ์ hand)์ผ๋ก ๋๋ฅธ๋ค
if( locationObj["left"]===locationObj["right"] ){
answer += hand === "left" ? "L" : "R"
current [ hand ] = numbers[i]
} else {
if( locationObj["left"] >locationObj["right"] ){
// ์ค๋ฅธ์์ด ๋ ๊ฐ๊น์ด ๊ฒฝ์ฐ
answer += "R"
current["right"] = numbers[i]
} else {
// ์ผ์์ด ๋ ๊ฐ๊น์ด ๊ฒฝ์ฐ
answer += "L"
current["left"] = numbers[i]
}
}
}
}
return answer
}
// reduce(), Object.entries(), ๋น๊ตฌ์กฐํ ๋น์ ์ฌ์ฉํ ํ์ด
const [ leftNumbers,rightNumbers ] =[ [ 1,4,7 ], [ 3,6,9 ] ]
function solution(numbers, hand) {
// ํ์ฌ ๋ ์์ง ์๊ฐ๋ฝ์ด ์ด๋ค ์์น์ ์๋์ง
const current ={
left : 10 ,
right : 12
}
return numbers.reduce( (acc,cur) => {
// useFinger : ์ด๋ค ์๊ฐ๋ฝ์ผ๋ก ๋๋ ๋์ง ์ต์ข
๋ฆฌํด๊ฐ("L", "R")
// target : ์ผ์์ธ์ง ์ค๋ฅธ์์ธ์ง ("left", "right")
// number : ์ต์ข
์ ์ผ๋ก ๋๋ฅธ ๋ฒํธ ํคํจ๋ (์ซ์, 0~9)
let [ useFinger, target, number] = ["" , "" , 0 ]
if (leftNumbers.includes( cur ) ){
[useFinger, target, number] = ["L", "left", cur]
} else if ( rightNumbers.includes(cur) ) {
[useFinger, target, number] = ["R", "right", cur]
} else {
const locationObj = Object.entries( current ).reduce( ( acc2, cur2) => {
const targetHand = cur2[0]
cur = cur === 0 ? 11 : cur
let location = Math.abs(cur - cur2[1])
if ( location >2 ) { //location >=3
location = Math.trunc(location / 3 + location %3)
}
acc2[ targetHand ] = location
return acc2
}, {})
if ( locationObj["left"] === locationObj["right"] ){
[useFinger, target, number ] = [
hand === "left" ? "L" : "R",
hand === "left" ? hand : "right",
cur
]
} else if ( locationObj["left"] > locationObj["right"] ){
[useFinger, target, number ] = [ "R", "right", cur ]
} else {
[useFinger, target, number ] = [ "L", "left", cur ]
}
}
current[target] = number
// console.log( cur, current, useFinger )
return acc + useFinger
}, "")
}
๐กย ELK Stack ์
ElasticSearch + Logstash + Kibana
์ ์กฐํฉ์ผ๋ก ์ด๋ฃจ์ด์ ธ์๋ค! (์ผ๋ฐ์ ์ผ๋ก)
ElasticSearch
:๊ฒ์์ ์ต์ ํ๋ ๋์คํฌ ๊ธฐ๋ฐ ๋ฐ์ดํฐ๋ฒ ์ด์ค(NoSQL), ๋ฌธ์ฅ ๊ฒ์์ฉ ๋ฐ์ดํฐ๋ค์ ์ ์ฅ
โ BE ์์ MySQL
, ElasticSearch
๋ก ๋ฐ๋ก ์ ์ฅํ๋๊ฒ ์๋๋ผ ๋จผ์ MySQL
์ ์ ์ฅ๋ ๋ฐ์ดํฐ๋ค ์ค ๋ฌธ์ฅ ๊ฒ์์ฉ
๋ฐ์ดํฐ๋ง ๋ฐ๋ก ๋ฝ์์ ElasticSearch
์ ์ ์ฅLogstash
: MySQL
์ ์๋ ๋ฐ์ดํฐ๋ฅผ ElasticSearch
๋ก ๊ฐ์ ธ์ค๋ ์ญํ ์ ํ๋ ๋๊ตฌKibana
: ElasticSearch
์ ๋ฐ์ดํฐ๋ฅผ ์๊ฐํํ๋ ๋๊ตฌ (API ์์ฒญ ํ์)