---
# Amazon EKS control-plane metrics (namespace AWS/EKS).
#
# Per cluster ({ClusterName}). These are the managed control-plane metrics (kube-apiserver,
# kube-scheduler, etcd) that EKS publishes to CloudWatch automatically, at no extra EKS charge, for
# clusters on Kubernetes 1.28+ (they are NOT Container Insights / the CloudWatch Observability add-on,
# which is agent-based and billed separately).
#
# Statistic note: EKS publishes these at 1-minute granularity. The `*_total*` metrics are per-period
# counters (sum -> per-second rate). Everything else is a gauge (inflight requests, APF seats, pending
# pods, etcd bytes) or an already-computed p99 latency in seconds; these use average/maximum so the value
# is correct regardless of the query period -- do NOT switch them to sum (that would multiply a gauge by
# the number of datapoints in the window).
version: v1
display_name: Amazon EKS
namespace: AWS/EKS
query:
  period: 5m
instance:
  dimensions:
    - name: ClusterName
      label: cluster_name
metrics:
  - id: apiserver_requests
    metric_name: apiserver_request_total
    statistics: [sum]
    rate: true
  - id: apiserver_requests_4xx
    metric_name: apiserver_request_total_4XX
    statistics: [sum]
    rate: true
  - id: apiserver_requests_5xx
    metric_name: apiserver_request_total_5XX
    statistics: [sum]
    rate: true
  - id: apiserver_latency_get_p99
    metric_name: apiserver_request_duration_seconds_GET_P99
    statistics: [average]
  - id: apiserver_latency_list_p99
    metric_name: apiserver_request_duration_seconds_LIST_P99
    statistics: [average]
  - id: apiserver_inflight_read_only
    metric_name: apiserver_current_inflight_requests_READONLY
    statistics: [average]
  - id: apiserver_inflight_mutating
    metric_name: apiserver_current_inflight_requests_MUTATING
    statistics: [average]
  - id: etcd_db_size_in_use
    metric_name: etcd_mvcc_db_total_size_in_use_in_bytes
    statistics: [maximum]
  - id: scheduler_pending_pods
    metric_name: scheduler_pending_pods
    statistics: [average]
  - id: scheduler_attempts_scheduled
    metric_name: scheduler_schedule_attempts_SCHEDULED
    statistics: [sum]
    rate: true
  - id: scheduler_attempts_unschedulable
    metric_name: scheduler_schedule_attempts_UNSCHEDULABLE
    statistics: [sum]
    rate: true
  - id: scheduler_attempts_error
    metric_name: scheduler_schedule_attempts_ERROR
    statistics: [sum]
    rate: true
  # ----------------------------------------------------------------------------------------
  # Opt-in metrics (disabled by default). Select them through rules[].metrics.
  # All are published at the {ClusterName} grain.
  # ----------------------------------------------------------------------------------------
  - id: apiserver_requests_429
    disabled: true
    metric_name: apiserver_request_total_429
    statistics: [sum]
    rate: true
  - id: apiserver_flowcontrol_seats
    disabled: true
    metric_name: apiserver_flowcontrol_current_executing_seats
    statistics: [average]
  - id: apiserver_latency_post_p99
    disabled: true
    metric_name: apiserver_request_duration_seconds_POST_P99
    statistics: [average]
  - id: apiserver_latency_put_p99
    disabled: true
    metric_name: apiserver_request_duration_seconds_PUT_P99
    statistics: [average]
  - id: apiserver_latency_patch_p99
    disabled: true
    metric_name: apiserver_request_duration_seconds_PATCH_P99
    statistics: [average]
  - id: apiserver_latency_delete_p99
    disabled: true
    metric_name: apiserver_request_duration_seconds_DELETE_P99
    statistics: [average]
  - id: scheduler_pending_pods_active
    disabled: true
    metric_name: scheduler_pending_pods_ACTIVEQ
    statistics: [average]
  - id: scheduler_pending_pods_backoff
    disabled: true
    metric_name: scheduler_pending_pods_BACKOFF
    statistics: [average]
  - id: scheduler_pending_pods_unschedulable
    disabled: true
    metric_name: scheduler_pending_pods_UNSCHEDULABLE
    statistics: [average]
  - id: scheduler_pending_pods_gated
    disabled: true
    metric_name: scheduler_pending_pods_GATED
    statistics: [average]
  - id: admission_webhook_requests_admit
    disabled: true
    metric_name: apiserver_admission_webhook_request_total_ADMIT
    statistics: [sum]
    rate: true
  - id: admission_webhook_requests_validating
    disabled: true
    metric_name: apiserver_admission_webhook_request_total_VALIDATING
    statistics: [sum]
    rate: true
