Prometheus + Grafana + AlertManger 相关整理

本文涉及的产品
EMR Serverless StarRocks,5000CU*H 48000GB*H
可观测监控 Prometheus 版,每月50GB免费额度
可观测可视化 Grafana 版,10个用户账号 1个月
简介: Prometheus + Grafana + AlertManger 相关整理

01 整体流程图


d6af04e3102a47b38b11451bd8dd22de.png


02 相关资料


可参考的教程:


  • 环境搭建:《Prometheus+Grafana+Alertmanager实现告警推送教程图文详解》
  • Grafana面板使用:《Grafana 使用表格面板进行数据可视化》


相关的下载:



03 相关配置


3.1 prometheus.yml

global:
  scrape_interval: 15s
  evaluation_interval: 15s 
alerting:
  alertmanagers:
  - static_configs:
    - targets:
       - localhost:9093
rule_files:
  - "/opt/prometheus_env/prometheus-2.34.0.linux-amd64/alarm_rules.yml"
scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']
        labels:
          instance: 'prometheus'
  - job_name: 'linux'
    static_configs:
      - targets: ['localhost:9100']
        labels:
          instance: 'localhost'
  - job_name: 'pushgateway'
    static_configs:
      - targets: ['localhost:9091']
        labels:
          instance: 'pushgateway'


3.2 alarm_rules.yml

groups:
- name: node
  rules:
  - alert: server_status
    expr: up{} == 0 
    for: 15s
    annotations:
      summary: "机器{{ $labels.instance }} 挂了"
      description: "请立即查看问题!"


3.3 alertmanager.yml

global:
  resolve_timeout: 5m
  smtp_smarthost: 'smtp.exmail.qq.com:465' # 定义163邮箱服务器端
  smtp_from: '您的qq邮箱账号'  #来自哪个邮箱发的
  smtp_auth_username: '您的qq邮箱账号' 邮箱验证
  smtp_auth_password: '邮箱密码'   # 邮箱授权码,不是登录密码
  smtp_require_tls: false   # 是否启用tls
route:
  group_by: ['alertname']
  group_wait: 10s
  group_interval: 10s
  repeat_interval: 3m  # 发送告警后间隔多久再次发送,减少发送邮件频率
  receiver: 'mail'    #发送的告警媒体
receivers:
- name: 'mail'        # 接收者配置,这里要与接收媒体一致
  email_configs: 
  - to: '接收人的qq邮箱' #发送给谁的邮箱,多个人多行列出
#inhibit_rules:
#  - source_match:
#      severity: 'critical'
#    target_match:
#      severity: 'warning'
#    equal: ['alertname', 'dev', 'instance']


04 systemctl脚本


4.1 配置

cd /usr/lib/systemd/system


① pushgateway.service文件,内容如下:

[Unit]
Description=Prometheus Push Gateway
After=network.target
[Service]
ExecStart=/opt/prometheus_env/pushgateway-1.4.2.linux-amd64/pushgateway
User=root
[Install]
WantedBy=multi-user.target


② node_exporter.service文件,内容如下:

[Unit]
Description=Prometheus Node Exporter
After=network.target
[Service]
ExecStart=/opt/prometheus_env/node_exporter-1.3.1.linux-amd64/node_exporter
User=root
[Install]
WantedBy=multi-user.target


③ prometheus.service文件,内容如下:

[Unit]
Description=Prometheus Service
After=network.target
[Service]
ExecStart=/opt/prometheus_env/prometheus-2.34.0.linux-amd64/prometheus \
--config.file=/opt/prometheus_env/prometheus-2.34.0.linux-amd64/prometheus.yml \
--web.read-timeout=5m  \
--web.max-connections=10 \
--storage.tsdb.retention=15d \
--storage.tsdb.path=/prometheus/data \
--query.max-concurrency=20 \
--query.timeout=2m
User=root
[Install]
WantedBy=multi-user.target


④ grafana.service文件,内容如下:

[Unit]
Description=Grafana
After=network.target
[Service]
ExecStart=/opt/prometheus_env/grafana-8.4.7/bin/grafana-server \
 --config=/opt/prometheus_env/grafana-8.4.7/conf/defaults.ini \
 --homepath=/opt/prometheus_env/grafana-8.4.7
