이 자습서에서는 Amazon EKS 및 Kubernetes에서 샘플 Redis OSS 애플리케이션의 Prometheus 지표를 스크레이핑하는 실습 입문을 제공합니다. Redis OSS(https://redis.io/)는 데이터베이스, 캐시 및 메시지 브로커로 사용되는 오픈 소스(BSD 라이선스), 인메모리 구조 데이터 스토어입니다. 자세한 내용은 redis
redis_exporter(MIT License 라이선스)는 지정된 포트(기본값: 0.0.0.0:9121)에서 Redis OSS Prometheus 지표를 노출하는 데 사용됩니다. 자세한 내용은 redis_exporter
이 튜토리얼에서는 다음과 같은 두 Docker Hub 리포지토리의 Docker 이미지를 사용합니다.
Prometheus 지표를 노출하는 샘플 Redis OSS 워크로드를 설치하는 방법
-
샘플 Redis OSS 워크로드의 네임스페이스를 설정합니다.
REDIS_NAMESPACE=redis-sample
-
Fargate 시작 유형의 클러스터에서 Redis OSS를 실행하는 경우 Fargate 프로파일을 설정해야 합니다. 프로파일을 설정하려면 다음 명령을 입력합니다.
MyCluster
를 클러스터 이름으로 바꿉니다.eksctl create fargateprofile --cluster
MyCluster
\ --namespace $REDIS_NAMESPACE --name $REDIS_NAMESPACE -
다음 명령을 입력하여 샘플 Redis OSS 워크로드를 설치합니다.
curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/service/cwagent-prometheus/sample_traffic/redis/redis-traffic-sample.yaml \ | sed "s/{{namespace}}/$REDIS_NAMESPACE/g" \ | kubectl apply -f -
-
설치에는 포트 9121에서 Redis OSS Prometheus 지표를 노출하는
my-redis-metrics
라는 서비스가 포함되어 있습니다. 다음 명령을 입력하여 서비스 세부 정보를 가져옵니다.kubectl describe service/my-redis-metrics -n $REDIS_NAMESPACE
결과의
Annotations
섹션에는 다음과 같이 워크로드를 자동 검색할 수 있도록 CloudWatch 에이전트의 Prometheus 스크레이프 구성과 일치하는 두 개의 주석이 표시됩니다.prometheus.io/port: 9121 prometheus.io/scrape: true
관련 Prometheus 스크레이프 구성은
kubernetes-eks.yaml
또는kubernetes-k8s.yaml
의- job_name: kubernetes-service-endpoints
섹션에서 찾아볼 수 있습니다.
CloudWatch에서 Redis OSS Prometheus 지표 수집을 시작하는 방법
-
다음 명령 중 하나를 입력하여 최신 버전의
kubernetes-eks.yaml
또는kubernetes-k8s.yaml
파일을 다운로드합니다. EC2 시작 유형의 Amazon EKS 클러스터의 경우 다음 명령을 입력합니다.curl -O https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/service/cwagent-prometheus/prometheus-eks.yaml
Fargate 시작 유형의 Amazon EKS 클러스터의 경우 다음 명령을 입력합니다.
curl -O https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/service/cwagent-prometheus/prometheus-eks-fargate.yaml
Amazon EC2 인스턴스에서 실행되는 Kubernetes 클러스터의 경우 다음 명령을 입력합니다.
curl -O https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/service/cwagent-prometheus/prometheus-k8s.yaml
-
텍스트 편집기를 사용하여 파일을 열고
cwagentconfig.json
섹션을 찾습니다. 다음 하위 섹션을 추가하고 변경 사항을 저장합니다. 이때 들여쓰기가 기존 패턴을 따라야 합니다.{ "source_labels": ["pod_name"], "label_matcher": "^redis-instance$", "dimensions": [["Namespace","ClusterName"]], "metric_selectors": [ "^redis_net_(in|out)put_bytes_total$", "^redis_(expired|evicted)_keys_total$", "^redis_keyspace_(hits|misses)_total$", "^redis_memory_used_bytes$", "^redis_connected_clients$" ] }, { "source_labels": ["pod_name"], "label_matcher": "^redis-instance$", "dimensions": [["Namespace","ClusterName","cmd"]], "metric_selectors": [ "^redis_commands_total$" ] }, { "source_labels": ["pod_name"], "label_matcher": "^redis-instance$", "dimensions": [["Namespace","ClusterName","db"]], "metric_selectors": [ "^redis_db_keys$" ] },
추가한 섹션에서는 Redis OSS 지표를 CloudWatch 에이전트 허용 목록에 넣습니다. 해당 지표 목록은 다음 단원을 참조하세요.
-
이 클러스터에 Prometheus가 지원되는 CloudWatch 에이전트를 이미 배포한 경우 다음 명령을 입력하여 해당 에이전트를 삭제해야 합니다.
kubectl delete deployment cwagent-prometheus -n amazon-cloudwatch
-
다음 명령 중 하나를 입력하여 업데이트된 구성으로 CloudWatch 에이전트를 배포합니다.
MyCluster
및region
을 설정과 일치하도록 바꿉니다.EC2 시작 유형의 Amazon EKS 클러스터의 경우 다음 명령을 입력합니다.
kubectl apply -f prometheus-eks.yaml
Fargate 시작 유형의 Amazon EKS 클러스터의 경우 다음 명령을 입력합니다.
cat prometheus-eks-fargate.yaml \ | sed "s/{{cluster_name}}/
MyCluster
/;s/{{region_name}}/region
/" \ | kubectl apply -f -Kubernetes 클러스터의 경우 다음 명령을 입력합니다.
cat prometheus-k8s.yaml \ | sed "s/{{cluster_name}}/
MyCluster
/;s/{{region_name}}/region
/" \ | kubectl apply -f -
Redis OSS Prometheus 지표 보기
이 튜토리얼에서는 CloudWatch의 ContainerInsights/Prometheus 네임스페이스에 다음 지표를 전송합니다. CloudWatch 콘솔을 사용하여 해당 네임스페이스의 지표를 볼 수 있습니다.
메트릭 이름 | 측정기준 |
---|---|
|
ClusterName, |
|
ClusterName, |
|
ClusterName, |
|
ClusterName, |
|
ClusterName, |
|
ClusterName, |
|
ClusterName, |
|
ClusterName, |
|
ClusterName, |
|
ClusterName, |
참고
[cmd] 측정기준의 값은 append
, client
, command
, config
, dbsize
, flushall
, get
, incr
, info
, latency
또는 slowlog
일 수 있습니다.
[db] 측정기준의 값은 db0
~db15
일 수 있습니다.
Redis OSS Prometheus 지표에 대한 CloudWatch 대시보드를 생성할 수도 있습니다.
Redis OSS Prometheus 지표에 대한 대시보드를 생성하는 방법
-
환경 변수를 만들어서 아래의 값을 배포와 일치하도록 바꿉니다.
DASHBOARD_NAME=
your_cw_dashboard_name
REGION_NAME=your_metric_region_such_as_us-east-1
CLUSTER_NAME=your_k8s_cluster_name_here
NAMESPACE=your_redis_service_namespace_here
-
다음 명령을 입력하여 대시보드를 생성합니다.
curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/service/cwagent-prometheus/sample_cloudwatch_dashboards/redis/cw_dashboard_redis.json \ | sed "s/{{YOUR_AWS_REGION}}/${REGION_NAME}/g" \ | sed "s/{{YOUR_CLUSTER_NAME}}/${CLUSTER_NAME}/g" \ | sed "s/{{YOUR_NAMESPACE}}/${NAMESPACE}/g" \