首页 / API 文档 / 运维中心 / 告警策略 / 查看告警策略列表

查看告警策略列表

请求信息

请求行

GET /apis/monitoring.coreos.com/v1/prometheusrules

查看类型为 PrometheusRule 的资源对象的列表。

请求参数

名称 类型 是否必填项 描述
allowWatchBookmarks boolean allowWatchBookmarks 请求使用 BOOKMARK 类型监视事件。没有实现书签的服务器可能会忽略此标志,而书签是由服务器自行发送的。客户端不应该假定书签在任何特定的间隔被返回,也不应该假定服务器将在会话期间发送任何 BOOKMARK 事件。如果这不是 watch 请求,这个字段将被忽略。如果在 apiserver 中未启用特性门 WatchBookmarks,则忽略该字段。
continue string 服务器定义的值,⽤于从服务器中查询更多的返回结果。客户端只能从上⼀个查询结果中获取该值。当查询列表时设置了limit 参数,返回结果未包含服务器上可以查询到的所有数据,此时,会返回 continue 参数,并为 continue 参数赋值⼀个 Token。需要查询更多返回结果时,可将 continue 参数及其值作为查询参数查询更多结果。说明:如果列表配置发⽣变化或查询过期,输⼊此查询参数后,会返回 410 错误码,如果继续输⼊该查询参数进⾏查询,返回的查询结果可能不是最新的数据。
fieldSelector string 字段选择器,可通过资源对象的字段过滤、筛选资源对象,默认返回所有资源对象。
labelSelector string 标签选择器,可通过标签过滤、筛选资源对象,默认返回所有资源对象。
limit integer limit 是查询列表请求返回的最大响应数。 如果存在更多项,则服务器会将列表元数据上的 “continue” 字段设置为一个值,该值可与相同的初始查询一起使用用来检索下一组结果。如果所有请求的对象都被过滤掉了,则设置的限制返回的项目数可能少于请求的项目数(最多为零),并且客户端应仅使用 continue 字段的存在来确定是否有更多结果可用。服务器可能选择不支持 limit 参数,并将返回所有可用结果。如果指定了限制,并且 continue 字段为空,则客户端可能会认为没有更多结果可用。如果 watch 为 true,则不支持此字段。 服务器保证使用 continue 时返回的对象与发出单个列表调用无限制地相同,也就是说,在发出第一个请求后,任何创建、修改或删除的对象都不会包含在任何后续的继续请求中。有时这被称为一致快照,并确保使用限制接收非常大结果的较小块的客户端可以确保它们看到所有可能的对象。如果在分块列表期间更新对象,则将返回在计算第一个列表结果时存在的对象版本。
pretty string 如果为 true,则会将返回结果输出成适合打印的格式。
resourceVersion string 当指定使用 watch 请求时,将显示在资源的特定版本之后发生的更改。默认从历史开始更改。当为 list 指定时:-如果未设置,则基于 quora -read 标志从远程存储返回结果;-如果它是 0,那么我们只是返回我们目前在缓存,没有保证;-如果设置为非零,那么结果至少与给定的 resourceVersion 一样为最新的值。
timeoutSeconds integer list/watch 方法的调用超时时长。这限制了调用的持续时间,不管是否活跃。
watch boolean 监视对所描述的资源的更改,并将其作为添加、更新和删除通知的流返回。需要指定 resourceVersion。

返回信息

Content-Type application/json, application/yaml

状态码: 200

OK

返回体示例

Prometheus 告警规则的列表。