[Install]
WantedBy=multi-user.target


⑤ alertmanager.service文件,内容如下:

[Unit]
Description=Prometheus alertmanager
After=network.target
[Service]
ExecStart=/opt/prometheus_env/alertmanager-0.24.0.linux-amd64/alertmanager \
--storage.path=/opt/prometheus_env/alertmanager-0.24.0.linux-amd64/data \
--config.file=/opt/prometheus_env/alertmanager-0.24.0.linux-amd64/alertmanager.yml
User=root
[Install]
WantedBy=multi-user.target


4.2 启动


重载配置:

systemctl daemon-reload


开启服务:

systemctl start pushgateway
systemctl start node_exporter
systemctl start prometheus
systemctl start grafana
systemctl start alertmanager


设置开机启动:

systemctl enable pushgateway
systemctl enable node_exporter
systemctl enable prometheus
systemctl enable grafana
systemctl enable alertmanager


查看服务状态:

systemctl status pushgateway


05 其它命令


开启端口,能被浏览器访问(例如开启:3000)

firewall-cmd --zone=public --add-port=3000/tcp --permanent


重启防火墙:

firewall-cmd --reload


查看端口:

netstat -tunlp | grep 9090


查看进程:

ps -elf|grep promethues


模拟CPU升高:

for i in `seq 1 $(cat /proc/cpuinfo |grep "physical id" |wc -l)`; do dd if=/dev/zero of=/dev/null & done
## top命令去查询进程并杀掉 !


相关实践学习
通过可观测可视化Grafana版进行数据可视化展示与分析
使用可观测可视化Grafana版进行数据可视化展示与分析。
目录
相关文章
|
12月前
|
Prometheus Kubernetes 监控
k8s中部署Grafana-prometheus系列文章第二篇
k8s中部署Grafana-prometheus系列文章第二篇
|
4月前
|
Prometheus 监控 Cloud Native
基于Prometheus和Grafana的监控平台 - 环境搭建
基于Prometheus和Grafana的监控平台 - 环境搭建
|
2月前
|
Prometheus 监控 Cloud Native
prometheus学习笔记之Grafana安装与配置
prometheus学习笔记之Grafana安装与配置
|
3月前
|
JSON Prometheus 监控
Prometheus+Grafana 部署
Prometheus 和 Grafana 组成监控解决方案。Prometheus 是开源系统监控工具,Grafana 则用于数据可视化。要连接 Prometheus 数据源,登录 Grafana,点击设置,选择“连接”,添加新数据源,选择 Prometheus 类型,并填入 Prometheus 服务器的 HTTP 地址,如 `http://192.168.1.1:9090`,验证连接。之后,从 Grafana 官方仪表板库导入监控面板,如主机监控模板,以可视化系统状态。完成这些步骤后,便建立了有效的监控系统。
71 1
|
12月前
|
存储 Prometheus 监控
【Prometheus】什么是prometheus?prometheus简介
【Prometheus】什么是prometheus?prometheus简介
108 0
|
5月前
|
存储 Prometheus 监控
Prometheus实战篇:Prometheus简介
Prometheus 是一个开源的服务监控系统和时序数据库,其提供了通用的数据模型和快捷数据采集、存储和查询接口。
|
11月前
|
Prometheus Cloud Native 网络安全
Prometheus+Grafana+Alertmanager部署教程(超详细)
Prometheus+Grafana+Alertmanager部署教程(超详细)
725 1
|
Prometheus Kubernetes 监控
Prometheus + Grafana on k8s部署
Prometheus + Grafana on k8s部署
1234 0
Prometheus + Grafana on k8s部署
|
11月前
|
Prometheus Cloud Native 数据可视化
Prometheus + Grafana + AlertManger 相关整理
Prometheus + Grafana + AlertManger 相关整理
42 0
|
12月前
|
Prometheus 监控 Kubernetes
k8s中部署prometheus监控告警系统-prometheus系列文章第一篇
k8s中部署prometheus监控告警系统-prometheus系列文章第一篇
下一篇
无影云桌面