본문 바로가기

개발관련/Data Visualization

Fluentd로 Elastic Search 로그를 수집할 때 특정 로그가 수집이 안되는 이슈 원인 파악 및 해결

반응형

Fluentd를 이용하여 Elastic Search에 로그를 수집할 때, 정상적으로 로그 수집이 안되는 것 같아 보이는 현상 발견.

  • Fluentd의 td-agent 로그에서 특이사항 발견되지 않음.(에러 로그 없음)
  • Elastic Search의 로그에서도 특이사항 발견되지 않음.(에러 로그 없음)
  • 하지만 키바나에서 특정 index가 수집이 안되고 있는 것을 확인

 

따라서 아래 순서대로 문제의 원인 파악을 진행함. :

  • Elastic Search에 직접 수집이 안되고 있는 index로 데이터를 입력해봄

# 예시
$ curl -XPUT "http://localhost:9200/my_index/_doc/1" -H 'Content-Type: application/json' -d'
{
  "name": "Jongmin Kim",
  "message": "안녕하세요 Elasticsearch"
}'

 

  • 그랬더니 아래 에러 확인

{"error":{"root_cause":[{"type":"validation_exception","reason":"Validation Failed: 1: this action would add [2] total shards, but this cluster currently has [1000]/[1000] maximum shards open;"}],"type":"validation_exception","reason":"Validation Failed: 1: this action would add [2] total shards, but this cluster currently has [1000]/[1000] maximum shards open;"},"status":400}

 

  • 따라서 샤드의 갯수 부족으로 인식하고 아래 명령어를 통해 노드 당 샤드 갯수를 늘려줌

$ curl -X PUT http://localhost:9200/_cluster/settings -H "Content-Type: application/json" -d '{ "persistent": { "cluster.max_shards_per_node": "3000" } }'

 

  • 샤드 갯수 수정 확인

$ curl -s http://localhost:9200/_cluster/settings?pretty
{
  "persistent" : {
    "cluster" : {
      "max_shards_per_node" : "3000"
    }
  },
  "transient" : {
    "search" : {
      "max_buckets" : "20000"
    }
  }
}

 

 

  • PUT 요청 재시도

$ curl -XPUT "http://localhost:9200/my_index/_doc/1" -H 'Content-Type: application/json' -d'
{
  "name": "Jongmin Kim",
  "message": "안녕하세요 Elasticsearch"
}'
{"_index":"my_index","_type":"_doc","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}

 

 

위 과정을 거쳐 정상적으로 새로운 index(샤드)가 생성되는 것을 확인함. 이슈 해결 완료.

 

그런데 이상한점이, 만약 샤드가 부족했더라면 Fluentd가 로그를 Elastic Search에 전송할 때, Elastic Search에서 에러를 뱉어냈다면, HTTP Response Status Code 가 200이 아닌것을 확인하고 Fluentd가 에러 로그를 출력하고 해당 로그는 전송 실패한 것으로 처리했을 것 같은데.. 왜 안그랬을까 생각해봄.

 

일단 개인적인 결론으로는 Elastic Search에서 샤드 부족으로 인한 에러 리턴 시 Response Body에는 status:400 이라는 값을 리턴하지만 HTTP Status Code는 200을 리턴했기 때문에 Fluentd 입장에서는 정상적으로 로그를 전송했다고 판단한게 아닌가 싶음.

반응형

'개발관련 > Data Visualization' 카테고리의 다른 글

Ubuntu에 ReDash 세팅 방법 & 사용 방법  (0) 2020.01.20