Prometheus + Grafana + AlertManger 相关整理

简介: 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命令去查询进程并杀掉 !


目录
相关文章
|
监控 Linux 数据安全/隐私保护
CentOS7下安装SNMP服务
CentOS7下安装SNMP服务
788 0
CentOS7下安装SNMP服务
|
缓存 JSON 数据格式
harbor2.0安装
harbor2.0安装过程和私有镜像上传
1600 3
harbor2.0安装
|
Kubernetes 应用服务中间件 nginx
二进制安装Kubernetes(k8s)v1.32.0
本指南提供了一个详细的步骤,用于在Linux系统上通过二进制文件安装Kubernetes(k8s)v1.32.0,支持IPv4+IPv6双栈。具体步骤包括环境准备、系统配置、组件安装和配置等。
4881 11
|
Java 网络安全
zookeeper的环境搭建和配置
本文介绍了如何在多台节点上搭建和配置Zookeeper环境。内容包括Zookeeper的下载、解压、环境变量配置、配置文件修改、zkdata目录创建、myid文件设置,以及将Zookeeper及其配置文件复制到其他节点。还提供了运行测试的命令,包括启动、状态检查和停止Zookeeper服务。
zookeeper的环境搭建和配置
|
运维 数据安全/隐私保护 Docker
Docker自建仓库之Docker Registry部署实战
关于如何使用Docker Registry镜像搭建本地私有Docker仓库的实战教程,包括了下载镜像、创建授权目录和用户名密码、启动Registry容器、验证端口和容器、测试登录仓库、上传和下载镜像的详细步骤。
4689 5
|
Kubernetes 监控 容器
K8S故障注入混沌工程开源平台ChaosMesh
总之,ChaosMesh作为一个Kubernetes混沌工程平台,为用户提供了测试和验证Kubernetes集群的可靠性的工具和框架,有助于提高系统的稳定性和性能。
635 0
|
存储 监控 搜索推荐
【Elasticsearch】初识elasticsearch(上)
【Elasticsearch】初识elasticsearch
156 0
下一篇
开通oss服务