콘텐츠로 이동

Kong

Kong 지표, 로그, 트레이스 정보 수집

지표

1. Kong 설정

Kong은 Prometheus 플러그인을 활성화한 뒤에야 지표 데이터를 보고할 수 있습니다. 여기서는 전역 방식으로 설정하는 것을 권장하며, Kong 공식 문서를 참고하세요

Kong Manager를 통해 설정

Kong Manager에 로그인한 뒤 Plugins 메뉴를 클릭하고 Prometheus를 추가합니다.

Kong API를 통해 설정

curl -X POST http://localhost:8001/plugins \
    --header "accept: application/json" \
    --header "Content-Type: application/json" \
    --data '
    {
  "name": "prometheus",
  "config": {
    "per_consumer": true,
    "status_code_metrics" : true,
    "bandwidth_metrics": true
  }
}'

2. DataKit 설정

  • datakit 설치 디렉터리의 conf.d/samples 디렉터리로 이동하여 prom.conf.sample을 복사한 뒤 kong.conf로 이름을 바꿉니다

cp prom.conf.sample kong.conf

  • kong.conf를 조정합니다

아래 두 개의 파라미터만 조정하고, 나머지는 그대로 유지합니다:

[[inputs.prom]]
  ## Exporter URLs.
  urls = ["http://127.0.0.1:8001/metrics"]
  keep_exist_metric_name = true
  • DataKit 재시작

다음 명령을 실행합니다

datakit service -R

3. Kong 지표 집합

지표명 단위 설명
kong_bandwidth_bytes bytes Kong의 대역폭 사용량, 바이트 단위
kong_datastore_reachable - 데이터 저장소에 도달 가능한지 여부를 나타내는 상태 지표
kong_http_requests_total count HTTP 요청의 총수
kong_kong_latency_ms_bucket ms Kong 자체 지연의 히스토그램 버킷, 밀리초 단위
kong_kong_latency_ms_count count Kong 자체 지연의 카운트
kong_kong_latency_ms_sum ms Kong 자체 지연의 합계, 밀리초 단위
kong_latency_ms_bucket ms 요청 지연의 히스토그램 버킷, 밀리초 단위
kong_latency_ms_count count 요청 지연의 카운트
kong_latency_ms_sum ms 요청 지연의 합계, 밀리초 단위
kong_memory_lua_shared_dict_bytes bytes Lua 공유 사전이 사용하는 메모리, 바이트 단위
kong_memory_lua_shared_dict_total_bytes bytes Lua 공유 사전의 총 메모리, 바이트 단위
kong_memory_workers_lua_vms_bytes bytes 워커 프로세스의 Lua 가상 머신이 사용하는 메모리, 바이트 단위
kong_nginx_connections_total count Nginx 연결의 총수
kong_nginx_metric_errors_total count Nginx 지표 오류의 총수
kong_nginx_requests_total count Nginx 요청의 총수
kong_node_info - 노드 정보
kong_request_latency_ms_bucket ms 요청 지연의 히스토그램 버킷, 밀리초 단위
kong_request_latency_ms_count count 요청 지연의 카운트
kong_request_latency_ms_sum ms 요청 지연의 합계, 밀리초 단위
kong_upstream_latency_ms_bucket ms 업스트림 지연의 히스토그램 버킷, 밀리초 단위
kong_upstream_latency_ms_count count 업스트림 지연의 카운트
kong_upstream_latency_ms_sum ms 업스트림 지연의 합계, 밀리초 단위

로그

1. Kong 설정

Kong은 TCP Log 플러그인을 활성화한 뒤에야 로그 데이터를 보고할 수 있습니다

Kong Manager를 통해 설정

Kong Manager에 로그인한 뒤 Plugins 메뉴를 클릭하고 TCP Log를 추가합니다.

파라미터 설명:

  • host:DataKit host
  • port: DataKit 로그 socket 포트

Kong API를 통해 설정

curl -X POST http://localhost:8001/plugins \
    --header "accept: application/json" \
    --header "Content-Type: application/json" \
    --data '
    {
  "name": "tcp-log",
  "config": {
    "port": 9580,
    "host" : "<datakit-host>"
  }
}'