template:
  family: EKS
  context_namespace: eks
  chart_defaults:
    instances:
      by_labels: [account_id, region, cluster_name]
  charts:
    - id: aws_cloudwatch_eks_apiserver_requests
      context: apiserver_requests
      title: EKS API Server Request Rate
      family: API Server
      units: requests/s
      algorithm: absolute
      dimensions:
        - selector: apiserver_requests_sum
          name: requests
    - id: aws_cloudwatch_eks_apiserver_request_errors
      context: apiserver_request_errors
      title: EKS API Server Request Errors
      family: API Server
      units: requests/s
      algorithm: absolute
      dimensions:
        - selector: apiserver_requests_4xx_sum
          name: 4xx
        - selector: apiserver_requests_5xx_sum
          name: 5xx
    - id: aws_cloudwatch_eks_apiserver_latency
      context: apiserver_latency
      title: EKS API Server Request Latency (p99)
      family: API Server
      units: seconds
      algorithm: absolute
      dimensions:
        - selector: apiserver_latency_get_p99_average
          name: get
        - selector: apiserver_latency_list_p99_average
          name: list
    - id: aws_cloudwatch_eks_apiserver_inflight
      context: apiserver_inflight
      title: EKS API Server In-Flight Requests
      family: API Server
      units: requests
      algorithm: absolute
      dimensions:
        - selector: apiserver_inflight_read_only_average
          name: read_only
        - selector: apiserver_inflight_mutating_average
          name: mutating
    - id: aws_cloudwatch_eks_etcd_db_size
      context: etcd_db_size
      title: EKS etcd Database Size In Use
      family: etcd
      units: bytes
      algorithm: absolute
      dimensions:
        - selector: etcd_db_size_in_use_maximum
          name: in_use
    - id: aws_cloudwatch_eks_scheduler_pending_pods
      context: scheduler_pending_pods
      title: EKS Scheduler Pending Pods
      family: Scheduler
      units: pods
      algorithm: absolute
      dimensions:
        - selector: scheduler_pending_pods_average
          name: pending
    - id: aws_cloudwatch_eks_scheduler_attempts
      context: scheduler_attempts
      title: EKS Scheduler Attempts
      family: Scheduler
      units: attempts/s
      algorithm: absolute
      dimensions:
        - selector: scheduler_attempts_scheduled_sum
          name: scheduled
        - selector: scheduler_attempts_unschedulable_sum
          name: unschedulable
        - selector: scheduler_attempts_error_sum
          name: error
    # ----------------------------------------------------------------------------------------
    # Charts for the opt-in metrics above.
    # ----------------------------------------------------------------------------------------
    - id: aws_cloudwatch_eks_apiserver_throttling
      context: apiserver_throttling
      title: EKS API Server Priority-and-Fairness Throttling
      family: API Server
      units: requests/s
      algorithm: absolute
      dimensions:
        - selector: apiserver_requests_429_sum
          name: throttled_429
    - id: aws_cloudwatch_eks_apiserver_flowcontrol
      context: apiserver_flowcontrol
      title: EKS API Server Concurrency Seats In Use
      family: API Server
      units: seats
      algorithm: absolute
      dimensions:
        - selector: apiserver_flowcontrol_seats_average
          name: executing
    - id: aws_cloudwatch_eks_apiserver_write_latency
      context: apiserver_write_latency
      title: EKS API Server Write Latency (p99)
      family: API Server
      units: seconds
      algorithm: absolute
      dimensions:
        - selector: apiserver_latency_post_p99_average
          name: post
        - selector: apiserver_latency_put_p99_average
          name: put
        - selector: apiserver_latency_patch_p99_average
          name: patch
        - selector: apiserver_latency_delete_p99_average
          name: delete
    - id: aws_cloudwatch_eks_scheduler_pending_by_queue
      context: scheduler_pending_by_queue
      title: EKS Scheduler Pending Pods by Queue
      family: Scheduler
      units: pods
      algorithm: absolute
      dimensions:
        - selector: scheduler_pending_pods_active_average
          name: active
        - selector: scheduler_pending_pods_backoff_average
          name: backoff
        - selector: scheduler_pending_pods_unschedulable_average
          name: unschedulable
        - selector: scheduler_pending_pods_gated_average
          name: gated
    - id: aws_cloudwatch_eks_admission_webhooks
      context: admission_webhooks
      title: EKS Admission Webhook Requests
      family: API Server
      units: requests/s
      algorithm: absolute
      dimensions:
        - selector: admission_webhook_requests_admit_sum
          name: admit
        - selector: admission_webhook_requests_validating_sum
          name: validating