{
   "apiVersion": "monitoring.coreos.com/v1",
   "items": [
     {
       "apiVersion": "monitoring.coreos.com/v1",
       "kind": "PrometheusRule",
       "metadata": {
         "annotations": {
           "alert.cpaas.io/alert.status": "{\"container.cpu.utilization-3znz1-cf1c1f6be9b6228ff9e9184f2c1f8eaa\":\"inactive\"}",
           "alert.cpaas.io/notifications": "[{\"name\":\"local-ares-template-notification\",\"namespace\":\"cpaas-system\"}]",
           "alert.cpaas.io/rules.description": "{}",
           "alert.cpaas.io/rules.disabled": "[]",
           "cpaas.io/creator": "admin@cpaas.io",
           "cpaas.io/description": "",
           "cpaas.io/display-name": "test-xqren",
           "cpaas.io/updated-at": "2021-06-22T03:22:32Z"
         },
         "creationTimestamp": "2021-06-22T03:22:32Z",
         "generation": 1,
         "labels": {
           "alert.cpaas.io/alert.status": "inactive",
           "alert.cpaas.io/cluster": "calico",
           "alert.cpaas.io/kind": "Deployment",
           "alert.cpaas.io/name": "deploy-a",
           "alert.cpaas.io/namespace": "asm-calico",
           "alert.cpaas.io/owner": "System",
           "alert.cpaas.io/project": "asm",
           "prometheus": "kube-prometheus"
         },
         "managedFields": [
           {
             "apiVersion": "monitoring.coreos.com/v1",
             "fieldsType": "FieldsV1",
             "fieldsV1": {
               "f:metadata": {
                 "f:annotations": {
                   ".": {},
                   "f:alert.cpaas.io/notifications": {},
                   "f:alert.cpaas.io/rules.description": {},
                   "f:alert.cpaas.io/rules.disabled": {},
                   "f:cpaas.io/description": {},
                   "f:cpaas.io/display-name": {}
                 },
                 "f:labels": {
                   ".": {},
                   "f:alert.cpaas.io/cluster": {},
                   "f:alert.cpaas.io/kind": {},
                   "f:alert.cpaas.io/name": {},
                   "f:alert.cpaas.io/namespace": {},
                   "f:alert.cpaas.io/owner": {},
                   "f:alert.cpaas.io/project": {},
                   "f:prometheus": {}
                 },
                 "f:ownerReferences": {}
               },
               "f:spec": {
                 ".": {},
                 "f:groups": {}
               }
             },
             "manager": "Mozilla",
             "operation": "Update",
             "time": "2021-06-22T03:22:32Z"
           },
           {
             "apiVersion": "monitoring.coreos.com/v1",
             "fieldsType": "FieldsV1",
             "fieldsV1": {
               "f:metadata": {
                 "f:annotations": {
                   "f:alert.cpaas.io/action": {},
                   "f:alert.cpaas.io/alert.status": {}
                 },
                 "f:labels": {
                   "f:alert.cpaas.io/alert.status": {}
                 }
               }
             },
             "manager": "manager",
             "operation": "Update",
             "time": "2021-06-22T03:22:35Z"
           }
         ],
         "name": "xqren-test",
         "namespace": "asm-calico",
         "ownerReferences": [
           {
             "apiVersion": "apps/v1",
             "blockOwnerDeletion": true,
             "controller": true,
             "kind": "Deployment",
             "name": "deploy-a",
             "uid": "75fa4cbd-a53b-40a1-95bd-881b2b6a0b81"
           }
         ],
         "resourceVersion": "13786440",
         "selfLink": "/apis/monitoring.coreos.com/v1/namespaces/asm-calico/prometheusrules/xqren-test",
         "uid": "13ea0de8-5658-494d-b34b-c917dbb723f9"
       },
       "spec": {
         "groups": [
           {
             "name": "general",
             "rules": [
               {
                 "alert": "container.cpu.utilization-3znz1-cf1c1f6be9b6228ff9e9184f2c1f8eaa",
                 "annotations": {
                   "alert_current_value": "{{ $value }}",
                   "alert_notifications": "[{\"name\":\"local-ares-template-notification\",\"namespace\":\"cpaas-system\"}]"
                 },
                 "expr": " sum by (pod_name, container_name) (container_cpu_usage_seconds_total_irate5m{namespace=\"asm-calico\",pod_name=~\"deploy-a-[a-z0-9]{7,10}-[a-z0-9]{5}\",image!=\"\",container_name!=\"POD\"}) / sum by (pod_name, container_name) (container_spec_cpu_quota{namespace=\"asm-calico\",pod_name=~\"deploy-a-[a-z0-9]{7,10}-[a-z0-9]{5}\",image!=\"\",container_name!=\"POD\"}) * 100000 \u003e0.2",
                 "for": "30s",
                 "labels": {
                   "alert_cluster": "calico",
                   "alert_indicator": "container.cpu.utilization",
                   "alert_indicator_aggregate_function": "",
                   "alert_indicator_aggregate_range": "0",
                   "alert_indicator_comparison": "\u003e",
                   "alert_indicator_query": "",
                   "alert_indicator_threshold": "0.2",
                   "alert_indicator_unit": "%",
                   "alert_involved_object_kind": "Deployment",
                   "alert_involved_object_name": "deploy-a",
                   "alert_involved_object_namespace": "asm-calico",
                   "alert_name": "container.cpu.utilization-3znz1",
                   "alert_project": "asm",
                   "alert_resource": "xqren-test",
                   "severity": "High"
                 }
               }
             ]
           }
         ]
       }
     }
   ],
   "kind": "PrometheusRuleList",
   "metadata": {
     "continue": "",
     "resourceVersion": "14820651",
     "selfLink": "/apis/monitoring.coreos.com/v1/prometheusrules"
   }
 }

