Prometheus의 컨트롤 플레인 지표 - Amazon EKS

Prometheus의 컨트롤 플레인 지표

Kubernetes API 서버는 모니터링 및 분석에 유용한 많은 지표를 표시합니다. 이러한 지표는 /metrics HTTP API를 나타내는 지표 엔드포인트를 통해 내부적으로 표시됩니다. 다른 엔드포인트와 마찬가지로 이 엔드포인트도 Amazon EKS 제어 영역에 표시됩니다. 이 주제에서는 Prometheus를 배포하는 방법과 이를 사용하여 클러스터의 작업을 보고 분석할 수 있는 몇 가지 방법에 대해 설명합니다.

원시 지표 보기

원시 지표 출력을 보려면 --raw 플래그와 함께 kubectl을 사용합니다. 이 명령을 사용하면 HTTP 경로를 전달할 수 있으며, 원시 응답이 반환됩니다.

kubectl get --raw /metrics

예제 출력은 다음과 같습니다.

[...] # HELP rest_client_requests_total Number of HTTP requests, partitioned by status code, method, and host. # TYPE rest_client_requests_total counter rest_client_requests_total{code="200",host="127.0.0.1:21362",method="POST"} 4994 rest_client_requests_total{code="200",host="127.0.0.1:443",method="DELETE"} 1 rest_client_requests_total{code="200",host="127.0.0.1:443",method="GET"} 1.326086e+06 rest_client_requests_total{code="200",host="127.0.0.1:443",method="PUT"} 862173 rest_client_requests_total{code="404",host="127.0.0.1:443",method="GET"} 2 rest_client_requests_total{code="409",host="127.0.0.1:443",method="POST"} 3 rest_client_requests_total{code="409",host="127.0.0.1:443",method="PUT"} 8 # HELP ssh_tunnel_open_count Counter of ssh tunnel total open attempts # TYPE ssh_tunnel_open_count counter ssh_tunnel_open_count 0 # HELP ssh_tunnel_open_fail_count Counter of ssh tunnel failed open attempts # TYPE ssh_tunnel_open_fail_count counter ssh_tunnel_open_fail_count 0

이 원시 출력은 API 서버가 표시하는 축자를 반환합니다. 이러한 지표는 Prometheus 형식으로 표시됩니다. 이 형식을 사용하면 API 서버가 행으로 구분된 다른 지표를 표시할 수 있습니다. 각 행에는 지표 이름, 태그 및 값이 포함되어 있습니다.

metric_name{"tag"="value"[,...]} value

특정 지표를 찾는 경우 이 엔드포인트가 유용하지만, 일반적으로 시간 경과에 따라 이러한 지표를 분석하려고 합니다. 이렇게 하려면 클러스터에 Prometheus를 배포할 수 있습니다. Prometheus는 표시된 엔드포인트를 스크랩하고 데이터를 집계하는 모니터링 및 시계열 데이터베이스로, 이를 통해 결과를 필터링, 그래프 작성 및 쿼리할 수 있습니다.

Prometheus 배포

이 주제는 Helm V3를 통해 Prometheus를 클러스터에 배포하는 데 도움이 됩니다. 이미 Helm이 설치되어 있는 경우 helm version 명령을 사용하여 버전을 확인할 수 있습니다. Helm은 Kubernetes 클러스터를 위한 패키지 관리자입니다. Helm 및 Helm 설치 방법에 대한 자세한 내용은 Amazon EKS에 Helm 사용 단원을 참조하십시오.

Amazon EKS 클러스터에 대해 Helm을 구성하면 이 Helm을 사용하여 다음과 같은 단계로 Prometheus를 배포할 수 있습니다.

Helm을 사용하여 Prometheus를 배포하는 방법
  1. Prometheus 네임스페이스를 생성합니다.

    kubectl create namespace prometheus
  2. prometheus-community 차트 리포지토리를 추가합니다

    helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
  3. Prometheus를 배포합니다.

    helm upgrade -i prometheus prometheus-community/prometheus \ --namespace prometheus \ --set alertmanager.persistentVolume.storageClass="gp2",server.persistentVolume.storageClass="gp2"
    참고

    이 명령을 실행할 때 Error: failed to download "stable/prometheus" (hint: running `helm repo update` may help) 오류가 발생하면 helm repo update prometheus-community를 실행한 다음 2단계 명령을 다시 실행해봅니다.

    Error: rendered manifests contain a resource that already exists 오류가 발생하면 helm uninstall your-release-name -n namespace를 실행한 다음 3단계 명령을 다시 실행해봅니다.

  4. prometheus 네임스페이스의 모든 Pods가 READY 상태인지 확인합니다.

    kubectl get pods -n prometheus

    예제 출력은 다음과 같습니다.

    NAME READY STATUS RESTARTS AGE prometheus-alertmanager-59b4c8c744-r7bgp 1/2 Running 0 48s prometheus-kube-state-metrics-7cfd87cf99-jkz2f 1/1 Running 0 48s prometheus-node-exporter-jcjqz 1/1 Running 0 48s prometheus-node-exporter-jxv2h 1/1 Running 0 48s prometheus-node-exporter-vbdks 1/1 Running 0 48s prometheus-pushgateway-76c444b68c-82tnw 1/1 Running 0 48s prometheus-server-775957f748-mmht9 1/2 Running 0 48s
  5. kubectl을 사용하여 포트를 통해 로컬 시스템에 Prometheus 콘솔을 전송합니다.

    kubectl --namespace=prometheus port-forward deploy/prometheus-server 9090
  6. 웹 브라우저에서 http://localhost:9090으로 이동하여 Prometheus 콘솔을 표시합니다.

  7. - insert metric at cursor(커서에 지표 삽입) 메뉴에서 지표를 선택한 후 Execute(실행)를 선택합니다. Graph(그래프) 탭을 선택하여 시간에 따른 지표를 표시합니다. 다음 이미지는 시간에 따른 container_memory_usage_bytes를 표시합니다.

    
                        Prometheus 지표
  8. 상단 탐색 모음에서 Status(상태)를 선택한 후 Targets(대상)를 선택합니다.

    
                        Prometheus 콘솔

    서비스 검색을 사용하여 Prometheus에 연결된 모든 Kubernetes 엔드포인트가 표시됩니다.

Amazon Managed Service for Prometheus에 Prometheus 지표 저장

Amazon Managed Service for Prometheus는 컨테이너화된 애플리케이션과 인프라를 대규모로 쉽게 모니터링할 수 있는 Prometheus 호환 모니터링 및 알림 서비스입니다. 지표의 수집, 스토리지, 쿼리 및 알림을 자동으로 확장하는 완전관리형 서비스입니다. 또한 AWS 보안 서비스와 통합되어 데이터에 빠르고 안전하게 액세스할 수 있습니다. 오픈 소스 PromQL 쿼리 언어를 사용하여 지표를 쿼리하고 지표에 대해 알릴 수 있습니다.

자세한 내용은 Amazon Managed Service for Prometheus 시작하기를 참조하세요.