APISIX
설치 및 설정¶
사전 조건¶
-
APISIX설치 - DataKit 설치
APISIX 설정¶
APISIX의 설정 파일은 config.yaml이며, datakit_host를 실제 주소로 조정해야 합니다. 호스트 환경이면 ip를 입력하고, Kubernetes 환경에서는 값을 datakit-service.datakit.svc로 조정합니다.
메트릭¶
APISIX는 Prometheus 프로토콜 방식으로 메트릭을 노출할 수 있으며, APISIX 설정 파일에 다음 구성을 추가합니다.
apisix:
prometheus:
enabled: true
path: /apisix/prometheus/metrics
metricPrefix: apisix_
containerPort: 9091
plugins:
- prometheus
또한 APISIX 글로벌 플러그인에서 prometheus 플러그인을 활성화해야 합니다.
로그¶
APISIX는 여러 방식으로 로그 정보를 전송할 수 있으며, 여기서는 주로 http-logger 플러그인으로 전송합니다.
또한 APISIX 라우트에 http-logger 전송 주소 정보를 설정해야 하며, 내용은 다음과 같습니다.
{
"batch_max_size": 1,
"uri": "http://<datakit_host>:9529/v1/write/logstreaming?source=apisix_logstreaming"
}
트레이스¶
APISIX는 Opentelemetry 프로토콜로 트레이스 정보를 전송할 수 있으며, opentelemetry 플러그인을 활성화해 전송합니다.
apisix:
plugins:
- opentelemetry
pluginAttrs:
opentelemetry:
resource:
service.name: APISIX
tenant.id: business_id
collector:
address: <datakit_host>:9529/otel
request_timeout: 3
DataKit¶
호스트¶
DataKit가 호스트에서 실행 중이면 호스트 방식으로 데이터를 수집할 수 있으며, DataKit 설치 디렉터리로 들어가 설정합니다.
- 메트릭
prometheus 수집기를 활성화해 APISIX의 메트릭을 수집합니다. DataKit 설치 디렉터리의 conf.d/samples로 들어가 다음 명령을 실행합니다.
cp prom.conf.sample apisix.conf
apisix.conf 내용을 조정하며, 주로 urls를 다음과 같이 조정합니다.
- 로그
logstreaming 수집기를 활성화해 APISIX의 로그를 수집합니다. DataKit 설치 디렉터리의 conf.d/log로 들어가 다음 명령을 실행합니다.
cp logstreaming.conf.sample logstreaming.conf
내용은 조정할 필요가 없습니다.
- 트레이스
opentelemetry 수집기를 활성화해 APISIX의 트레이스 데이터를 수집합니다. DataKit 설치 디렉터리의 conf.d/opentelemetry로 들어가 다음 명령을 실행합니다.
cp opentelemetry.conf.sample opentelemetry.conf
내용은 조정할 필요가 없습니다.
- 재시작
조정이 끝나면 Datakit를 재시작합니다.
Kubernetes¶
DataKit가 Kubernetes에서 실행 중이면 다음 방식으로 설정할 수 있습니다.
- 메트릭
KubernetesPrometheus 수집기를 통해 Prometheus의 메트릭 정보를 수집할 수 있습니다.
datakit.yaml을 편집해 ConfigMap에 apisix.conf 항목을 추가합니다.
apiVersion: v1
kind: ConfigMap
metadata:
name: datakit-conf
namespace: datakit
data:
apisix.conf: |-
[inputs.kubernetesprometheus]
node_local = true
scrape_interval = "30s"
keep_exist_metric_name = false
[[inputs.kubernetesprometheus.instances]]
role = "pod"
namespaces = ["apisix"]
selector = "app.kubernetes.io/name=apisix"
scrape = "true"
scheme = "http"
port = "9091"
path = "/apisix/prometheus/metrics"
interval = "30s"
[inputs.kubernetesprometheus.instances.custom]
measurement = "apisix"
job_as_measurement = false
[inputs.kubernetesprometheus.instances.custom.tags]
node_name = "__kubernetes_pod_node_name"
namespace = "__kubernetes_pod_namespace"
pod_name = "__kubernetes_pod_name"
instance = "__kubernetes_mate_instance"
host = "__kubernetes_mate_host"
그다음 apisix.conf를 DataKit의 /usr/local/datakit/conf.d/kubernetesprometheus/ 디렉터리에 마운트합니다.
- mountPath: /usr/local/datakit/conf.d/kubernetesprometheus/apisix.conf
name: datakit-conf
subPath: apisix.conf
- 로그
datakit.yaml을 편집해 ENV_DEFAULT_ENABLED_INPUTS 환경 변수 값에 logstreaming을 추가합니다. 예시는 다음과 같습니다.
- name: ENV_DEFAULT_ENABLED_INPUTS
value: dk,cpu,disk,diskio,mem,swap,system,hostobject,net,host_processes,container,statsd,logstreaming
- 트레이스
datakit.yaml을 편집해 ENV_DEFAULT_ENABLED_INPUTS 환경 변수 값에 opentelemetry를 추가하고, 동시에 OTEL과 DDTrace 데이터 호환을 위해 ENV_INPUT_DDTRACE_COMPATIBLE_OTEL을 활성화합니다.
- name: ENV_DEFAULT_ENABLED_INPUTS
value: dk,cpu,disk,diskio,mem,swap,system,hostobject,net,host_processes,container,statsd,logstreaming,opentelemetry
- name: ENV_INPUT_DDTRACE_COMPATIBLE_OTEL
value: 'true'
- 재시작
조정이 끝나면 Datakit를 재시작합니다.
메트릭¶
| 메트릭 | 설명 | 유형 |
|---|---|---|
| bandwidth | APISIX 트래픽(ingress/egress) | int |
| etcd_modify_indexes | etcd 인덱스 기록 수 | int |
| etcd_reachable | etcd 가용성, 1은 사용 가능, 0은 사용 불가 | int |
| http_latency_bucket | 서비스의 요청 시간 지연 | int |
| http_latency_count | 서비스의 요청 시간 지연 개수 | int |
| http_latency_sum | 서비스의 요청 시간 지연 총합 | int |
| http_requests_total | http 요청 총수 | int |
| http_status | http 상태 | int |
| nginx_http_current_connections | 현재 nginx의 연결 수 | int |
| nginx_metric_errors_total | nginx 오류 메트릭 수 | int |
| node_info | 노드 정보 | int |
| shared_dict_capacity_bytes | APISIX nginx의 용량 | int |
| shared_dict_free_space_bytes | APISIX nginx의 사용 가능 공간 | int |
로그¶
Pipeline을 사용해 APISIX 로그의 trace_id를 추출하여 트레이스와 로그의 연관을 구현합니다.
jsonData=load_json(_)
requestJson = jsonData["request"]
responseJson = jsonData["response"]
add_key(http_status,responseJson["status"])
add_key(url,requestJson["url"])
add_key(client_ip,jsonData["client_ip"])
trace_id = requestJson["headers"]["traceparent"]
grok(trace_id, "%{DATA}-%{DATA:trace_id}-%{DATA}")