Prometheus 的控制面板指标 - Amazon EKS
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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 结合使用

在为您的 Amazon EKS 集群配置 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,然后尝试再次运行第 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. 将 Web 浏览器指向 localhost:9090 来查看 Prometheus 控制台。

  7. - insert metric at cursor (- 在光标位置插入指标) 菜单选择一个指标,然后选择 Execute (执行)。选择 Graph (图表) 选项卡显示一段时间内的指标。下图显示了一段时间内的 container_memory_usage_bytes

    
                        Prometheus 指标
  8. 在顶部导航栏中,选择 Status (状态),然后选择 Targets (目标)

    
                        Prometheus 控制台

    显示使用服务发现连接到 Prometheus 的所有 Kubernetes 端点。

将您的 Prometheus 指标存储在 Amazon Managed Service for Prometheus

Amazon Managed Service for Prometheus 是一项与 Prometheus 兼容的监控和警报服务,可以轻松实现对容器化应用程序和基础设施的大规模监控。这是一项完全托管的服务,可自动扩展指标的提取、存储、查询和警报。这项服务还集成了 Amazon 安全服务,可以快速安全地访问您的数据。您可以使用开源 ProMQL 查询语言来查询指标并发出警报。

有关更多信息,请参阅开始使用 Amazon Managed Service for Prometheus