2. DataKit 설정

  • datakit 설치 디렉터리의 conf.d/log 디렉터리로 이동하여 logging.conf.sample을 복사한 뒤 kong-socket.conf로 이름을 바꿉니다

cp logging.conf.sample kong-socket.conf

  • kong-socket.conf를 조정합니다

아래 전체 내용으로 교체할 수 있습니다:

# {"version": "1.22.0", "desc": "do NOT edit this line"}

[[inputs.logging]]
  ## Required
  ## File names or a pattern to tail.

  # Only two protocols are supported:TCP and UDP.
  sockets = [
     "tcp://0.0.0.0:9580",
  #  "udp://0.0.0.0:9531",
  ]
  ## glob filteer
  ignore = [""]

  ## Your logging source, if it's empty, use 'default'.
  source = "kong_tcp_log"

  ## Add service tag, if it's empty, use $source.
  service = ""

  ## Grok pipeline script name.
  pipeline = ""

  ## optional status:
  ##   "emerg","alert","critical","error","warning","info","debug","OK"
  ignore_status = []

  ## optional encodings:
  ##    "utf-8", "utf-16le", "utf-16be", "gbk", "gb18030" or ""
  character_encoding = ""

  ## The pattern should be a regexp. Note the use of '''this regexp'''.
  ## regexp link: https://golang.org/pkg/regexp/syntax/#hdr-Syntax
  # multiline_match = '''^\S'''

  auto_multiline_detection = true
  auto_multiline_extra_patterns = []

  ## Removes ANSI escape codes from text strings.
  remove_ansi_escape_codes = false

  ## If the data sent failure, will retry forevery.
  blocking_mode = true

  ## If file is inactive, it is ignored.
  ## time units are "ms", "s", "m", "h"
  ignore_dead_log = "1h"

  ## Read file from beginning.
  from_beginning = false

  [inputs.logging.tags]
  # some_tag = "some_value"
  # more_tag = "some_other_value"
  • DataKit 재시작

다음 명령을 실행합니다

datakit service -R

Pipeline

Pipeline은 로그 필드 추출에 사용할 수 있으며, 내장된 Pipeline 템플릿이 있습니다. Pipeline 템플릿 라이브러리에서 Kong을 찾아 복제하여 사용하세요.

트레이스

1. Kong 설정

Kong은 OpenTelemetry 플러그인을 활성화한 뒤에야 트레이스 데이터를 보고할 수 있습니다. 이 기능은 Kong version ≥ 3.3.2가 필요합니다.

전역 트레이스 설정 활성화

kong.conf에 아래 설정 항목을 추가합니다:

tracing_instrumentations = all
tracing_sampling_rate = 1.0

또는 환경 변수를 추가합니다:

  KONG_TRACING_INSTRUMENTATIONS: all
  KONG_TRACING_SAMPLING_RATE: 1.0

Kong 서비스를 재시작하면 적용됩니다.

Kong Manager를 통해 설정

Kong Manager에 로그인한 뒤 Plugins 메뉴를 클릭하고 OpenTelemetry를 추가합니다.

Kong API를 통해 설정

curl -X POST http://localhost:8001/plugins \
    --header "accept: application/json" \
    --header "Content-Type: application/json" \
    --data '
{
  "protocols": [
    "http"
  ],
  "name": "opentelemetry",
  "config": {
    "propagation": {
      "default_format": "datadog"
    },
    "traces_endpoint": "http://192.168.2.110:9529/otel/v1/traces"
  },
  "enabled": true
}'
curl -X POST http://localhost:8001/plugins \
    --header "accept: application/json" \
    --header "Content-Type: application/json" \
    --data '
{
  "protocols": [
    "http"
  ],
  "name": "opentelemetry",
  "config": {
    "endpoint": "http://192.168.2.110:9529/otel/v1/traces"
  },
  "enabled": true
}'

2. DataKit 설정

  • datakit 설치 디렉터리의 conf.d/opentelemetry 디렉터리로 이동하여 opentelemetry.conf.sample을 복사한 뒤 opentelemetry.conf로 이름을 바꿉니다

cp opentelemetry.conf.sample opentelemetry.conf

설정 내용은 조정할 필요가 없습니다

  • DataKit 재시작

다음 명령을 실행합니다

datakit service -R

문서 평가

이 페이지가 도움이 되었나요?