返回体说明

名称 类型 描述
apiVersion string 查看公共参数
items array Prometheus 告警规则的列表。更多信息:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md
字段路径:items
items[] object Prometheus 实例的告警规则。
字段路径:items[]
items[].apiVersion string 查看公共参数
items[].kind string 查看公共参数
items[].metadata object 查看公共参数
items[].spec object PrometheusRuleSpec 包含了规则的标准参数。
字段路径:items[].spec
spec.groups array Prometheus 告警规则文件的内容。
字段路径:items[].spec.groups
spec.groups[] object 按顺序统计的记录和告警规则的列表。
字段路径:items[].spec.groups[]
groups[].name string 规则组的名称。
字段路径:items[].spec.groups[].name
groups[].rules array 规则列表。
字段路径:items[].spec.groups[].rules
groups[].rules[] object 描述了一个告警或记录规则。
字段路径:items[].spec.groups[].rules[]
rules[].alert string 告警规则 的名称。
字段路径:items[].spec.groups[].rules[].alert
rules[].annotations object 告警规则的注释,告警规则中,须包含以下必须的注释: -`alert_current_value`:Prometheus 查询表达式的值。固定值为 "$value"。 -`alert_notifications`:告警触发时,发送通知的通知策略列表。值为 "[]" 表示不设置通知;值为 "[{\"name\":\"xqren\",\"namespace\":\"cpaas-system\"}]" 时,表示为告警策略设置了一个位于 cpaas-system 命名空间中的名称为 xqren 的通知策略。
字段路径:items[].spec.groups[].rules[].annotations
rules[].for string 触发规则的持续时间。
字段路径:items[].spec.groups[].rules[].for
rules[].labels object 告警规则的标签。告警规则中,需包含如下必须的 label: -`alert_cluster`:告警规则所在集群的名称。 -`alert_project`:告警规则所在项目的名称。 -`alert_namespace`:告警规则所在命名空间的名称。 -`alert_resource`:告警策略的名称。 -`alert_name`:告警规则的名称 -`alert_involved_object_kind`:告警资源的类型,可选:Cluster、Node、Workload。 -`alert_involved_object_namespace`:告警资源所在命名空间的名称。 -`alert_involved_object_name`:告警资源的名称。 -`alert_indicator`:用于查询规则的指标名称,"custom" 表示自定义指标。 -`alert_indicator_comparison`:规则的比较运算符,例如:>。 -`alert_indicator_threshold`:规则的阈值,例如:0.5。 -`alert_indicator_unit`:指标的单位,例如:%。 -`severity`:指标的告警等级,可选:Critical、High、Medium、Low。
字段路径:items[].spec.groups[].rules[].labels
kind string 查看公共参数
metadata object 查看公共参数

其他状态码

状态码: 401

Unauthorized