乔克视界 乔克视界
首页
  • 运维
  • 开发
  • 监控
  • 安全
  • 随笔
  • Docker
  • Golang
  • Python
  • AIOps
  • DevOps
  • Kubernetes
  • Prometheus
  • ELK
  • 心情杂货
  • 读书笔记
  • 面试
  • 实用技巧
  • 博客搭建
友链
关于
收藏
  • 分类
  • 标签
  • 归档

乔克

云原生爱好者
首页
  • 运维
  • 开发
  • 监控
  • 安全
  • 随笔
  • Docker
  • Golang
  • Python
  • AIOps
  • DevOps
  • Kubernetes
  • Prometheus
  • ELK
  • 心情杂货
  • 读书笔记
  • 面试
  • 实用技巧
  • 博客搭建
友链
关于
收藏
  • 分类
  • 标签
  • 归档
  • Docker

  • Golang

  • AIOps

  • Python

  • DevOps

  • Kubernetes

  • Prometheus

    • Prometheus 介绍
    • 手动搭建 Prometheus
    • 配置监控
    • 安装 Grafana
    • AlertManager
    • Operator 部署 Prometheus
    • 常用函数
    • 黑盒监控
    • 集群事件监控之 kube-eventer
    • 配置企业微信告警
    • PromQL 常用操作
    • 配置短信告警
      • 部署
    • 监控指标
    • PushGateway
    • Google 四大黄金指标
    • Kubernetes 性能指标
  • ELK

  • 专栏
  • Prometheus
乔克
2025-07-20
目录

配置短信告警

Prometheus 是以 operator 方式部署

这里仅仅提供一个思路,万变不离其宗。

使用短信告警之前需要自己购买短信服务,然后定义好短信模板,一般都有现成的 sdk,自己简单包装一下就可以使用了。

思路:通过自定义 webhook 的方式进行发送。

我简单写了一个 webhook,项目地址:https://github.com/cool-ops/prometheus-alert-sms.git (opens new window)

# 部署

1、下载代码

git clone https://github.com/cool-ops/prometheus-alert-sms.git
1

2、编译代码

cd prometheus-alert-sms/
sh build.sh
1
2

3、打包镜像

docker build -t registry.cn-hangzhou.aliyuncs.com/rookieops/prometheus-alert-sms:v0.0.7 .
1

注:镜像地址更换成自己的仓库地址

4、推送镜像到镜像仓库

docker push registry.cn-hangzhou.aliyuncs.com/rookieops/prometheus-alert-sms:v0.0.7
1

5、修改项目目录下的 prometheus-alert-sms.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: sms-conf
  namespace: monitoring
data:
  sms.yaml: |
    adapter:
      adapter_name: "RongLianYun"
    RongLianYun:
      baseUrl : "https://app.cloopen.com:8883"
      accountSid : "xxxxxx"
      appToken   : "xxxxxx"
      appId      : "xxxxx"
      templateId : "xxx"
      phones : ["11111111111","22222222222"]

    AliYun:
      aliRegion: "cn-hangzhou"
      accessKeyId: "xxxx"
      accessSecret: "xxxx"
      phoneNumbers: "11111111111,22222222222"
      signName: "xxxx"
      templateCode: "xxxx"
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: prometheus-alert-sms
  namespace: monitoring
spec:
  replicas: 1
  selector:
    matchLabels:
      app: prometheus-alert-sms
  template:
    metadata:
      labels:
        app: prometheus-alert-sms
    spec:
      containers:
        - name: prometheus-alert-sms
          image: registry.cn-hangzhou.aliyuncs.com/rookieops/prometheus-alert-sms:v0.0.7
          imagePullPolicy: IfNotPresent
          livenessProbe:
            failureThreshold: 3
            httpGet:
              path: /healthCheck
              port: tcp-9000
              scheme: HTTP
            initialDelaySeconds: 30
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 2
            readinessProbe:
              failureThreshold: 3
              httpGet:
                path: /healthCheck
                port: tcp-9000
                scheme: HTTP
              initialDelaySeconds: 30
              periodSeconds: 10
              successThreshold: 1
              timeoutSeconds: 2
          env:
            - name: CONFIG_PATH
              value: /app/conf/sms.yaml
          ports:
            - name: app-port
              containerPort: 9000
              protocol: TCP
          resources:
            limits:
              cpu: 500m
              memory: 1Gi
            requests:
              cpu: 500m
              memory: 1Gi
          volumeMounts:
            - name: sms-conf
              mountPath: /app/conf/sms.yaml
              subPath: sms.yaml
      volumes:
        - name: sms-conf
          configMap:
            name: sms-conf
---
apiVersion: v1
kind: Service
metadata:
  name: prometheus-alter-sms
  namespace: monitoring
spec:
  selector:
    app: prometheus-alert-sms
  ports:
    - name: app-port
      port: 9000
      targetPort: 9000
      protocol: TCP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

到自己购买的短信服务获取对应的信息。

7、部署 yaml 文件

kubectl apply -f prometheus-alert-sms.yaml
1

8、修改 alertmanager 的报警媒介

 ......
      - receiver: sms
        group_wait: 10s
        match:
          filesystem: node
    receivers:
    - name: 'sms'
      webhook_configs:
      - url: "http://prometheus-alter-sms.monitoring.svc:9000"
        send_resolved: true
......
1
2
3
4
5
6
7
8
9
10
11

然后如果有报警就可以正常接受到报警了。

1593674134089 5bf29dc7 061d 41f1 883b 4fa3eec6da9b

上次更新: 2025/07/20, 10:40:32
PromQL 常用操作
监控指标

← PromQL 常用操作 监控指标→

最近更新
01
elastic 账户认证 401 问题
07-20
02
使用 helm 安装 es 和 kibana
07-20
03
elastic stack 搭建
07-20
更多文章>
Theme by Vdoing | Copyright © 2019-2025 乔克 | MIT License | 渝ICP备20002153号 |
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式