kubernetes Prometheus警报规则未显示

qmelpv7a  于 2023-08-03  发布在  Kubernetes
关注(0)|答案(2)|浏览(282)

我创建了警报规则文件.yml并将其复制到prometheus contianer的“/”下,然后将其添加到values.yml文件中,但在UI中看不到规则

prometheus.yml:
    rule_files:
      - /etc/config/recording_rules.yml
      - /etc/config/alerting_rules.yml
      - /custom_alerting_rules.yml
    ## Below two files are DEPRECATED will be removed from this default values file
      - /etc/config/rules
      - /etc/config/alerts

    alerting:
      alertmanagers:
        - static_configs:
            - targets: ['alertmanager:9093'] here i tried the @IP of alert manager service

字符串
这是警报文件

groups:
  - name: my-custom-alerts
    rules:
      - alert: HighPodCount
        expr: count(kube_pod_info{pod=~"consumer.*"}) > 2
        for: 5m
        labels:
          severity: critical
        annotations:
          summary: High pod count
          description: The number of pods is above the threshold.


k get svc显示

prometheus-alertmanager               ClusterIP      10.10x.21x.x8    <none>        9093/TCP                       68m


我做错了什么?

kgqe7b3p

kgqe7b3p1#

从Prometheus服务器的Angular 来看,其配置和规则文件不会自动重新加载。您需要手动调用Reload管理API。
有三种方法可用于此目的:
1.如果你在普罗米修斯战斗机里:

curl -XPOST http://:::9090/-/reload

字符串
1.如果你在同一个命名空间的另一个pod容器中:

# prometheus pod name: prometheus-0
curl -XPOST http://prometheus-0:9090/-/reload


1.如果你不在K8s集群(即运行kubectl命令的地方):

# prometheus pod name: prometheus-0, namespace: monitoring
kubectl port-forward prometheus-0 -nmonitoring 9090:9090
# in another shell
curl -XPOST http://127.0.0.1:9090/-/reload

4smxwvx5

4smxwvx52#

如果你使用prometheus operator,你也可以使用PrometheusRule crd而不是文件:

apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
  name: my-custom-alert
  namespace: my-namespace
spec:
  groups:
  - name: my-custom-alerts
    rules:
      - alert: HighPodCount
        expr: count(kube_pod_info{pod=~"consumer.*"}) > 2
        for: 5m
        labels:
          severity: critical
        annotations:
          summary: High pod count
          description: The number of pods is above the threshold.

字符串
然后:

#> kubectl get PrometheusRule -n my-namespace
my-custom-alert


这将使操作员在prometheus的配置中安装警报,而无需您做任何其他事情。

相关问题